Skip to content

CompressionStream

Defined in: next/api.d.ts:508

A ponyfill of CompressionStream of the Compression Streams standard: it compresses the chunks written to its CompressionStream.writable side into the chunks read from its CompressionStream.readable side, in any Format and with the options of compress. Pipe data through it with pipeThrough(). It neither replaces nor uses the global CompressionStream.

The chunks written may be any Input, read as the functions read their data: bytes in a SharedArrayBuffer are copied first. A chunk of any other type errors the stream with ERR_COMPRS_INVALID_ARG, and so does a detached buffer. The chunks read are Bytes, which together hold the compressed data: their sizes follow the codec, not the chunks written. 'deflate' is the zlib format, as in the standard.

In Node.js, a chunk that the stream predicts to take 2 ms or more is compressed on a thread of the libuv pool, so that it does not block the event loop, and cheaper ones on the calling thread, which yields to the event loop every few milliseconds, as the stream helpers of the package root do. The browser build compresses each chunk on the calling thread. Errors of the codec error the stream, with an ErrorCode as code.

new CompressionStream(format, options?): CompressionStream

Defined in: next/api.d.ts:517

Create a stream that compresses in format, with options, which are checked here, as compressSync checks them.

Format

CompressionStreamOptions

CompressionStream

An error with an ErrorCode as code, such as ERR_COMPRS_INVALID_ARG for an unknown format or an invalid option.

get [toStringTag](): string

Defined in: next/api.d.ts:522

string


get readable(): ReadableStream<Uint8Array<ArrayBuffer>>

Defined in: next/api.d.ts:519

The side to read the compressed data from.

ReadableStream<Uint8Array<ArrayBuffer>>


get writable(): WritableStream<Input>

Defined in: next/api.d.ts:521

The side to write the data to compress to.

WritableStream<Input>