@moq/flate
v0.1.1
Published
Group-scoped DEFLATE: a stream of self-delimited frames sharing one compression window.
Readme
@moq/flate
Group-scoped DEFLATE: a stream of self-delimited frames sharing one compression window.
A sequence of frame payloads is compressed into a single raw DEFLATE (RFC 1951) stream, sync-flushed at each frame boundary. Every frame is self-delimited (byte-aligned, the window retained) while later frames reuse the earlier ones as context, so a stream of similar payloads (a snapshot followed by deltas, repeated records, log lines) compresses far better than each payload alone.
This is plain raw DEFLATE with a Z_SYNC_FLUSH after each frame, so it interoperates on the wire with any peer using the same primitive, including the Rust moq-flate crate. The fixed 4-byte sync-flush marker is stripped per frame (RFC 7692's permessage-deflate trick). There is no length prefix: the caller frames each slice (@moq/net already does).
Quick Start
npm add @moq/flateimport { Encoder, Decoder } from "@moq/flate";
const encoder = new Encoder();
const a = encoder.frame(new TextEncoder().encode("the quick brown fox"));
const b = encoder.frame(new TextEncoder().encode("the quick brown dog")); // smaller: reuses the window
// Feed slices to the decoder in the same order they were produced.
const decoder = new Decoder();
new TextDecoder().decode(decoder.frame(a)); // "the quick brown fox"
new TextDecoder().decode(decoder.frame(b)); // "the quick brown dog"Create a fresh Encoder/Decoder pair per independent stream (in moq-net terms, per group). new Encoder({ level }) sets the DEFLATE level (0..=9, default 6); new Decoder({ maxFrameSize }) caps how far a single frame may inflate (default 64 MiB), rejecting zip bombs.
