velt/compress
API referenceDecompression, written in Velt: gzip (RFC 1952), zlib (RFC 1950), raw DEFLATE (RFC 1951) and Brotli (RFC 7932). They are what fetch decodes compressed response bodies with. For a walkthrough, read the guide.
Exports
content-encoding: deflate decodes to: zlib, or raw DEFLATE without a zlib header.inflateRawThe bytes a raw DEFLATE stream decodes to.brotliDecompressOne-shot: the whole decoded stream.CompressErrorCompressed input that is not valid, or that ends before its stream does.InflateDecoderDecodes a stream fed in pieces (feed, then finish) into chunks (read).BrotliDecoderStreaming decoder: input arrives in pieces, output is pulled in bounded chunks.InflateFormatA compressed stream's wrapping: "gzip", "zlib", "raw" (DEFLATE alone), or "deflate", HTTP's content-encoding: deflate: zlib, or raw DEFLATE when the stream does not start with a zlib header (as browsers and Node's fetch accept both).Re-exported from velt/compress/inflate/inflate_decoder
function gunzip(input: u8[]): u8[] throws CompressErrorThe bytes a gzip stream (one or more members) decodes to.
Re-exported from velt/compress/inflate/inflate_decoder
function inflate(input: u8[]): u8[] throws CompressErrorThe bytes a zlib stream decodes to.
Re-exported from velt/compress/inflate/inflate_decoder
function inflateHttp(input: u8[]): u8[] throws CompressErrorThe bytes a body with HTTP's content-encoding: deflate decodes to: zlib, or raw DEFLATE
without a zlib header.
Re-exported from velt/compress/inflate/inflate_decoder
function inflateRaw(input: u8[]): u8[] throws CompressErrorThe bytes a raw DEFLATE stream decodes to.
Re-exported from velt/compress/brotli/brotli_decoder
function brotliDecompress(input: u8[]): u8[] throws CompressErrorOne-shot: the whole decoded stream. Throws CompressError on invalid or truncated input.
Re-exported from velt/compress/errors
class CompressError extends ErrorCompressed input that is not valid, or that ends before its stream does.
Thrown bybrotliDecompressBrotliDecoder.readgunzipinflateInflateDecoder.readinflateHttpinflateRaw
constructor(message: string)No doc comment yetRe-exported from velt/compress/inflate/inflate_decoder
Decodes a stream fed in pieces (feed, then finish) into chunks (read).
constructor(format: InflateFormat)No doc comment yetfeed(input: u8[])Queues more compressed bytes (input is kept, not copied, when nothing is left over).
finish()No more input follows.
get done(): boolWhether the stream has ended and every decoded byte was read.
read(max: i64): u8[] throws CompressErrorUp to max decoded bytes; [] when more input is needed first, or at the end (done).
Throws CompressError for input that is not a valid stream, and for one that finish()
cut short.
Re-exported from velt/compress/brotli/brotli_decoder
Streaming decoder: input arrives in pieces, output is pulled in bounded chunks.
constructor()No doc comment yetfeed(input: u8[])Queue more compressed bytes (the decoder copies them; the caller may reuse the array).
finish()No more input will follow.
read(max: i64): u8[] throws CompressErrorUp to max (> 0) decoded bytes. Returns [] when it needs more input before it can produce
anything, or when the stream has ended (then done is true). Throws CompressError on
invalid data, on data after the end of the stream, or when finish() was called and the
stream is incomplete. Never returns more than max bytes, so a tiny input that expands
hugely is produced in bounded chunks.
get done(): boolThe stream's last meta-block has been decoded and all output read.
Re-exported from velt/compress/inflate/inflate_decoder
type InflateFormat = "gzip" | "zlib" | "raw" | "deflate"A compressed stream's wrapping: "gzip", "zlib", "raw" (DEFLATE alone), or "deflate",
HTTP's content-encoding: deflate: zlib, or raw DEFLATE when the stream does not start with a
zlib header (as browsers and Node's fetch accept both).
Parameter ofInflateDecoder.constructor