aistore.sdk.batch.multipart.multipart_stream_buffer
aistore.sdk.batch.multipart.multipart_stream_buffer
Module Contents
Classes
Data
API
Manages reading content from an iterator and buffering it efficiently.
This class handles the low-level details of reading from content iterators and managing the sliding window buffer. It provides an abstraction layer that prevents higher-level classes from directly manipulating the buffer.
Parameters:
Iterator yielding chunks of content data
The multipart boundary marker to detect
Maximum size of the internal sliding window buffer
Get the boundary pattern.
Fill buffer ensuring we have at least min_size bytes available, with boundary safety margin.
This method ensures we always have enough data in the buffer to avoid boundary splits when consuming data.
Parameters:
Minimum buffer size required
Returns: bool
True if sufficient data available, False if stream exhausted
Read one chunk from content iterator into buffer.
Returns: bool
True if chunk read successfully, False if iterator exhausted
Consume content before a pattern at a known position and return it.
Parameters:
Known position of the pattern in the buffer
Pattern to search for in the buffer (for length calculation)
Whether to strip whitespace and line endings from consumed content. Defaults to True.
Returns: bytes
Content found before the pattern, with optional cleaning applied. Returns empty bytes if position is invalid.
Consume and return data from buffer, ensuring boundary safety.
This method ensures that after consumption, we maintain enough buffer data to avoid boundary splits.
Parameters:
Number of bytes to consume
Returns: bytes
Consumed data
Ensure at least min_bytes are available in buffer.
Parameters:
Minimum buffer size required. Defaults to 0.
Returns: bool
True if sufficient buffer available, False if stream exhausted
Find boundary position in current buffer.
Returns: int
Position of boundary within buffer, -1 if not found or no boundary set
Raises:
ValueError: If no boundary has been set for this reader
Find pattern in current buffer data.
Parameters:
Pattern to search for
Starting offset for search. Defaults to 0.
Returns: int
Position of pattern relative to buffer start, -1 if not found
Get the size of the boundary pattern.
Returns: int
Size of boundary in bytes, 0 if no boundary set
Get current buffer size for safe content calculations.
Returns: int
Current size of buffer
Get a copy of data slice from buffer.
Parameters:
Starting position. Defaults to 0.
Ending position, None for end of buffer.
Returns: bytes
Copy of requested data range
Get size of content that can be safely consumed without risking boundary split.
This ensures we don’t consume data that might contain a partial boundary that spans across buffer chunks.
Returns: int
Size of content consumable without a boundary split. Returns full buffer size if no boundary is set.
Check if a boundary has been configured for this reader.
Returns: bool
True if boundary is set, False otherwise
Check if buffer has any data or can get more.
Returns: bool
True if data is available or can be obtained
Check if both stream and buffer are exhausted.
Returns: bool
True if no more data can be obtained
Read and consume all data until the next boundary is found.
Parameters:
Whether to strip whitespace and line endings from consumed content. Defaults to True.
Raises:
ValueError: If no boundary has been set for this reader
Skip leading whitespace in buffer.
Returns: int
Number of whitespace bytes that were skipped