Expand description
Streaming compression abstractions backed by zrip (zstd).
§Design
Both Compressor and Decompressor are stream-oriented: they
accept bounded input chunks and produce bounded output chunks, so the
heap footprint of processing a file does not grow with the file
size. The STREAM_BUF_SIZE sliding window
keeps memory constant (~64 KiB typical, capped well below 4 MiB even
for adversarial frames).
§Wire format
The compressed body is a concatenation of independent zstd frames:
each Compressor::compress call emits one complete frame when the
next call arrives (or on Compressor::finish).
The decompressor buffers compressed bytes until a complete frame is
present (frame boundaries are detected by a small built-in zstd frame
parser), then decodes exactly that frame with
zrip::decompress_with_limit. A frame may therefore span several
decompress() inputs, and one input may contain several frames.
§Constant memory
- Compressor: buffers at most one input chunk internally plus the zrip encoder workspace (~150 KiB).
- Decompressor: holds at most one compressed frame
(
MAX_PENDING_FRAME) and one decompressed frame (MAX_FRAME_OUTPUT) at a time.
The server should feed Compressor::compress in
STREAM_BUF_SIZE windows (64 KiB), keeping
frames ~64 KiB and the client’s transient buffers small.
Structs§
- Zrip
Compressor - zstd compressor emitting one independent frame per input chunk.
- Zrip
Decompressor - zstd decompressor reassembling frames across arbitrary chunk boundaries.
Enums§
- Compression
Format - Compression formats understood by libfw.
Constants§
- MAX_
FRAME_ OUTPUT - Safety ceiling for the decompressed size of a single frame.
- MAX_
OUTPUT_ PER_ CALL - Default cap on the total bytes a single
Decompressor::decompresscall may append to the output buffer. - MAX_
PENDING_ FRAME - Maximum compressed bytes buffered while waiting for a frame boundary.
- ZRIP_
DEFAULT_ LEVEL - Default zrip compression level (Fast strategy, good for network transfer).
Traits§
- Compressor
- Streaming compressor. Feed it bounded input chunks; it appends the compressed bytes produced so far to the provided output buffer.
- Decompressor
- Streaming decompressor. Feed it arbitrary compressed bytes; decoded output is appended to the provided buffer.
Functions§
- compressor
- Construct a compressor for
format. - decompressor
- Construct a decompressor for
format. - decompressor_
with_ limit - Construct a decompressor for
formatwith an explicit per-call output budget (bytes a singleDecompressor::decompresscall may append).