Version: 0.0.5 (stable)
agrag.loaders.common.read_within_limit
read_within_limit(stream:BinaryIO, source:SourceRef, opts:ReadOptions) -> bytes
Read a source's bytes without exceeding max_document_bytes.
Rejects a source whose known size already exceeds the limit before reading, and caps the actual read one byte past the limit so a source with no reported size cannot be buffered past the configured bound either.
Parameters:
- stream (
BinaryIO) – The open binary stream for the source. - source (
SourceRef) – The source being read. - opts (
ReadOptions) – The read options, formax_document_bytes.
Returns:
bytes– The source's raw bytes.
Raises:
DocumentTooLargeError– The source is, or would be, over the limit.ValueError–opts.max_document_bytesis not a positive integer.