snappy · API

snappy.framing

Snappy framing format: a sNaPpY stream identifier chunk followed by a sequence of length-prefixed chunks, each either compressed or uncompressed raw-format data guarded by a masked CRC-32C. See https://github.com/google/snappy/blob/main/framing_format.txt.

Chunk layout: 1-byte type, 3-byte little-endian data length, then the data. Compressed/uncompressed data chunks additionally carry a 4-byte little-endian masked CRC-32C of the uncompressed bytes as the first 4 bytes of their data.

Structs

FramedWriter

struct FramedWriter

Incremental framing-format encoder: feed arbitrary-sized buffers to write, splitting into <=64 KiB chunks internally; finish returns the complete encoded stream.

Implements Movable

__init__

def __init__(out self)

write

def write(mut self, data: Span[UInt8])

finish

def finish(deinit self) -> List[UInt8]

FramedReader

struct FramedReader

Incremental framing-format decoder: read_chunk returns each data chunk's decompressed bytes in order (verifying its CRC-32C), or None once the stream is exhausted. Stream-identifier, padding, and skippable chunks are consumed transparently.

Implements Movable

__init__

def __init__(out self, data: Span[UInt8])

read_chunk

def read_chunk(mut self) -> Optional[List[UInt8]]

Functions

compress_framed

def compress_framed(data: Span[UInt8]) -> List[UInt8]

Compress data into a complete Snappy framing-format stream (stream identifier + one or more chunks, each <= 64 KiB uncompressed).

decompress_framed

def decompress_framed(data: Span[UInt8]) -> List[UInt8]

Decompress a full Snappy framing-format stream, verifying every chunk's masked CRC-32C. Raises on a missing/misplaced stream identifier, an unsupported unskippable chunk type, or a checksum mismatch.

Aliases

comptime CHUNK_COMPRESSED = UInt8(0)
comptime CHUNK_UNCOMPRESSED = UInt8(1)
comptime CHUNK_PADDING = UInt8(254)
comptime CHUNK_STREAM_IDENTIFIER = UInt8(255)