Skip to content

NodeHttpCompression

HTTP response compression backed by node:zlib, shared by the Node.js, Bun, and Deno platforms.

Byte-array bodies are compressed in one shot with the asynchronous node:zlib APIs, preserving an exact Content-Length. Streaming bodies go through node:zlib transform streams that flush each input chunk.

4 exports Added in v4.0.0 Source

Constants

algorithms

Added in v4.0.0 Source

The compression algorithms supported by the runtime's node:zlib. zstd requires Node.js 22.15 or newer.

Signature

declare const algorithms: ReadonlySet<Platform.CompressionAlgorithm>;

Constructors

Creates a node:zlib compression transform stream that flushes each input chunk, for streaming response bodies.

Signature

declare function compressTransform(algorithm: CompressionAlgorithm, options?: any): Duplex;

A Web ReadableStream version of compressTransform, for platforms that stream response bodies as Web streams.

Signature

declare function compressTransformWeb(
  algorithm: CompressionAlgorithm,
  options?: any,
): (
  stream: ReadableStream<Uint8Array<ArrayBufferLike>>,
) => ReadableStream<Uint8Array<ArrayBufferLike>>;

make

Added in v4.0.0 Source

Creates a Compression that compresses byte-array bodies in one shot with the asynchronous node:zlib APIs, setting the exact Content-Length of the compressed body. All other bodies are delegated to fallback.

Signature

declare function make(fallback: Compression): Compression;