Class: InflateAuto

InflateAuto(optsopt)

new InflateAuto(optsopt)

Decompressor for DEFLATE compressed data in either zlib, gzip, or "raw" format.

This class is intended to be a drop-in replacement for zlib.Inflate, zlib.InflateRaw, and/or zlib.Gunzip.

This class emits the additional event 'format' when the compression format has been set or detected with the instance of the format class which will be used to decode the data.

Parameters:
Name Type Attributes Description
opts InflateAuto.InflateAutoOptions <optional>
Combined options for this class and for the detected format.
Source:

Extends

  • stream.Transform

Members

(static, constant) detectors :InflateAuto.FormatDetector

Format detectors supported by default.
Type:
Properties:
Name Type Description
detectDeflate InflateAuto.FormatDetector Detects the ZLIB DEFLATE format, as specified in RFC 1950.
detectGzip InflateAuto.FormatDetector Detects the GZIP format, as specified in RFC 1952.
Source:

Methods

(static) createInflateAuto(optsopt) → {InflateAuto}

Creates an instance of InflateAuto. Analogous to zlib.createInflate.
Parameters:
Name Type Attributes Description
opts object <optional>
Constructor options.
Source:
Returns:
Instance of InflateAuto with opts.
Type
InflateAuto

(static) inflateAuto(buffernon-null, optsopt, callbacknon-null)

Decompresses a compressed Buffer. Analogous to zlib.inflate.
Parameters:
Name Type Attributes Description
buffer Buffer Compressed data to decompress.
opts object <optional>
Decompression options.
callback function Callback which receives the decompressed data.
Source:

(static) inflateAutoSync(buffernon-null, optsopt) → (non-null) {Buffer}

Decompresses a compressed Buffer synchronously. Analogous to zlib.inflateSync.
Parameters:
Name Type Attributes Description
buffer Buffer Compressed data to decompress.
opts object <optional>
Decompression options.
Source:
Returns:
Decompressed data.
Type
Buffer

_destroy(err, callback)

Implements #destroy on this stream by ensuring _handle is set null (for _closed) as done by zlib.ZlibBase#_destroy since nodejs/node@8a02d941b6c (v12) and nodejs/node@c6a43fa2ef (v10.15.1).
Parameters:
Name Type Description
err Error Error passed to #destroy.
callback function Callback once destroyed.
Source:

(protected) _detectFormat(chunk, end) → (nullable) {function}

Detects the format of a given Buffer. This method passes chunk to each of the InflateAutoOptions.detectors. The first detector to match is returned. If at least one detector is indeterminate and end is false, null is returned. Otherwise InflateAutoOptions.defaultFormat is returned or an Error is thrown.
Parameters:
Name Type Description
chunk Buffer Beginning of data for which to detect the compression format.
end boolean Is chunk the end of the data stream?
Source:
Throws:
If any detector throws or end is true and no default format is given.
Returns:
An instance of the zlib type which will decode chunk and subsequent data, or null if chunk is too short to deduce the format conclusively and end is false.
Type
function

(protected) _flush(callback)

Flushes any buffered data when the stream is ending.
Parameters:
Name Type Description
callback function Callback once stream has ended.
Source:

(protected) _processChunk(chunknon-null, flushFlag, cbopt, nullable) → {Buffer|undefined}

Process a chunk of data, synchronously or asynchronously.
Parameters:
Name Type Attributes Description
chunk external:ArrayBufferView Chunk of data to write.
flushFlag number Flush flag with which to write the data.
cb function <optional>
<nullable>
Callback. Synchronous if falsey.
Source:
Throws:
If a detector or format constructor throws and cb is not a function.
Returns:
Decompressed chunk if synchronous, otherwise undefined.
Type
Buffer | undefined

(protected) _queueMethodCall(name, argsnon-null)

Queues a method call for the format until one is set.

In addition to queueing the method call, if the arguments includes a callback function, that function is invoked immediately in order to prevent deadlocks in existing code which doesn't write until the callback completes.

Parameters:
Name Type Description
name string Name of the method to call.
args arguments | Array Arguments to pass to the method call.
Source:

(protected) _transform(chunk, encodingnullable, callbackopt, nullable)

Inflates a chunk of data.
Parameters:
Name Type Attributes Description
chunk Buffer Chunk of data to inflate.
encoding string <nullable>
Ignored.
callback function <optional>
<nullable>
Callback once chunk has been written.
Source:

close(callbackopt, nullable)

Closes this stream and its underlying resources (zlib handle).
Parameters:
Name Type Attributes Description
callback function <optional>
<nullable>
Callback once resources have been freed.
Source:

flush(kindopt, callbackopt, nullable)

Flushes queued writes with a given zlib flush behavior.
Parameters:
Name Type Attributes Description
kind number <optional>
Flush behavior of writes to zlib. Must be one of the zlib flush constant values.
callback function <optional>
<nullable>
Callback once data has been flushed.
Source:

getFormat() → (nullable) {function}

Gets the constructor function used to create the decoder for data written to this stream.
Source:
See:
Returns:
Constructor for the stream class which is used to decode data written to this stream, or undefined if the format has not been detected or set.
Type
function

params(level, strategy, callbackopt, nullable)

Sets the inflate compression parameters.

For inflate, this has no effect. This method is kept for compatibility only. It is only defined when Inflate.prototype.params is defined.

Note: Parameter checking is not performed if the format hasn't been determined. Although this is currently possible (since parameters are currently independent of format) it requires instantiating a zlib object with bindings, which is heavy for checking args which haven't changed since this method was added to the Node API. If there is a use case for such checking, please open an issue.

Parameters:
Name Type Attributes Description
level number Compression level (between zlib.Z_MIN_LEVEL and zlib.Z_MAX_LEVEL).
strategy number Compression strategy (one of the zlib strategy constant values).
callback function <optional>
<nullable>
Callback once parameters have been set.
Source:

reset()

Discards any buffered data and resets the decoder to its initial state.

Note: If a format has been detected, reset does not currently clear the detection (for performance and to reduce complexity). If there is a real-world use case for this type of "full reset", please open an issue.

Source:

setFormat(Format)

Sets the format which will be used to decode data written to this stream. Note: The current implementation only allows the format to be set once. Calling this method after the format has been set will throw an exception.
Parameters:
Name Type Description
Format function Constructor for the stream class which will be used to decode data written to this stream.
Source:
See:
Throws:
If previously set to a different Format or Format constructor throws.

Type Definitions

FormatDetector(chunknon-null) → {function|undefined}

A function which detects the format for a given chunk of data. The function may be called any number of times with non-null, non-empty Buffers. The return value can be any of the following:
  1. If a format can be definitively determined: A constructor for the stream.Duplex class of the format which takes the options Object as an argument. An instance of the class will be used to decode data written to this stream.
  2. If all formats supported by this detector can be definitively ruled out: null. This function will not be called again unless the stream is reset.
  3. None of the above: undefined. This function will be called again when more data is available.
Parameters:
Name Type Description
chunk Buffer Non-empty chunk of data to check.
Source:
Returns:
Constructor for a stream.Duplex class to decode chunk and subsequent data written to the stream, null if the format is unrecognized/unsupported, undefined if format detection requires more data.
Type
function | undefined

InflateAutoOptions

Options for InflateAuto. Note that the InflateAuto options object is passed to the constructor for the detected data format to allow drop-in replacement. It may have additional properties to the ones defined here.
Type:
  • Object
Properties:
Name Type Attributes Description
defaultFormat function | boolean Constructor of the format which is used if no detectors match. Pass null or false for no default. (default: InflateRaw)
detectors Array.<!InflateAuto.FormatDetector> <optional>
Functions which detect the data format for a chunk of data and return the constructor for a class to decode the data. If any detector requires large amounts of data, adjust highWaterMark appropriately. (default: [detectDeflate, detectGzip])
Source: