Skip to main content

acompress_sequence

Asynchronously compresses a sequence of bytes using Gzip and yields the resulting data chunks. The function utilizes a streaming buffer to provide incremental output and can optionally include a randomized filename in the Gzip header.

def acompress_sequence(
sequence: AsyncIterable[bytes],
max_random_bytes: int | None = None
) - > AsyncGenerator[bytes, None]

Asynchronously compresses a sequence of byte chunks into a Gzip-encoded stream using a streaming buffer. Use this to generate compressed data incrementally from an async iterator without loading the entire sequence into memory.

Parameters

NameTypeDescription
sequenceAsyncIterable[bytes]The source sequence of byte chunks to be compressed.
max_random_bytes`intNone` = None

Returns

TypeDescription
AsyncGenerator[bytes, None]An async generator yielding chunks of Gzip-compressed data as they become available.