Skip to content
velt/compress exports

velt/compress

API reference

Decompression, 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.

import { gunzip, brotliDecompress, InflateDecoder } from "velt/compress";

Exports

Re-exported from velt/compress/inflate/inflate_decoder

function gunzip(input: u8[]): u8[] throws CompressError

The bytes a gzip stream (one or more members) decodes to.

Re-exported from velt/compress/inflate/inflate_decoder

function inflate(input: u8[]): u8[] throws CompressError

The bytes a zlib stream decodes to.

Re-exported from velt/compress/inflate/inflate_decoder

function inflateHttp(input: u8[]): u8[] throws CompressError

The 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 CompressError

The bytes a raw DEFLATE stream decodes to.

Re-exported from velt/compress/brotli/brotli_decoder

function brotliDecompress(input: u8[]): u8[] throws CompressError

One-shot: the whole decoded stream. Throws CompressError on invalid or truncated input.

class

CompressError

#std/compress/errors.vlt:4

Re-exported from velt/compress/errors

class CompressError extends Error

Compressed input that is not valid, or that ends before its stream does.

constructor(message: string)No doc comment yet

Re-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 yet
feed(input: u8[])

Queues more compressed bytes (input is kept, not copied, when nothing is left over).

finish()

No more input follows.

get done(): bool

Whether the stream has ended and every decoded byte was read.

read(max: i64): u8[] throws CompressError

Up 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 yet
feed(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 CompressError

Up 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(): bool

The 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).