Skip to content

Lz4DecompressContext

Defined in: index.d.ts:54

Streaming LZ4 frame decompression context.

The input may hold several concatenated frames, including skippable and legacy frames. The context works in one of two modes:

  • By default, it buffers its input: transform() keeps each chunk and returns an empty buffer, and flush() decodes what has been kept since the last flush(), which must end between frames. maxOutputSize limits the output of each flush() on its own, not of the whole stream.
  • With { incremental: true }, it decodes its input as it arrives: transform() returns the content of each block once all of the block has arrived, and throws as soon as the input is invalid; flush() returns an empty buffer; finish() throws if the input did not end between frames. maxOutputSize limits the output of the whole stream, and the context keeps at most one block of input. The stream helpers use this mode.

new Lz4DecompressContext(maxOutputSize?, options?): Lz4DecompressContext

Defined in: index.d.ts:793

maxOutputSize defaults to 256 MB. options.incremental selects the incremental mode; options must be an object, undefined or null.

number | null

StreamContextOptions | null

Lz4DecompressContext

[dispose](): void

Defined in: index.d.ts:56

Close the context, like close(): using declarations call it.

void


close(): void

Defined in: index.d.ts:823

Release the native state of the context now rather than when the context is garbage-collected. Later calls throw, and finish() releases the state too. Closing a finished or closed context does nothing. [Symbol.dispose]() is the same method, for using declarations.

void


finish(): Buffer

Defined in: index.d.ts:815

Finalize the decompression stream, then release the native state. By default, decompress the data buffered since the last flush(), like flush(). Incremental, return an empty buffer, or throw if the input did not end between frames, including empty input. Throws if the stream is already finished.

Buffer


finishAsync(): Promise<Buffer<ArrayBufferLike>>

Defined in: index.d.ts:866

finish() on the libuv thread pool: returns a Promise of the rest of the output, and reports every error by rejecting it. The native state is released once the call has run, whether it succeeded or not. In the browser build, it runs synchronously, on the calling thread.

At most one asynchronous call may be in flight per context: until its Promise settles, another asynchronous call rejects and a synchronous call throws <name> is busy: an asynchronous call has not finished. After close(), calls reject with <name> already closed.

Promise<Buffer<ArrayBufferLike>>


flush(): Buffer

Defined in: index.d.ts:807

By default, decompress all buffered data and return the result, with at most maxOutputSize bytes. Throws if no compressed data was transformed at all, if the input ends inside a frame, or if data that is not a frame follows a frame. Incremental, return an empty buffer.

Buffer


flushAsync(): Promise<Buffer<ArrayBufferLike>>

Defined in: index.d.ts:852

flush() on the libuv thread pool: returns a Promise of the output, and reports every error by rejecting it. In the browser build, it runs synchronously, on the calling thread.

At most one asynchronous call may be in flight per context: until its Promise settles, another asynchronous call rejects and a synchronous call throws <name> is busy: an asynchronous call has not finished. After close(), calls reject with <name> already closed.

Promise<Buffer<ArrayBufferLike>>


transform(chunk): Buffer

Defined in: index.d.ts:800

Take a chunk of compressed data. By default, keep it and return an empty buffer: the output comes from flush(). Incremental, return the content of the blocks that the chunk completes, and throw if the input is invalid or the output exceeds maxOutputSize.

Buffer<ArrayBufferLike> | Uint8Array<ArrayBufferLike>

Buffer


transformAsync(chunk): Promise<Buffer<ArrayBufferLike>>

Defined in: index.d.ts:840

transform(chunk) on the libuv thread pool: returns a Promise of the output, and reports every error, an invalid argument included, by rejecting it. The chunk is copied before the method returns, so the caller may reuse its memory at once. In the browser build, it runs synchronously, on the calling thread.

At most one asynchronous call may be in flight per context: until its Promise settles, another asynchronous call rejects and a synchronous call throws <name> is busy: an asynchronous call has not finished, such as zstd stream is busy: an asynchronous call has not finished. close() while a call is in flight releases the native state once the call settles, and its Promise still settles. After close(), calls reject with <name> already closed.

Buffer<ArrayBufferLike> | Uint8Array<ArrayBufferLike>

Promise<Buffer<ArrayBufferLike>>