zlib. deflate

Represents a handle for interacting with a deflate stream initiated by deflater().

Example
const zstrmd = deflater(…);

for (let data = ...; data; data = ...) {
	zstrmd.write(data, Z_PARTIAL_FLUSH);	// write uncompressed data to stream
	if (foo)
	let defl = zstrmd.read();	// read back compressed stream content
}

// terminate the stream at the end of data input to complete a valid archive
zstrmd.write(last_data, Z_FINISH);
defl = ztrmd.read();

zstrmd.error();
See
  • module:zlib#deflater()

Methods

error() → {string}nullable

Queries error information.

Returns a string containing a description of the last occurred error or null if there is no error information.

Returns: string

read() → {string}nullable

Reads a chunk of compressed data from the deflate stream.

Returns the current content of the deflate buffer, fed through module:zlib.deflate#write.

Returns compressed chunk on success.

Returns null if an error occurred.

Returns: string

write(src, flushopt, nullable) → {boolean}nullable

Writes a chunk of data to the deflate stream.

Input data must be a string, it is internally compressed by the zlib deflate() routine, the end result is buffered according to the requested flush mode until read via module:zlib.zstrmd#read. Valid flushvalues are Z_NO_FLUSH (the default), Z_SYNC_FLUSH, Z_PARTIAL_FLUSH, Z_FULL_FLUSH, Z_FINISH. If flush is Z_FINISH then no more data can be written to the stream. Refer to the Zlib manual for details on each flush mode.

Returns true on success.

Returns null if an error occurred.

Parameters:
NameTypeDescription
srcstring

The string of data to deflate.

flushnumber(optional, nullable, default: Z_NO_FLUSH)

The zlib flush mode.

Returns: boolean