aistore.sdk.batch.multipart.stateful_streaming_parser
aistore.sdk.batch.multipart.stateful_streaming_parser
Module Contents
Classes
Data
API
A stateful streaming parser for efficiently processing multipart HTTP responses.
The parser maintains state across multiple parts of a multipart response, automatically detecting boundaries, extracting headers, and providing streaming access to body content.
Parameters:
Iterator yielding chunks of the HTTP response
The multipart boundary marker (including leading dashes)
Maximum size of the internal sliding window buffer
This class is not thread-safe. Each instance should be used by a single thread or proper synchronization must be implemented by the caller.
Return the number of bytes in chunk that are header content, i.e. the bytes before the first terminator (WIN_LINE_END or UNIX_LINE_END).
Also detects terminators that span the buffer-chunk boundary (e.g. the buffer ends with \r\n\r and chunk starts with \n) to avoid over-counting and triggering a spurious MultipartDecodeError.
Parameters:
The raw chunk peeked from the stream before appending
Returns: int
Number of bytes in chunk that are header content (0 if the chunk starts with or completes a terminator)
Extract headers using the optimized content reader abstraction.
Returns: Optional[bytes]
Optional[bytes]: Headers as bytes if found, None if stream exhausted
Raises:
MultipartDecodeError: If accumulated header bytes exceed max_buffer_size, or the terminator is found at a position exceeding max_buffer_size.
Return the number of header bytes already in the buffer, excluding any trailing terminator-prefix bytes (e.g. a trailing \r that is the first byte of \r\n\r\n must not inflate the header size counter).
Returns: int
Number of countable header bytes currently in the buffer
Find the first boundary marker using the optimized buffer reader.
Returns: bool
True if boundary found, False if exhausted without finding boundary
Get the next part without loading it completely into memory.
Returns: Optional[Tuple[bytes, BodyStreamReader ]]
Optional[Tuple[bytes, BodyStreamReader]]: If part exists, returns tuple of headers and body stream