2012-02-27 20:09:35 +01:00
|
|
|
|
# Zlib
|
2011-09-07 01:13:05 +02:00
|
|
|
|
|
2017-01-23 04:16:21 +01:00
|
|
|
|
<!--introduced_in=v0.10.0-->
|
|
|
|
|
|
2016-07-16 00:35:38 +02:00
|
|
|
|
> Stability: 2 - Stable
|
2012-03-03 00:14:03 +01:00
|
|
|
|
|
2016-05-13 22:56:30 +02:00
|
|
|
|
The `zlib` module provides compression functionality implemented using Gzip and
|
2018-12-10 00:06:50 +01:00
|
|
|
|
Deflate/Inflate, as well as Brotli. It can be accessed using:
|
2011-09-07 01:13:05 +02:00
|
|
|
|
|
2016-05-13 22:56:30 +02:00
|
|
|
|
```js
|
|
|
|
|
const zlib = require('zlib');
|
|
|
|
|
```
|
2011-10-14 18:20:05 +02:00
|
|
|
|
|
2016-11-15 18:56:15 +01:00
|
|
|
|
Compressing or decompressing a stream (such as a file) can be accomplished by
|
2016-05-13 22:56:30 +02:00
|
|
|
|
piping the source stream data through a `zlib` stream into a destination stream:
|
2011-10-14 18:20:05 +02:00
|
|
|
|
|
2016-01-17 18:39:07 +01:00
|
|
|
|
```js
|
|
|
|
|
const gzip = zlib.createGzip();
|
|
|
|
|
const fs = require('fs');
|
|
|
|
|
const inp = fs.createReadStream('input.txt');
|
|
|
|
|
const out = fs.createWriteStream('input.txt.gz');
|
2011-09-07 01:13:05 +02:00
|
|
|
|
|
2019-06-08 15:16:21 +02:00
|
|
|
|
inp.pipe(gzip)
|
|
|
|
|
.on('error', () => {
|
|
|
|
|
// handle error
|
|
|
|
|
})
|
|
|
|
|
.pipe(out)
|
|
|
|
|
.on('error', () => {
|
|
|
|
|
// handle error
|
|
|
|
|
});
|
2016-01-17 18:39:07 +01:00
|
|
|
|
```
|
2011-09-07 01:13:05 +02:00
|
|
|
|
|
2016-05-13 22:56:30 +02:00
|
|
|
|
It is also possible to compress or decompress data in a single step:
|
2011-10-24 18:29:24 +02:00
|
|
|
|
|
2016-01-17 18:39:07 +01:00
|
|
|
|
```js
|
|
|
|
|
const input = '.................................';
|
2016-01-24 10:15:51 +01:00
|
|
|
|
zlib.deflate(input, (err, buffer) => {
|
2016-01-17 18:39:07 +01:00
|
|
|
|
if (!err) {
|
|
|
|
|
console.log(buffer.toString('base64'));
|
2016-01-24 10:15:51 +01:00
|
|
|
|
} else {
|
|
|
|
|
// handle error
|
2016-01-17 18:39:07 +01:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2016-04-25 04:36:57 +02:00
|
|
|
|
const buffer = Buffer.from('eJzT0yMAAGTvBe8=', 'base64');
|
2016-01-24 10:15:51 +01:00
|
|
|
|
zlib.unzip(buffer, (err, buffer) => {
|
2016-01-17 18:39:07 +01:00
|
|
|
|
if (!err) {
|
|
|
|
|
console.log(buffer.toString());
|
2016-01-24 10:15:51 +01:00
|
|
|
|
} else {
|
|
|
|
|
// handle error
|
2016-01-17 18:39:07 +01:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
```
|
2011-10-24 18:29:24 +02:00
|
|
|
|
|
2017-08-23 23:59:06 +02:00
|
|
|
|
## Threadpool Usage
|
|
|
|
|
|
2019-06-20 21:32:36 +02:00
|
|
|
|
All zlib APIs, except those that are explicitly synchronous, use libuv's
|
2018-04-28 13:00:04 +02:00
|
|
|
|
threadpool. This can lead to surprising effects in some applications, such as
|
|
|
|
|
subpar performance (which can be mitigated by adjusting the [pool size][])
|
|
|
|
|
and/or unrecoverable and catastrophic memory fragmentation.
|
2017-08-23 23:59:06 +02:00
|
|
|
|
|
2016-05-13 22:56:30 +02:00
|
|
|
|
## Compressing HTTP requests and responses
|
|
|
|
|
|
2018-12-10 00:06:50 +01:00
|
|
|
|
The `zlib` module can be used to implement support for the `gzip`, `deflate`
|
|
|
|
|
and `br` content-encoding mechanisms defined by
|
2016-05-13 22:56:30 +02:00
|
|
|
|
[HTTP](https://tools.ietf.org/html/rfc7230#section-4.2).
|
|
|
|
|
|
|
|
|
|
The HTTP [`Accept-Encoding`][] header is used within an http request to identify
|
2016-11-15 18:56:15 +01:00
|
|
|
|
the compression encodings accepted by the client. The [`Content-Encoding`][]
|
|
|
|
|
header is used to identify the compression encodings actually applied to a
|
2016-05-13 22:56:30 +02:00
|
|
|
|
message.
|
2011-10-14 18:20:05 +02:00
|
|
|
|
|
2018-02-06 06:55:16 +01:00
|
|
|
|
The examples given below are drastically simplified to show the basic concept.
|
|
|
|
|
Using `zlib` encoding can be expensive, and the results ought to be cached.
|
|
|
|
|
See [Memory Usage Tuning][] for more information on the speed/memory/compression
|
|
|
|
|
tradeoffs involved in `zlib` usage.
|
2011-10-14 18:20:05 +02:00
|
|
|
|
|
2016-01-17 18:39:07 +01:00
|
|
|
|
```js
|
2019-03-22 03:44:26 +01:00
|
|
|
|
// Client request example
|
2016-01-17 18:39:07 +01:00
|
|
|
|
const zlib = require('zlib');
|
|
|
|
|
const http = require('http');
|
|
|
|
|
const fs = require('fs');
|
2016-05-13 22:56:30 +02:00
|
|
|
|
const request = http.get({ host: 'example.com',
|
2017-04-21 16:38:31 +02:00
|
|
|
|
path: '/',
|
|
|
|
|
port: 80,
|
2018-12-10 00:06:50 +01:00
|
|
|
|
headers: { 'Accept-Encoding': 'br,gzip,deflate' } });
|
2016-01-17 18:39:07 +01:00
|
|
|
|
request.on('response', (response) => {
|
2017-04-22 14:22:40 +02:00
|
|
|
|
const output = fs.createWriteStream('example.com_index.html');
|
2016-01-17 18:39:07 +01:00
|
|
|
|
|
|
|
|
|
switch (response.headers['content-encoding']) {
|
2018-12-10 00:06:50 +01:00
|
|
|
|
case 'br':
|
|
|
|
|
response.pipe(zlib.createBrotliDecompress()).pipe(output);
|
|
|
|
|
break;
|
|
|
|
|
// Or, just use zlib.createUnzip() to handle both of the following cases:
|
2016-01-17 18:39:07 +01:00
|
|
|
|
case 'gzip':
|
|
|
|
|
response.pipe(zlib.createGunzip()).pipe(output);
|
|
|
|
|
break;
|
|
|
|
|
case 'deflate':
|
|
|
|
|
response.pipe(zlib.createInflate()).pipe(output);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
response.pipe(output);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
});
|
2017-04-21 06:53:00 +02:00
|
|
|
|
```
|
2016-01-17 18:39:07 +01:00
|
|
|
|
|
2017-04-21 06:53:00 +02:00
|
|
|
|
```js
|
2016-01-17 18:39:07 +01:00
|
|
|
|
// server example
|
|
|
|
|
// Running a gzip operation on every request is quite expensive.
|
|
|
|
|
// It would be much more efficient to cache the compressed buffer.
|
|
|
|
|
const zlib = require('zlib');
|
|
|
|
|
const http = require('http');
|
|
|
|
|
const fs = require('fs');
|
|
|
|
|
http.createServer((request, response) => {
|
2017-04-22 14:22:40 +02:00
|
|
|
|
const raw = fs.createReadStream('index.html');
|
2019-02-26 01:55:45 +01:00
|
|
|
|
// Store both a compressed and an uncompressed version of the resource.
|
|
|
|
|
response.setHeader('Vary: Accept-Encoding');
|
2017-04-22 14:22:40 +02:00
|
|
|
|
let acceptEncoding = request.headers['accept-encoding'];
|
2016-01-17 18:39:07 +01:00
|
|
|
|
if (!acceptEncoding) {
|
|
|
|
|
acceptEncoding = '';
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-20 22:15:58 +02:00
|
|
|
|
// Note: This is not a conformant accept-encoding parser.
|
2017-11-23 00:04:16 +01:00
|
|
|
|
// See https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.3
|
2017-05-31 20:10:55 +02:00
|
|
|
|
if (/\bdeflate\b/.test(acceptEncoding)) {
|
2016-05-13 22:56:30 +02:00
|
|
|
|
response.writeHead(200, { 'Content-Encoding': 'deflate' });
|
2016-01-17 18:39:07 +01:00
|
|
|
|
raw.pipe(zlib.createDeflate()).pipe(response);
|
2017-05-31 20:10:55 +02:00
|
|
|
|
} else if (/\bgzip\b/.test(acceptEncoding)) {
|
2016-05-13 22:56:30 +02:00
|
|
|
|
response.writeHead(200, { 'Content-Encoding': 'gzip' });
|
2016-01-17 18:39:07 +01:00
|
|
|
|
raw.pipe(zlib.createGzip()).pipe(response);
|
2018-12-10 00:06:50 +01:00
|
|
|
|
} else if (/\bbr\b/.test(acceptEncoding)) {
|
|
|
|
|
response.writeHead(200, { 'Content-Encoding': 'br' });
|
|
|
|
|
raw.pipe(zlib.createBrotliCompress()).pipe(response);
|
2016-01-17 18:39:07 +01:00
|
|
|
|
} else {
|
|
|
|
|
response.writeHead(200, {});
|
|
|
|
|
raw.pipe(response);
|
|
|
|
|
}
|
|
|
|
|
}).listen(1337);
|
|
|
|
|
```
|
2011-09-07 01:13:05 +02:00
|
|
|
|
|
2016-10-17 02:20:56 +02:00
|
|
|
|
By default, the `zlib` methods will throw an error when decompressing
|
2016-04-06 00:54:34 +02:00
|
|
|
|
truncated data. However, if it is known that the data is incomplete, or
|
|
|
|
|
the desire is to inspect only the beginning of a compressed file, it is
|
|
|
|
|
possible to suppress the default error handling by changing the flushing
|
2017-05-31 20:10:55 +02:00
|
|
|
|
method that is used to decompress the last chunk of input data:
|
2016-04-06 00:54:34 +02:00
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
// This is a truncated version of the buffer from the above examples
|
2016-04-25 04:36:57 +02:00
|
|
|
|
const buffer = Buffer.from('eJzT0yMA', 'base64');
|
2016-04-06 00:54:34 +02:00
|
|
|
|
|
2017-04-21 16:38:31 +02:00
|
|
|
|
zlib.unzip(
|
|
|
|
|
buffer,
|
2018-12-10 00:06:50 +01:00
|
|
|
|
// For Brotli, the equivalent is zlib.constants.BROTLI_OPERATION_FLUSH.
|
2017-05-31 20:10:55 +02:00
|
|
|
|
{ finishFlush: zlib.constants.Z_SYNC_FLUSH },
|
2017-04-21 16:38:31 +02:00
|
|
|
|
(err, buffer) => {
|
|
|
|
|
if (!err) {
|
|
|
|
|
console.log(buffer.toString());
|
|
|
|
|
} else {
|
|
|
|
|
// handle error
|
|
|
|
|
}
|
|
|
|
|
});
|
2016-04-06 00:54:34 +02:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
This will not change the behavior in other error-throwing situations, e.g.
|
|
|
|
|
when the input data has an invalid format. Using this method, it will not be
|
|
|
|
|
possible to determine whether the input ended prematurely or lacks the
|
|
|
|
|
integrity checks, making it necessary to manually check that the
|
|
|
|
|
decompressed result is valid.
|
|
|
|
|
|
2012-02-27 20:09:35 +01:00
|
|
|
|
## Memory Usage Tuning
|
|
|
|
|
|
|
|
|
|
<!--type=misc-->
|
2011-09-07 01:13:05 +02:00
|
|
|
|
|
2018-12-10 00:06:50 +01:00
|
|
|
|
### For zlib-based streams
|
|
|
|
|
|
2018-03-04 14:46:49 +01:00
|
|
|
|
From `zlib/zconf.h`, modified to Node.js's usage:
|
2011-09-07 01:13:05 +02:00
|
|
|
|
|
|
|
|
|
The memory requirements for deflate are (in bytes):
|
|
|
|
|
|
2017-04-21 21:55:51 +02:00
|
|
|
|
<!-- eslint-disable semi -->
|
2016-07-09 07:13:09 +02:00
|
|
|
|
```js
|
2017-04-21 21:55:51 +02:00
|
|
|
|
(1 << (windowBits + 2)) + (1 << (memLevel + 9))
|
2016-01-17 18:39:07 +01:00
|
|
|
|
```
|
2011-09-07 01:13:05 +02:00
|
|
|
|
|
2018-04-29 19:46:41 +02:00
|
|
|
|
That is: 128K for `windowBits` = 15 + 128K for `memLevel` = 8
|
2011-09-07 01:13:05 +02:00
|
|
|
|
(default values) plus a few kilobytes for small objects.
|
|
|
|
|
|
2016-05-13 22:56:30 +02:00
|
|
|
|
For example, to reduce the default memory requirements from 256K to 128K, the
|
2016-09-01 16:55:42 +02:00
|
|
|
|
options should be set to:
|
2011-09-07 01:13:05 +02:00
|
|
|
|
|
2016-07-09 07:13:09 +02:00
|
|
|
|
```js
|
2017-04-21 06:53:00 +02:00
|
|
|
|
const options = { windowBits: 14, memLevel: 7 };
|
2016-01-17 18:39:07 +01:00
|
|
|
|
```
|
2011-09-07 01:13:05 +02:00
|
|
|
|
|
2016-05-13 22:56:30 +02:00
|
|
|
|
This will, however, generally degrade compression.
|
2011-09-07 01:13:05 +02:00
|
|
|
|
|
2017-04-21 21:55:51 +02:00
|
|
|
|
The memory requirements for inflate are (in bytes) `1 << windowBits`.
|
2018-04-29 19:46:41 +02:00
|
|
|
|
That is, 32K for `windowBits` = 15 (default value) plus a few kilobytes
|
2011-09-07 01:13:05 +02:00
|
|
|
|
for small objects.
|
|
|
|
|
|
|
|
|
|
This is in addition to a single internal output slab buffer of size
|
|
|
|
|
`chunkSize`, which defaults to 16K.
|
2011-10-14 18:20:05 +02:00
|
|
|
|
|
2016-05-13 22:56:30 +02:00
|
|
|
|
The speed of `zlib` compression is affected most dramatically by the
|
2018-04-02 07:38:48 +02:00
|
|
|
|
`level` setting. A higher level will result in better compression, but
|
|
|
|
|
will take longer to complete. A lower level will result in less
|
2011-10-14 18:20:05 +02:00
|
|
|
|
compression, but will be much faster.
|
|
|
|
|
|
2016-05-13 22:56:30 +02:00
|
|
|
|
In general, greater memory usage options will mean that Node.js has to make
|
|
|
|
|
fewer calls to `zlib` because it will be able to process more data on
|
2018-04-02 07:38:48 +02:00
|
|
|
|
each `write` operation. So, this is another factor that affects the
|
2011-10-14 18:20:05 +02:00
|
|
|
|
speed, at the cost of memory usage.
|
2012-06-15 07:17:39 +02:00
|
|
|
|
|
2018-12-10 00:06:50 +01:00
|
|
|
|
### For Brotli-based streams
|
|
|
|
|
|
|
|
|
|
There are equivalents to the zlib options for Brotli-based streams, although
|
|
|
|
|
these options have different ranges than the zlib ones:
|
|
|
|
|
|
2019-09-13 06:22:29 +02:00
|
|
|
|
* zlib’s `level` option matches Brotli’s `BROTLI_PARAM_QUALITY` option.
|
|
|
|
|
* zlib’s `windowBits` option matches Brotli’s `BROTLI_PARAM_LGWIN` option.
|
2018-12-10 00:06:50 +01:00
|
|
|
|
|
|
|
|
|
See [below][Brotli parameters] for more details on Brotli-specific options.
|
|
|
|
|
|
2016-04-19 10:04:07 +02:00
|
|
|
|
## Flushing
|
|
|
|
|
|
2016-05-13 22:56:30 +02:00
|
|
|
|
Calling [`.flush()`][] on a compression stream will make `zlib` return as much
|
2016-04-19 10:04:07 +02:00
|
|
|
|
output as currently possible. This may come at the cost of degraded compression
|
|
|
|
|
quality, but can be useful when data needs to be available as soon as possible.
|
|
|
|
|
|
|
|
|
|
In the following example, `flush()` is used to write a compressed partial
|
|
|
|
|
HTTP response to the client:
|
2019-08-29 15:28:03 +02:00
|
|
|
|
|
2016-04-19 10:04:07 +02:00
|
|
|
|
```js
|
|
|
|
|
const zlib = require('zlib');
|
|
|
|
|
const http = require('http');
|
|
|
|
|
|
|
|
|
|
http.createServer((request, response) => {
|
|
|
|
|
// For the sake of simplicity, the Accept-Encoding checks are omitted.
|
|
|
|
|
response.writeHead(200, { 'content-encoding': 'gzip' });
|
|
|
|
|
const output = zlib.createGzip();
|
|
|
|
|
output.pipe(response);
|
|
|
|
|
|
|
|
|
|
setInterval(() => {
|
|
|
|
|
output.write(`The current time is ${Date()}\n`, () => {
|
|
|
|
|
// The data has been passed to zlib, but the compression algorithm may
|
|
|
|
|
// have decided to buffer the data for more efficient compression.
|
|
|
|
|
// Calling .flush() will make the data available as soon as the client
|
|
|
|
|
// is ready to receive it.
|
|
|
|
|
output.flush();
|
|
|
|
|
});
|
|
|
|
|
}, 1000);
|
|
|
|
|
}).listen(1337);
|
|
|
|
|
```
|
|
|
|
|
|
2012-06-15 07:17:39 +02:00
|
|
|
|
## Constants
|
2016-05-18 16:30:23 +02:00
|
|
|
|
<!-- YAML
|
|
|
|
|
added: v0.5.8
|
|
|
|
|
-->
|
2012-06-15 07:17:39 +02:00
|
|
|
|
|
|
|
|
|
<!--type=misc-->
|
|
|
|
|
|
2018-12-10 00:06:50 +01:00
|
|
|
|
### zlib constants
|
|
|
|
|
|
2016-06-07 23:38:00 +02:00
|
|
|
|
All of the constants defined in `zlib.h` are also defined on
|
|
|
|
|
`require('zlib').constants`. In the normal course of operations, it will not be
|
2018-04-02 07:38:48 +02:00
|
|
|
|
necessary to use these constants. They are documented so that their presence is
|
2016-06-07 23:38:00 +02:00
|
|
|
|
not surprising. This section is taken almost directly from the
|
2019-07-06 16:53:01 +02:00
|
|
|
|
[zlib documentation][].
|
2016-06-07 23:38:00 +02:00
|
|
|
|
|
2018-02-06 06:55:16 +01:00
|
|
|
|
Previously, the constants were available directly from `require('zlib')`, for
|
|
|
|
|
instance `zlib.Z_NO_FLUSH`. Accessing the constants directly from the module is
|
|
|
|
|
currently still possible but is deprecated.
|
2012-06-15 07:17:39 +02:00
|
|
|
|
|
|
|
|
|
Allowed flush values.
|
|
|
|
|
|
2016-06-07 23:38:00 +02:00
|
|
|
|
* `zlib.constants.Z_NO_FLUSH`
|
|
|
|
|
* `zlib.constants.Z_PARTIAL_FLUSH`
|
|
|
|
|
* `zlib.constants.Z_SYNC_FLUSH`
|
|
|
|
|
* `zlib.constants.Z_FULL_FLUSH`
|
|
|
|
|
* `zlib.constants.Z_FINISH`
|
|
|
|
|
* `zlib.constants.Z_BLOCK`
|
|
|
|
|
* `zlib.constants.Z_TREES`
|
2012-06-15 07:17:39 +02:00
|
|
|
|
|
|
|
|
|
Return codes for the compression/decompression functions. Negative
|
|
|
|
|
values are errors, positive values are used for special but normal
|
|
|
|
|
events.
|
|
|
|
|
|
2016-06-07 23:38:00 +02:00
|
|
|
|
* `zlib.constants.Z_OK`
|
|
|
|
|
* `zlib.constants.Z_STREAM_END`
|
|
|
|
|
* `zlib.constants.Z_NEED_DICT`
|
|
|
|
|
* `zlib.constants.Z_ERRNO`
|
|
|
|
|
* `zlib.constants.Z_STREAM_ERROR`
|
|
|
|
|
* `zlib.constants.Z_DATA_ERROR`
|
|
|
|
|
* `zlib.constants.Z_MEM_ERROR`
|
|
|
|
|
* `zlib.constants.Z_BUF_ERROR`
|
|
|
|
|
* `zlib.constants.Z_VERSION_ERROR`
|
2012-06-15 07:17:39 +02:00
|
|
|
|
|
|
|
|
|
Compression levels.
|
|
|
|
|
|
2016-06-07 23:38:00 +02:00
|
|
|
|
* `zlib.constants.Z_NO_COMPRESSION`
|
|
|
|
|
* `zlib.constants.Z_BEST_SPEED`
|
|
|
|
|
* `zlib.constants.Z_BEST_COMPRESSION`
|
|
|
|
|
* `zlib.constants.Z_DEFAULT_COMPRESSION`
|
2012-06-15 07:17:39 +02:00
|
|
|
|
|
|
|
|
|
Compression strategy.
|
|
|
|
|
|
2016-06-07 23:38:00 +02:00
|
|
|
|
* `zlib.constants.Z_FILTERED`
|
|
|
|
|
* `zlib.constants.Z_HUFFMAN_ONLY`
|
|
|
|
|
* `zlib.constants.Z_RLE`
|
|
|
|
|
* `zlib.constants.Z_FIXED`
|
|
|
|
|
* `zlib.constants.Z_DEFAULT_STRATEGY`
|
2015-11-05 16:40:47 +01:00
|
|
|
|
|
2018-12-10 00:06:50 +01:00
|
|
|
|
### Brotli constants
|
|
|
|
|
<!-- YAML
|
2019-01-16 15:55:55 +01:00
|
|
|
|
added: v11.7.0
|
2018-12-10 00:06:50 +01:00
|
|
|
|
-->
|
|
|
|
|
|
|
|
|
|
There are several options and other constants available for Brotli-based
|
|
|
|
|
streams:
|
|
|
|
|
|
|
|
|
|
#### Flush operations
|
|
|
|
|
|
|
|
|
|
The following values are valid flush operations for Brotli-based streams:
|
|
|
|
|
|
|
|
|
|
* `zlib.constants.BROTLI_OPERATION_PROCESS` (default for all operations)
|
|
|
|
|
* `zlib.constants.BROTLI_OPERATION_FLUSH` (default when calling `.flush()`)
|
|
|
|
|
* `zlib.constants.BROTLI_OPERATION_FINISH` (default for the last chunk)
|
|
|
|
|
* `zlib.constants.BROTLI_OPERATION_EMIT_METADATA`
|
|
|
|
|
* This particular operation may be hard to use in a Node.js context,
|
|
|
|
|
as the streaming layer makes it hard to know which data will end up
|
|
|
|
|
in this frame. Also, there is currently no way to consume this data through
|
|
|
|
|
the Node.js API.
|
|
|
|
|
|
|
|
|
|
#### Compressor options
|
|
|
|
|
|
|
|
|
|
There are several options that can be set on Brotli encoders, affecting
|
|
|
|
|
compression efficiency and speed. Both the keys and the values can be accessed
|
|
|
|
|
as properties of the `zlib.constants` object.
|
|
|
|
|
|
|
|
|
|
The most important options are:
|
|
|
|
|
|
|
|
|
|
* `BROTLI_PARAM_MODE`
|
|
|
|
|
* `BROTLI_MODE_GENERIC` (default)
|
|
|
|
|
* `BROTLI_MODE_TEXT`, adjusted for UTF-8 text
|
|
|
|
|
* `BROTLI_MODE_FONT`, adjusted for WOFF 2.0 fonts
|
|
|
|
|
* `BROTLI_PARAM_QUALITY`
|
|
|
|
|
* Ranges from `BROTLI_MIN_QUALITY` to `BROTLI_MAX_QUALITY`,
|
|
|
|
|
with a default of `BROTLI_DEFAULT_QUALITY`.
|
|
|
|
|
* `BROTLI_PARAM_SIZE_HINT`
|
|
|
|
|
* Integer value representing the expected input size;
|
|
|
|
|
defaults to `0` for an unknown input size.
|
|
|
|
|
|
|
|
|
|
The following flags can be set for advanced control over the compression
|
|
|
|
|
algorithm and memory usage tuning:
|
|
|
|
|
|
|
|
|
|
* `BROTLI_PARAM_LGWIN`
|
|
|
|
|
* Ranges from `BROTLI_MIN_WINDOW_BITS` to `BROTLI_MAX_WINDOW_BITS`,
|
|
|
|
|
with a default of `BROTLI_DEFAULT_WINDOW`, or up to
|
|
|
|
|
`BROTLI_LARGE_MAX_WINDOW_BITS` if the `BROTLI_PARAM_LARGE_WINDOW` flag
|
|
|
|
|
is set.
|
|
|
|
|
* `BROTLI_PARAM_LGBLOCK`
|
|
|
|
|
* Ranges from `BROTLI_MIN_INPUT_BLOCK_BITS` to `BROTLI_MAX_INPUT_BLOCK_BITS`.
|
|
|
|
|
* `BROTLI_PARAM_DISABLE_LITERAL_CONTEXT_MODELING`
|
|
|
|
|
* Boolean flag that decreases compression ratio in favour of
|
|
|
|
|
decompression speed.
|
|
|
|
|
* `BROTLI_PARAM_LARGE_WINDOW`
|
|
|
|
|
* Boolean flag enabling “Large Window Brotli” mode (not compatible with the
|
|
|
|
|
Brotli format as standardized in [RFC 7932][]).
|
|
|
|
|
* `BROTLI_PARAM_NPOSTFIX`
|
|
|
|
|
* Ranges from `0` to `BROTLI_MAX_NPOSTFIX`.
|
|
|
|
|
* `BROTLI_PARAM_NDIRECT`
|
|
|
|
|
* Ranges from `0` to `15 << NPOSTFIX` in steps of `1 << NPOSTFIX`.
|
|
|
|
|
|
|
|
|
|
#### Decompressor options
|
|
|
|
|
|
|
|
|
|
These advanced options are available for controlling decompression:
|
|
|
|
|
|
|
|
|
|
* `BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATION`
|
|
|
|
|
* Boolean flag that affects internal memory allocation patterns.
|
|
|
|
|
* `BROTLI_DECODER_PARAM_LARGE_WINDOW`
|
|
|
|
|
* Boolean flag enabling “Large Window Brotli” mode (not compatible with the
|
|
|
|
|
Brotli format as standardized in [RFC 7932][]).
|
|
|
|
|
|
2019-12-25 00:47:04 +01:00
|
|
|
|
## Class: `Options`
|
2016-05-18 16:30:23 +02:00
|
|
|
|
<!-- YAML
|
|
|
|
|
added: v0.11.1
|
2017-02-21 23:38:50 +01:00
|
|
|
|
changes:
|
2018-01-10 01:23:55 +01:00
|
|
|
|
- version: v9.4.0
|
2017-10-06 21:19:33 +02:00
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/16042
|
2018-04-29 19:46:41 +02:00
|
|
|
|
description: The `dictionary` option can be an `ArrayBuffer`.
|
2017-03-16 04:26:14 +01:00
|
|
|
|
- version: v8.0.0
|
2017-03-23 03:45:03 +01:00
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/12001
|
2018-04-29 19:46:41 +02:00
|
|
|
|
description: The `dictionary` option can be an `Uint8Array` now.
|
2017-02-21 23:38:50 +01:00
|
|
|
|
- version: v5.11.0
|
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/6069
|
|
|
|
|
description: The `finishFlush` option is supported now.
|
2016-05-18 16:30:23 +02:00
|
|
|
|
-->
|
2015-11-05 16:40:47 +01:00
|
|
|
|
|
|
|
|
|
<!--type=misc-->
|
|
|
|
|
|
2018-12-10 00:06:50 +01:00
|
|
|
|
Each zlib-based class takes an `options` object. All options are optional.
|
2015-11-05 16:40:47 +01:00
|
|
|
|
|
2019-06-20 21:32:36 +02:00
|
|
|
|
Some options are only relevant when compressing and are
|
2015-11-05 16:40:47 +01:00
|
|
|
|
ignored by the decompression classes.
|
|
|
|
|
|
2018-04-02 03:44:32 +02:00
|
|
|
|
* `flush` {integer} **Default:** `zlib.constants.Z_NO_FLUSH`
|
|
|
|
|
* `finishFlush` {integer} **Default:** `zlib.constants.Z_FINISH`
|
|
|
|
|
* `chunkSize` {integer} **Default:** `16 * 1024`
|
2017-03-23 03:45:03 +01:00
|
|
|
|
* `windowBits` {integer}
|
|
|
|
|
* `level` {integer} (compression only)
|
|
|
|
|
* `memLevel` {integer} (compression only)
|
|
|
|
|
* `strategy` {integer} (compression only)
|
2017-10-06 21:19:33 +02:00
|
|
|
|
* `dictionary` {Buffer|TypedArray|DataView|ArrayBuffer} (deflate/inflate only,
|
|
|
|
|
empty dictionary by default)
|
2018-04-29 13:16:44 +02:00
|
|
|
|
* `info` {boolean} (If `true`, returns an object with `buffer` and `engine`.)
|
2015-11-05 16:40:47 +01:00
|
|
|
|
|
2019-07-06 16:53:01 +02:00
|
|
|
|
See the [`deflateInit2` and `inflateInit2`][] documentation for more
|
|
|
|
|
information.
|
2015-11-05 16:40:47 +01:00
|
|
|
|
|
2019-12-25 00:47:04 +01:00
|
|
|
|
## Class: `BrotliOptions`
|
2018-12-10 00:06:50 +01:00
|
|
|
|
<!-- YAML
|
2019-01-16 15:55:55 +01:00
|
|
|
|
added: v11.7.0
|
2018-12-10 00:06:50 +01:00
|
|
|
|
-->
|
|
|
|
|
|
|
|
|
|
<!--type=misc-->
|
|
|
|
|
|
|
|
|
|
Each Brotli-based class takes an `options` object. All options are optional.
|
|
|
|
|
|
|
|
|
|
* `flush` {integer} **Default:** `zlib.constants.BROTLI_OPERATION_PROCESS`
|
|
|
|
|
* `finishFlush` {integer} **Default:** `zlib.constants.BROTLI_OPERATION_FINISH`
|
|
|
|
|
* `chunkSize` {integer} **Default:** `16 * 1024`
|
|
|
|
|
* `params` {Object} Key-value object containing indexed [Brotli parameters][].
|
|
|
|
|
|
|
|
|
|
For example:
|
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
const stream = zlib.createBrotliCompress({
|
|
|
|
|
chunkSize: 32 * 1024,
|
|
|
|
|
params: {
|
|
|
|
|
[zlib.constants.BROTLI_PARAM_MODE]: zlib.constants.BROTLI_MODE_TEXT,
|
|
|
|
|
[zlib.constants.BROTLI_PARAM_QUALITY]: 4,
|
|
|
|
|
[zlib.constants.BROTLI_PARAM_SIZE_HINT]: fs.statSync(inputFile).size
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
```
|
|
|
|
|
|
2019-12-25 00:47:04 +01:00
|
|
|
|
## Class: `zlib.BrotliCompress`
|
2018-12-10 00:06:50 +01:00
|
|
|
|
<!-- YAML
|
2019-01-16 15:55:55 +01:00
|
|
|
|
added: v11.7.0
|
2018-12-10 00:06:50 +01:00
|
|
|
|
-->
|
|
|
|
|
|
|
|
|
|
Compress data using the Brotli algorithm.
|
|
|
|
|
|
2019-12-25 00:47:04 +01:00
|
|
|
|
## Class: `zlib.BrotliDecompress`
|
2018-12-10 00:06:50 +01:00
|
|
|
|
<!-- YAML
|
2019-01-16 15:55:55 +01:00
|
|
|
|
added: v11.7.0
|
2018-12-10 00:06:50 +01:00
|
|
|
|
-->
|
|
|
|
|
|
|
|
|
|
Decompress data using the Brotli algorithm.
|
|
|
|
|
|
2019-12-25 00:47:04 +01:00
|
|
|
|
## Class: `zlib.Deflate`
|
2016-05-18 16:30:23 +02:00
|
|
|
|
<!-- YAML
|
|
|
|
|
added: v0.5.8
|
|
|
|
|
-->
|
2015-11-05 16:40:47 +01:00
|
|
|
|
|
|
|
|
|
Compress data using deflate.
|
|
|
|
|
|
2019-12-25 00:47:04 +01:00
|
|
|
|
## Class: `zlib.DeflateRaw`
|
2016-05-18 16:30:23 +02:00
|
|
|
|
<!-- YAML
|
|
|
|
|
added: v0.5.8
|
|
|
|
|
-->
|
2015-11-05 16:40:47 +01:00
|
|
|
|
|
2016-05-13 22:56:30 +02:00
|
|
|
|
Compress data using deflate, and do not append a `zlib` header.
|
2015-11-05 16:40:47 +01:00
|
|
|
|
|
2019-12-25 00:47:04 +01:00
|
|
|
|
## Class: `zlib.Gunzip`
|
2016-05-18 16:30:23 +02:00
|
|
|
|
<!-- YAML
|
|
|
|
|
added: v0.5.8
|
2017-02-21 23:38:50 +01:00
|
|
|
|
changes:
|
|
|
|
|
- version: v6.0.0
|
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/5883
|
|
|
|
|
description: Trailing garbage at the end of the input stream will now
|
2018-04-09 18:30:22 +02:00
|
|
|
|
result in an `'error'` event.
|
2017-02-21 23:38:50 +01:00
|
|
|
|
- version: v5.9.0
|
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/5120
|
|
|
|
|
description: Multiple concatenated gzip file members are supported now.
|
|
|
|
|
- version: v5.0.0
|
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/2595
|
2018-04-09 18:30:22 +02:00
|
|
|
|
description: A truncated input stream will now result in an `'error'` event.
|
2016-05-18 16:30:23 +02:00
|
|
|
|
-->
|
2015-11-05 16:40:47 +01:00
|
|
|
|
|
|
|
|
|
Decompress a gzip stream.
|
|
|
|
|
|
2019-12-25 00:47:04 +01:00
|
|
|
|
## Class: `zlib.Gzip`
|
2016-05-18 16:30:23 +02:00
|
|
|
|
<!-- YAML
|
|
|
|
|
added: v0.5.8
|
|
|
|
|
-->
|
2015-11-05 16:40:47 +01:00
|
|
|
|
|
|
|
|
|
Compress data using gzip.
|
|
|
|
|
|
2019-12-25 00:47:04 +01:00
|
|
|
|
## Class: `zlib.Inflate`
|
2016-05-18 16:30:23 +02:00
|
|
|
|
<!-- YAML
|
|
|
|
|
added: v0.5.8
|
2017-02-21 23:38:50 +01:00
|
|
|
|
changes:
|
|
|
|
|
- version: v5.0.0
|
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/2595
|
2018-04-09 18:30:22 +02:00
|
|
|
|
description: A truncated input stream will now result in an `'error'` event.
|
2016-05-18 16:30:23 +02:00
|
|
|
|
-->
|
2015-11-05 16:40:47 +01:00
|
|
|
|
|
|
|
|
|
Decompress a deflate stream.
|
|
|
|
|
|
2019-12-25 00:47:04 +01:00
|
|
|
|
## Class: `zlib.InflateRaw`
|
2016-05-18 16:30:23 +02:00
|
|
|
|
<!-- YAML
|
|
|
|
|
added: v0.5.8
|
2017-02-21 23:38:50 +01:00
|
|
|
|
changes:
|
|
|
|
|
- version: v6.8.0
|
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/8512
|
|
|
|
|
description: Custom dictionaries are now supported by `InflateRaw`.
|
|
|
|
|
- version: v5.0.0
|
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/2595
|
2018-04-09 18:30:22 +02:00
|
|
|
|
description: A truncated input stream will now result in an `'error'` event.
|
2016-05-18 16:30:23 +02:00
|
|
|
|
-->
|
2015-11-05 16:40:47 +01:00
|
|
|
|
|
|
|
|
|
Decompress a raw deflate stream.
|
|
|
|
|
|
2019-12-25 00:47:04 +01:00
|
|
|
|
## Class: `zlib.Unzip`
|
2016-05-18 16:30:23 +02:00
|
|
|
|
<!-- YAML
|
|
|
|
|
added: v0.5.8
|
|
|
|
|
-->
|
2015-11-05 16:40:47 +01:00
|
|
|
|
|
|
|
|
|
Decompress either a Gzip- or Deflate-compressed stream by auto-detecting
|
|
|
|
|
the header.
|
|
|
|
|
|
2019-12-25 00:47:04 +01:00
|
|
|
|
## Class: `zlib.ZlibBase`
|
2016-05-18 16:30:23 +02:00
|
|
|
|
<!-- YAML
|
|
|
|
|
added: v0.5.8
|
2018-12-10 00:06:50 +01:00
|
|
|
|
changes:
|
2019-01-16 15:55:55 +01:00
|
|
|
|
- version: v11.7.0
|
2018-12-10 00:06:50 +01:00
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/24939
|
|
|
|
|
description: This class was renamed from `Zlib` to `ZlibBase`.
|
2016-05-18 16:30:23 +02:00
|
|
|
|
-->
|
2015-11-05 16:40:47 +01:00
|
|
|
|
|
|
|
|
|
Not exported by the `zlib` module. It is documented here because it is the base
|
|
|
|
|
class of the compressor/decompressor classes.
|
|
|
|
|
|
2018-08-16 08:03:15 +02:00
|
|
|
|
This class inherits from [`stream.Transform`][], allowing `zlib` objects to be
|
|
|
|
|
used in pipes and similar stream operations.
|
|
|
|
|
|
2019-12-25 00:47:04 +01:00
|
|
|
|
### `zlib.bytesRead`
|
2017-05-18 02:09:00 +02:00
|
|
|
|
<!-- YAML
|
2017-11-16 15:32:56 +01:00
|
|
|
|
added: v8.1.0
|
2018-03-02 18:53:46 +01:00
|
|
|
|
deprecated: v10.0.0
|
2017-05-18 02:09:00 +02:00
|
|
|
|
-->
|
|
|
|
|
|
2018-03-17 16:59:54 +01:00
|
|
|
|
> Stability: 0 - Deprecated: Use [`zlib.bytesWritten`][] instead.
|
|
|
|
|
|
2017-05-18 02:09:00 +02:00
|
|
|
|
* {number}
|
|
|
|
|
|
2018-03-17 16:59:54 +01:00
|
|
|
|
Deprecated alias for [`zlib.bytesWritten`][]. This original name was chosen
|
|
|
|
|
because it also made sense to interpret the value as the number of bytes
|
|
|
|
|
read by the engine, but is inconsistent with other streams in Node.js that
|
|
|
|
|
expose values under these names.
|
|
|
|
|
|
2019-12-25 00:47:04 +01:00
|
|
|
|
### `zlib.bytesWritten`
|
2018-03-17 16:59:54 +01:00
|
|
|
|
<!-- YAML
|
2018-03-02 18:53:46 +01:00
|
|
|
|
added: v10.0.0
|
2018-03-17 16:59:54 +01:00
|
|
|
|
-->
|
|
|
|
|
|
|
|
|
|
* {number}
|
|
|
|
|
|
|
|
|
|
The `zlib.bytesWritten` property specifies the number of bytes written to
|
|
|
|
|
the engine, before the bytes are processed (compressed or decompressed,
|
|
|
|
|
as appropriate for the derived class).
|
2017-05-18 02:09:00 +02:00
|
|
|
|
|
2019-12-25 00:47:04 +01:00
|
|
|
|
### `zlib.close([callback])`
|
2017-10-29 18:35:52 +01:00
|
|
|
|
<!-- YAML
|
|
|
|
|
added: v0.9.4
|
|
|
|
|
-->
|
|
|
|
|
|
2018-07-12 19:48:11 +02:00
|
|
|
|
* `callback` {Function}
|
|
|
|
|
|
2017-10-29 18:35:52 +01:00
|
|
|
|
Close the underlying handle.
|
|
|
|
|
|
2019-12-25 00:47:04 +01:00
|
|
|
|
### `zlib.flush([kind, ]callback)`
|
2016-05-18 16:30:23 +02:00
|
|
|
|
<!-- YAML
|
|
|
|
|
added: v0.5.8
|
|
|
|
|
-->
|
2015-11-05 16:40:47 +01:00
|
|
|
|
|
2018-12-10 00:06:50 +01:00
|
|
|
|
* `kind` **Default:** `zlib.constants.Z_FULL_FLUSH` for zlib-based streams,
|
|
|
|
|
`zlib.constants.BROTLI_OPERATION_FLUSH` for Brotli-based streams.
|
2018-07-12 19:48:11 +02:00
|
|
|
|
* `callback` {Function}
|
2015-11-05 16:40:47 +01:00
|
|
|
|
|
|
|
|
|
Flush pending data. Don't call this frivolously, premature flushes negatively
|
|
|
|
|
impact the effectiveness of the compression algorithm.
|
|
|
|
|
|
2016-05-13 22:56:30 +02:00
|
|
|
|
Calling this only flushes data from the internal `zlib` state, and does not
|
2016-04-12 21:50:05 +02:00
|
|
|
|
perform flushing of any kind on the streams level. Rather, it behaves like a
|
|
|
|
|
normal call to `.write()`, i.e. it will be queued up behind other pending
|
|
|
|
|
writes and will only produce output when data is being read from the stream.
|
|
|
|
|
|
2019-12-25 00:47:04 +01:00
|
|
|
|
### `zlib.params(level, strategy, callback)`
|
2016-05-18 16:30:23 +02:00
|
|
|
|
<!-- YAML
|
|
|
|
|
added: v0.11.4
|
|
|
|
|
-->
|
2015-11-05 16:40:47 +01:00
|
|
|
|
|
2018-07-12 19:48:11 +02:00
|
|
|
|
* `level` {integer}
|
|
|
|
|
* `strategy` {integer}
|
|
|
|
|
* `callback` {Function}
|
|
|
|
|
|
2018-12-10 00:06:50 +01:00
|
|
|
|
This function is only available for zlib-based streams, i.e. not Brotli.
|
|
|
|
|
|
2015-11-05 16:40:47 +01:00
|
|
|
|
Dynamically update the compression level and compression strategy.
|
|
|
|
|
Only applicable to deflate algorithm.
|
|
|
|
|
|
2019-12-25 00:47:04 +01:00
|
|
|
|
### `zlib.reset()`
|
2016-05-18 16:30:23 +02:00
|
|
|
|
<!-- YAML
|
|
|
|
|
added: v0.7.0
|
|
|
|
|
-->
|
2015-11-05 16:40:47 +01:00
|
|
|
|
|
2016-10-30 05:02:38 +01:00
|
|
|
|
Reset the compressor/decompressor to factory defaults. Only applicable to
|
|
|
|
|
the inflate and deflate algorithms.
|
|
|
|
|
|
2019-12-25 00:47:04 +01:00
|
|
|
|
## `zlib.constants`
|
2017-01-13 04:02:17 +01:00
|
|
|
|
<!-- YAML
|
|
|
|
|
added: v7.0.0
|
|
|
|
|
-->
|
2016-06-07 23:38:00 +02:00
|
|
|
|
|
2016-07-09 07:13:09 +02:00
|
|
|
|
Provides an object enumerating Zlib-related constants.
|
2016-06-07 23:38:00 +02:00
|
|
|
|
|
2019-12-25 00:47:04 +01:00
|
|
|
|
## `zlib.createBrotliCompress([options])`
|
2018-12-10 00:06:50 +01:00
|
|
|
|
<!-- YAML
|
2019-01-16 15:55:55 +01:00
|
|
|
|
added: v11.7.0
|
2018-12-10 00:06:50 +01:00
|
|
|
|
-->
|
|
|
|
|
|
|
|
|
|
* `options` {brotli options}
|
|
|
|
|
|
|
|
|
|
Creates and returns a new [`BrotliCompress`][] object.
|
|
|
|
|
|
2019-12-25 00:47:04 +01:00
|
|
|
|
## `zlib.createBrotliDecompress([options])`
|
2018-12-10 00:06:50 +01:00
|
|
|
|
<!-- YAML
|
2019-01-16 15:55:55 +01:00
|
|
|
|
added: v11.7.0
|
2018-12-10 00:06:50 +01:00
|
|
|
|
-->
|
|
|
|
|
|
|
|
|
|
* `options` {brotli options}
|
|
|
|
|
|
|
|
|
|
Creates and returns a new [`BrotliDecompress`][] object.
|
|
|
|
|
|
2019-12-25 00:47:04 +01:00
|
|
|
|
## `zlib.createDeflate([options])`
|
2016-05-18 16:30:23 +02:00
|
|
|
|
<!-- YAML
|
|
|
|
|
added: v0.5.8
|
|
|
|
|
-->
|
2015-11-05 16:40:47 +01:00
|
|
|
|
|
2018-07-21 11:38:10 +02:00
|
|
|
|
* `options` {zlib options}
|
2018-07-12 19:48:11 +02:00
|
|
|
|
|
2018-07-21 11:38:10 +02:00
|
|
|
|
Creates and returns a new [`Deflate`][] object.
|
2015-11-05 16:40:47 +01:00
|
|
|
|
|
2019-12-25 00:47:04 +01:00
|
|
|
|
## `zlib.createDeflateRaw([options])`
|
2016-05-18 16:30:23 +02:00
|
|
|
|
<!-- YAML
|
|
|
|
|
added: v0.5.8
|
|
|
|
|
-->
|
2015-11-05 16:40:47 +01:00
|
|
|
|
|
2018-07-21 11:38:10 +02:00
|
|
|
|
* `options` {zlib options}
|
2018-07-12 19:48:11 +02:00
|
|
|
|
|
2018-07-21 11:38:10 +02:00
|
|
|
|
Creates and returns a new [`DeflateRaw`][] object.
|
2015-11-05 16:40:47 +01:00
|
|
|
|
|
2018-04-29 19:46:41 +02:00
|
|
|
|
An upgrade of zlib from 1.2.8 to 1.2.11 changed behavior when `windowBits`
|
|
|
|
|
is set to 8 for raw deflate streams. zlib would automatically set `windowBits`
|
2017-10-26 12:32:23 +02:00
|
|
|
|
to 9 if was initially set to 8. Newer versions of zlib will throw an exception,
|
|
|
|
|
so Node.js restored the original behavior of upgrading a value of 8 to 9,
|
|
|
|
|
since passing `windowBits = 9` to zlib actually results in a compressed stream
|
|
|
|
|
that effectively uses an 8-bit window only.
|
2017-05-18 11:49:08 +02:00
|
|
|
|
|
2019-12-25 00:47:04 +01:00
|
|
|
|
## `zlib.createGunzip([options])`
|
2016-05-18 16:30:23 +02:00
|
|
|
|
<!-- YAML
|
|
|
|
|
added: v0.5.8
|
|
|
|
|
-->
|
2015-11-05 16:40:47 +01:00
|
|
|
|
|
2018-07-21 11:38:10 +02:00
|
|
|
|
* `options` {zlib options}
|
2018-07-12 19:48:11 +02:00
|
|
|
|
|
2018-07-21 11:38:10 +02:00
|
|
|
|
Creates and returns a new [`Gunzip`][] object.
|
2015-11-05 16:40:47 +01:00
|
|
|
|
|
2019-12-25 00:47:04 +01:00
|
|
|
|
## `zlib.createGzip([options])`
|
2016-05-18 16:30:23 +02:00
|
|
|
|
<!-- YAML
|
|
|
|
|
added: v0.5.8
|
|
|
|
|
-->
|
2015-11-05 16:40:47 +01:00
|
|
|
|
|
2018-07-21 11:38:10 +02:00
|
|
|
|
* `options` {zlib options}
|
2018-07-12 19:48:11 +02:00
|
|
|
|
|
2018-07-21 11:38:10 +02:00
|
|
|
|
Creates and returns a new [`Gzip`][] object.
|
2019-06-08 15:16:21 +02:00
|
|
|
|
See [example][zlib.createGzip example].
|
2015-11-05 16:40:47 +01:00
|
|
|
|
|
2019-12-25 00:47:04 +01:00
|
|
|
|
## `zlib.createInflate([options])`
|
2016-05-18 16:30:23 +02:00
|
|
|
|
<!-- YAML
|
|
|
|
|
added: v0.5.8
|
|
|
|
|
-->
|
2015-11-05 16:40:47 +01:00
|
|
|
|
|
2018-07-21 11:38:10 +02:00
|
|
|
|
* `options` {zlib options}
|
2018-07-12 19:48:11 +02:00
|
|
|
|
|
2018-07-21 11:38:10 +02:00
|
|
|
|
Creates and returns a new [`Inflate`][] object.
|
2015-11-05 16:40:47 +01:00
|
|
|
|
|
2019-12-25 00:47:04 +01:00
|
|
|
|
## `zlib.createInflateRaw([options])`
|
2016-05-18 16:30:23 +02:00
|
|
|
|
<!-- YAML
|
|
|
|
|
added: v0.5.8
|
|
|
|
|
-->
|
2015-11-05 16:40:47 +01:00
|
|
|
|
|
2018-07-21 11:38:10 +02:00
|
|
|
|
* `options` {zlib options}
|
2018-07-12 19:48:11 +02:00
|
|
|
|
|
2018-07-21 11:38:10 +02:00
|
|
|
|
Creates and returns a new [`InflateRaw`][] object.
|
2015-11-05 16:40:47 +01:00
|
|
|
|
|
2019-12-25 00:47:04 +01:00
|
|
|
|
## `zlib.createUnzip([options])`
|
2016-05-18 16:30:23 +02:00
|
|
|
|
<!-- YAML
|
|
|
|
|
added: v0.5.8
|
|
|
|
|
-->
|
2015-11-05 16:40:47 +01:00
|
|
|
|
|
2018-07-21 11:38:10 +02:00
|
|
|
|
* `options` {zlib options}
|
2018-07-12 19:48:11 +02:00
|
|
|
|
|
2018-07-21 11:38:10 +02:00
|
|
|
|
Creates and returns a new [`Unzip`][] object.
|
2015-11-05 16:40:47 +01:00
|
|
|
|
|
|
|
|
|
## Convenience Methods
|
|
|
|
|
|
|
|
|
|
<!--type=misc-->
|
|
|
|
|
|
2017-10-06 21:19:33 +02:00
|
|
|
|
All of these take a [`Buffer`][], [`TypedArray`][], [`DataView`][],
|
|
|
|
|
[`ArrayBuffer`][] or string as the first argument, an optional second argument
|
|
|
|
|
to supply options to the `zlib` classes and will call the supplied callback
|
|
|
|
|
with `callback(error, result)`.
|
2015-11-05 16:40:47 +01:00
|
|
|
|
|
|
|
|
|
Every method has a `*Sync` counterpart, which accept the same arguments, but
|
|
|
|
|
without a callback.
|
|
|
|
|
|
2019-12-25 00:47:04 +01:00
|
|
|
|
### `zlib.brotliCompress(buffer[, options], callback)`
|
2018-12-10 00:06:50 +01:00
|
|
|
|
<!-- YAML
|
2019-01-16 15:55:55 +01:00
|
|
|
|
added: v11.7.0
|
2018-12-10 00:06:50 +01:00
|
|
|
|
-->
|
2019-09-06 07:42:22 +02:00
|
|
|
|
|
2018-12-10 00:06:50 +01:00
|
|
|
|
* `buffer` {Buffer|TypedArray|DataView|ArrayBuffer|string}
|
|
|
|
|
* `options` {brotli options}
|
|
|
|
|
* `callback` {Function}
|
|
|
|
|
|
2019-12-25 00:47:04 +01:00
|
|
|
|
### `zlib.brotliCompressSync(buffer[, options])`
|
2018-12-10 00:06:50 +01:00
|
|
|
|
<!-- YAML
|
2019-01-16 15:55:55 +01:00
|
|
|
|
added: v11.7.0
|
2018-12-10 00:06:50 +01:00
|
|
|
|
-->
|
2019-09-06 07:42:22 +02:00
|
|
|
|
|
2018-12-10 00:06:50 +01:00
|
|
|
|
* `buffer` {Buffer|TypedArray|DataView|ArrayBuffer|string}
|
|
|
|
|
* `options` {brotli options}
|
|
|
|
|
|
|
|
|
|
Compress a chunk of data with [`BrotliCompress`][].
|
|
|
|
|
|
2019-12-25 00:47:04 +01:00
|
|
|
|
### `zlib.brotliDecompress(buffer[, options], callback)`
|
2018-12-10 00:06:50 +01:00
|
|
|
|
<!-- YAML
|
2019-01-16 15:55:55 +01:00
|
|
|
|
added: v11.7.0
|
2018-12-10 00:06:50 +01:00
|
|
|
|
-->
|
2019-09-06 07:42:22 +02:00
|
|
|
|
|
2018-12-10 00:06:50 +01:00
|
|
|
|
* `buffer` {Buffer|TypedArray|DataView|ArrayBuffer|string}
|
|
|
|
|
* `options` {brotli options}
|
|
|
|
|
* `callback` {Function}
|
|
|
|
|
|
2019-12-25 00:47:04 +01:00
|
|
|
|
### `zlib.brotliDecompressSync(buffer[, options])`
|
2018-12-10 00:06:50 +01:00
|
|
|
|
<!-- YAML
|
2019-01-16 15:55:55 +01:00
|
|
|
|
added: v11.7.0
|
2018-12-10 00:06:50 +01:00
|
|
|
|
-->
|
2019-09-06 07:42:22 +02:00
|
|
|
|
|
2018-12-10 00:06:50 +01:00
|
|
|
|
* `buffer` {Buffer|TypedArray|DataView|ArrayBuffer|string}
|
|
|
|
|
* `options` {brotli options}
|
|
|
|
|
|
|
|
|
|
Decompress a chunk of data with [`BrotliDecompress`][].
|
|
|
|
|
|
2019-12-25 00:47:04 +01:00
|
|
|
|
### `zlib.deflate(buffer[, options], callback)`
|
2016-05-18 16:30:23 +02:00
|
|
|
|
<!-- YAML
|
|
|
|
|
added: v0.6.0
|
2017-03-23 03:45:03 +01:00
|
|
|
|
changes:
|
2018-01-10 01:23:55 +01:00
|
|
|
|
- version: v9.4.0
|
2017-10-06 21:19:33 +02:00
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/16042
|
2018-04-29 19:46:41 +02:00
|
|
|
|
description: The `buffer` parameter can be an `ArrayBuffer`.
|
2017-03-16 04:26:14 +01:00
|
|
|
|
- version: v8.0.0
|
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/12223
|
2018-04-29 19:46:41 +02:00
|
|
|
|
description: The `buffer` parameter can be any `TypedArray` or `DataView`.
|
2017-03-16 04:26:14 +01:00
|
|
|
|
- version: v8.0.0
|
2017-03-23 03:45:03 +01:00
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/12001
|
2018-04-29 19:46:41 +02:00
|
|
|
|
description: The `buffer` parameter can be an `Uint8Array` now.
|
2016-05-18 16:30:23 +02:00
|
|
|
|
-->
|
2019-09-06 07:42:22 +02:00
|
|
|
|
|
2018-07-12 19:48:11 +02:00
|
|
|
|
* `buffer` {Buffer|TypedArray|DataView|ArrayBuffer|string}
|
2018-07-21 11:38:10 +02:00
|
|
|
|
* `options` {zlib options}
|
2018-07-12 19:48:11 +02:00
|
|
|
|
* `callback` {Function}
|
|
|
|
|
|
2019-12-25 00:47:04 +01:00
|
|
|
|
### `zlib.deflateSync(buffer[, options])`
|
2016-05-18 16:30:23 +02:00
|
|
|
|
<!-- YAML
|
|
|
|
|
added: v0.11.12
|
2017-03-23 03:45:03 +01:00
|
|
|
|
changes:
|
2018-01-10 01:23:55 +01:00
|
|
|
|
- version: v9.4.0
|
2017-10-06 21:19:33 +02:00
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/16042
|
2018-04-29 19:46:41 +02:00
|
|
|
|
description: The `buffer` parameter can be an `ArrayBuffer`.
|
2017-03-16 04:26:14 +01:00
|
|
|
|
- version: v8.0.0
|
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/12223
|
2018-04-29 19:46:41 +02:00
|
|
|
|
description: The `buffer` parameter can be any `TypedArray` or `DataView`.
|
2017-03-16 04:26:14 +01:00
|
|
|
|
- version: v8.0.0
|
2017-03-23 03:45:03 +01:00
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/12001
|
2018-04-29 19:46:41 +02:00
|
|
|
|
description: The `buffer` parameter can be an `Uint8Array` now.
|
2016-05-18 16:30:23 +02:00
|
|
|
|
-->
|
2015-11-05 16:40:47 +01:00
|
|
|
|
|
2018-07-12 19:48:11 +02:00
|
|
|
|
* `buffer` {Buffer|TypedArray|DataView|ArrayBuffer|string}
|
2018-07-21 11:38:10 +02:00
|
|
|
|
* `options` {zlib options}
|
2017-03-23 03:45:03 +01:00
|
|
|
|
|
2018-04-29 19:46:41 +02:00
|
|
|
|
Compress a chunk of data with [`Deflate`][].
|
2015-11-05 16:40:47 +01:00
|
|
|
|
|
2019-12-25 00:47:04 +01:00
|
|
|
|
### `zlib.deflateRaw(buffer[, options], callback)`
|
2016-05-18 16:30:23 +02:00
|
|
|
|
<!-- YAML
|
|
|
|
|
added: v0.6.0
|
2017-03-23 03:45:03 +01:00
|
|
|
|
changes:
|
2017-03-16 04:26:14 +01:00
|
|
|
|
- version: v8.0.0
|
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/12223
|
2018-04-29 19:46:41 +02:00
|
|
|
|
description: The `buffer` parameter can be any `TypedArray` or `DataView`.
|
2017-03-16 04:26:14 +01:00
|
|
|
|
- version: v8.0.0
|
2017-03-23 03:45:03 +01:00
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/12001
|
2018-04-29 19:46:41 +02:00
|
|
|
|
description: The `buffer` parameter can be an `Uint8Array` now.
|
2016-05-18 16:30:23 +02:00
|
|
|
|
-->
|
2018-07-12 19:48:11 +02:00
|
|
|
|
|
|
|
|
|
* `buffer` {Buffer|TypedArray|DataView|ArrayBuffer|string}
|
2018-07-21 11:38:10 +02:00
|
|
|
|
* `options` {zlib options}
|
2018-07-12 19:48:11 +02:00
|
|
|
|
* `callback` {Function}
|
|
|
|
|
|
2019-12-25 00:47:04 +01:00
|
|
|
|
### `zlib.deflateRawSync(buffer[, options])`
|
2016-05-18 16:30:23 +02:00
|
|
|
|
<!-- YAML
|
|
|
|
|
added: v0.11.12
|
2017-03-23 03:45:03 +01:00
|
|
|
|
changes:
|
2018-01-10 01:23:55 +01:00
|
|
|
|
- version: v9.4.0
|
2017-10-06 21:19:33 +02:00
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/16042
|
2018-04-29 19:46:41 +02:00
|
|
|
|
description: The `buffer` parameter can be an `ArrayBuffer`.
|
2017-03-16 04:26:14 +01:00
|
|
|
|
- version: v8.0.0
|
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/12223
|
2018-04-29 19:46:41 +02:00
|
|
|
|
description: The `buffer` parameter can be any `TypedArray` or `DataView`.
|
2017-03-16 04:26:14 +01:00
|
|
|
|
- version: v8.0.0
|
2017-03-23 03:45:03 +01:00
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/12001
|
2018-04-29 19:46:41 +02:00
|
|
|
|
description: The `buffer` parameter can be an `Uint8Array` now.
|
2016-05-18 16:30:23 +02:00
|
|
|
|
-->
|
2015-11-05 16:40:47 +01:00
|
|
|
|
|
2018-07-12 19:48:11 +02:00
|
|
|
|
* `buffer` {Buffer|TypedArray|DataView|ArrayBuffer|string}
|
2018-07-21 11:38:10 +02:00
|
|
|
|
* `options` {zlib options}
|
2017-03-23 03:45:03 +01:00
|
|
|
|
|
2018-04-29 19:46:41 +02:00
|
|
|
|
Compress a chunk of data with [`DeflateRaw`][].
|
2015-11-05 16:40:47 +01:00
|
|
|
|
|
2019-12-25 00:47:04 +01:00
|
|
|
|
### `zlib.gunzip(buffer[, options], callback)`
|
2016-05-18 16:30:23 +02:00
|
|
|
|
<!-- YAML
|
|
|
|
|
added: v0.6.0
|
2017-03-23 03:45:03 +01:00
|
|
|
|
changes:
|
2018-01-10 01:23:55 +01:00
|
|
|
|
- version: v9.4.0
|
2017-10-06 21:19:33 +02:00
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/16042
|
2018-04-29 19:46:41 +02:00
|
|
|
|
description: The `buffer` parameter can be an `ArrayBuffer`.
|
2017-03-16 04:26:14 +01:00
|
|
|
|
- version: v8.0.0
|
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/12223
|
2018-04-29 19:46:41 +02:00
|
|
|
|
description: The `buffer` parameter can be any `TypedArray` or `DataView`.
|
2017-03-16 04:26:14 +01:00
|
|
|
|
- version: v8.0.0
|
2017-03-23 03:45:03 +01:00
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/12001
|
2018-04-29 19:46:41 +02:00
|
|
|
|
description: The `buffer` parameter can be an `Uint8Array` now.
|
2016-05-18 16:30:23 +02:00
|
|
|
|
-->
|
2018-07-12 19:48:11 +02:00
|
|
|
|
|
|
|
|
|
* `buffer` {Buffer|TypedArray|DataView|ArrayBuffer|string}
|
2018-07-21 11:38:10 +02:00
|
|
|
|
* `options` {zlib options}
|
2018-07-12 19:48:11 +02:00
|
|
|
|
* `callback` {Function}
|
|
|
|
|
|
2019-12-25 00:47:04 +01:00
|
|
|
|
### `zlib.gunzipSync(buffer[, options])`
|
2016-05-18 16:30:23 +02:00
|
|
|
|
<!-- YAML
|
|
|
|
|
added: v0.11.12
|
2017-03-23 03:45:03 +01:00
|
|
|
|
changes:
|
2018-01-10 01:23:55 +01:00
|
|
|
|
- version: v9.4.0
|
2017-10-06 21:19:33 +02:00
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/16042
|
2018-04-29 19:46:41 +02:00
|
|
|
|
description: The `buffer` parameter can be an `ArrayBuffer`.
|
2017-03-16 04:26:14 +01:00
|
|
|
|
- version: v8.0.0
|
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/12223
|
2018-04-29 19:46:41 +02:00
|
|
|
|
description: The `buffer` parameter can be any `TypedArray` or `DataView`.
|
2017-03-16 04:26:14 +01:00
|
|
|
|
- version: v8.0.0
|
2017-03-23 03:45:03 +01:00
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/12001
|
2018-04-29 19:46:41 +02:00
|
|
|
|
description: The `buffer` parameter can be an `Uint8Array` now.
|
2016-05-18 16:30:23 +02:00
|
|
|
|
-->
|
2015-11-05 16:40:47 +01:00
|
|
|
|
|
2018-07-12 19:48:11 +02:00
|
|
|
|
* `buffer` {Buffer|TypedArray|DataView|ArrayBuffer|string}
|
2018-07-21 11:38:10 +02:00
|
|
|
|
* `options` {zlib options}
|
2017-03-23 03:45:03 +01:00
|
|
|
|
|
2018-04-29 19:46:41 +02:00
|
|
|
|
Decompress a chunk of data with [`Gunzip`][].
|
2015-11-05 16:40:47 +01:00
|
|
|
|
|
2019-12-25 00:47:04 +01:00
|
|
|
|
### `zlib.gzip(buffer[, options], callback)`
|
2016-05-18 16:30:23 +02:00
|
|
|
|
<!-- YAML
|
|
|
|
|
added: v0.6.0
|
2017-03-23 03:45:03 +01:00
|
|
|
|
changes:
|
2018-01-10 01:23:55 +01:00
|
|
|
|
- version: v9.4.0
|
2017-10-06 21:19:33 +02:00
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/16042
|
2018-04-29 19:46:41 +02:00
|
|
|
|
description: The `buffer` parameter can be an `ArrayBuffer`.
|
2017-03-16 04:26:14 +01:00
|
|
|
|
- version: v8.0.0
|
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/12223
|
2018-04-29 19:46:41 +02:00
|
|
|
|
description: The `buffer` parameter can be any `TypedArray` or `DataView`.
|
2017-03-16 04:26:14 +01:00
|
|
|
|
- version: v8.0.0
|
2017-03-23 03:45:03 +01:00
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/12001
|
2018-04-29 19:46:41 +02:00
|
|
|
|
description: The `buffer` parameter can be an `Uint8Array` now.
|
2016-05-18 16:30:23 +02:00
|
|
|
|
-->
|
2018-07-12 19:48:11 +02:00
|
|
|
|
|
|
|
|
|
* `buffer` {Buffer|TypedArray|DataView|ArrayBuffer|string}
|
2018-07-21 11:38:10 +02:00
|
|
|
|
* `options` {zlib options}
|
2018-07-12 19:48:11 +02:00
|
|
|
|
* `callback` {Function}
|
|
|
|
|
|
2019-12-25 00:47:04 +01:00
|
|
|
|
### `zlib.gzipSync(buffer[, options])`
|
2016-05-18 16:30:23 +02:00
|
|
|
|
<!-- YAML
|
|
|
|
|
added: v0.11.12
|
2017-03-23 03:45:03 +01:00
|
|
|
|
changes:
|
2018-01-10 01:23:55 +01:00
|
|
|
|
- version: v9.4.0
|
2017-10-06 21:19:33 +02:00
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/16042
|
2018-04-29 19:46:41 +02:00
|
|
|
|
description: The `buffer` parameter can be an `ArrayBuffer`.
|
2017-03-16 04:26:14 +01:00
|
|
|
|
- version: v8.0.0
|
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/12223
|
2018-04-29 19:46:41 +02:00
|
|
|
|
description: The `buffer` parameter can be any `TypedArray` or `DataView`.
|
2017-03-16 04:26:14 +01:00
|
|
|
|
- version: v8.0.0
|
2017-03-23 03:45:03 +01:00
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/12001
|
2018-04-29 19:46:41 +02:00
|
|
|
|
description: The `buffer` parameter can be an `Uint8Array` now.
|
2016-05-18 16:30:23 +02:00
|
|
|
|
-->
|
2015-11-05 16:40:47 +01:00
|
|
|
|
|
2018-07-12 19:48:11 +02:00
|
|
|
|
* `buffer` {Buffer|TypedArray|DataView|ArrayBuffer|string}
|
2018-07-21 11:38:10 +02:00
|
|
|
|
* `options` {zlib options}
|
2015-11-05 16:40:47 +01:00
|
|
|
|
|
2018-04-29 19:46:41 +02:00
|
|
|
|
Compress a chunk of data with [`Gzip`][].
|
2017-03-23 03:45:03 +01:00
|
|
|
|
|
2019-12-25 00:47:04 +01:00
|
|
|
|
### `zlib.inflate(buffer[, options], callback)`
|
2016-05-18 16:30:23 +02:00
|
|
|
|
<!-- YAML
|
|
|
|
|
added: v0.6.0
|
2017-03-23 03:45:03 +01:00
|
|
|
|
changes:
|
2018-01-10 01:23:55 +01:00
|
|
|
|
- version: v9.4.0
|
2017-10-06 21:19:33 +02:00
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/16042
|
2018-04-29 19:46:41 +02:00
|
|
|
|
description: The `buffer` parameter can be an `ArrayBuffer`.
|
2017-03-16 04:26:14 +01:00
|
|
|
|
- version: v8.0.0
|
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/12223
|
2018-04-29 19:46:41 +02:00
|
|
|
|
description: The `buffer` parameter can be any `TypedArray` or `DataView`.
|
2017-03-16 04:26:14 +01:00
|
|
|
|
- version: v8.0.0
|
2017-03-23 03:45:03 +01:00
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/12001
|
2018-04-29 19:46:41 +02:00
|
|
|
|
description: The `buffer` parameter can be an `Uint8Array` now.
|
2016-05-18 16:30:23 +02:00
|
|
|
|
-->
|
2018-07-12 19:48:11 +02:00
|
|
|
|
|
|
|
|
|
* `buffer` {Buffer|TypedArray|DataView|ArrayBuffer|string}
|
2018-07-21 11:38:10 +02:00
|
|
|
|
* `options` {zlib options}
|
2018-07-12 19:48:11 +02:00
|
|
|
|
* `callback` {Function}
|
|
|
|
|
|
2019-12-25 00:47:04 +01:00
|
|
|
|
### `zlib.inflateSync(buffer[, options])`
|
2016-05-18 16:30:23 +02:00
|
|
|
|
<!-- YAML
|
|
|
|
|
added: v0.11.12
|
2017-03-23 03:45:03 +01:00
|
|
|
|
changes:
|
2018-01-10 01:23:55 +01:00
|
|
|
|
- version: v9.4.0
|
2017-10-06 21:19:33 +02:00
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/16042
|
2018-04-29 19:46:41 +02:00
|
|
|
|
description: The `buffer` parameter can be an `ArrayBuffer`.
|
2017-03-16 04:26:14 +01:00
|
|
|
|
- version: v8.0.0
|
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/12223
|
2018-04-29 19:46:41 +02:00
|
|
|
|
description: The `buffer` parameter can be any `TypedArray` or `DataView`.
|
2017-03-16 04:26:14 +01:00
|
|
|
|
- version: v8.0.0
|
2017-03-23 03:45:03 +01:00
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/12001
|
2018-04-29 19:46:41 +02:00
|
|
|
|
description: The `buffer` parameter can be an `Uint8Array` now.
|
2016-05-18 16:30:23 +02:00
|
|
|
|
-->
|
2015-11-05 16:40:47 +01:00
|
|
|
|
|
2018-07-12 19:48:11 +02:00
|
|
|
|
* `buffer` {Buffer|TypedArray|DataView|ArrayBuffer|string}
|
2018-07-21 11:38:10 +02:00
|
|
|
|
* `options` {zlib options}
|
2015-11-05 16:40:47 +01:00
|
|
|
|
|
2018-04-29 19:46:41 +02:00
|
|
|
|
Decompress a chunk of data with [`Inflate`][].
|
2017-03-23 03:45:03 +01:00
|
|
|
|
|
2019-12-25 00:47:04 +01:00
|
|
|
|
### `zlib.inflateRaw(buffer[, options], callback)`
|
2016-05-18 16:30:23 +02:00
|
|
|
|
<!-- YAML
|
|
|
|
|
added: v0.6.0
|
2017-03-23 03:45:03 +01:00
|
|
|
|
changes:
|
2018-01-10 01:23:55 +01:00
|
|
|
|
- version: v9.4.0
|
2017-10-06 21:19:33 +02:00
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/16042
|
2018-04-29 19:46:41 +02:00
|
|
|
|
description: The `buffer` parameter can be an `ArrayBuffer`.
|
2017-03-16 04:26:14 +01:00
|
|
|
|
- version: v8.0.0
|
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/12223
|
2018-04-29 19:46:41 +02:00
|
|
|
|
description: The `buffer` parameter can be any `TypedArray` or `DataView`.
|
2017-03-16 04:26:14 +01:00
|
|
|
|
- version: v8.0.0
|
2017-03-23 03:45:03 +01:00
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/12001
|
2018-04-29 19:46:41 +02:00
|
|
|
|
description: The `buffer` parameter can be an `Uint8Array` now.
|
2016-05-18 16:30:23 +02:00
|
|
|
|
-->
|
2018-07-12 19:48:11 +02:00
|
|
|
|
|
|
|
|
|
* `buffer` {Buffer|TypedArray|DataView|ArrayBuffer|string}
|
2018-07-21 11:38:10 +02:00
|
|
|
|
* `options` {zlib options}
|
2018-07-12 19:48:11 +02:00
|
|
|
|
* `callback` {Function}
|
|
|
|
|
|
2019-12-25 00:47:04 +01:00
|
|
|
|
### `zlib.inflateRawSync(buffer[, options])`
|
2016-05-18 16:30:23 +02:00
|
|
|
|
<!-- YAML
|
|
|
|
|
added: v0.11.12
|
2017-03-23 03:45:03 +01:00
|
|
|
|
changes:
|
2018-01-10 01:23:55 +01:00
|
|
|
|
- version: v9.4.0
|
2017-10-06 21:19:33 +02:00
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/16042
|
2018-04-29 19:46:41 +02:00
|
|
|
|
description: The `buffer` parameter can be an `ArrayBuffer`.
|
2017-03-16 04:26:14 +01:00
|
|
|
|
- version: v8.0.0
|
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/12223
|
2018-04-29 19:46:41 +02:00
|
|
|
|
description: The `buffer` parameter can be any `TypedArray` or `DataView`.
|
2017-03-16 04:26:14 +01:00
|
|
|
|
- version: v8.0.0
|
2017-03-23 03:45:03 +01:00
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/12001
|
2018-04-29 19:46:41 +02:00
|
|
|
|
description: The `buffer` parameter can be an `Uint8Array` now.
|
2016-05-18 16:30:23 +02:00
|
|
|
|
-->
|
2015-11-05 16:40:47 +01:00
|
|
|
|
|
2018-07-12 19:48:11 +02:00
|
|
|
|
* `buffer` {Buffer|TypedArray|DataView|ArrayBuffer|string}
|
2018-07-21 11:38:10 +02:00
|
|
|
|
* `options` {zlib options}
|
2017-03-23 03:45:03 +01:00
|
|
|
|
|
2018-04-29 19:46:41 +02:00
|
|
|
|
Decompress a chunk of data with [`InflateRaw`][].
|
2015-11-05 16:40:47 +01:00
|
|
|
|
|
2019-12-25 00:47:04 +01:00
|
|
|
|
### `zlib.unzip(buffer[, options], callback)`
|
2016-05-18 16:30:23 +02:00
|
|
|
|
<!-- YAML
|
|
|
|
|
added: v0.6.0
|
2017-03-23 03:45:03 +01:00
|
|
|
|
changes:
|
2018-01-10 01:23:55 +01:00
|
|
|
|
- version: v9.4.0
|
2017-10-06 21:19:33 +02:00
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/16042
|
2018-04-29 19:46:41 +02:00
|
|
|
|
description: The `buffer` parameter can be an `ArrayBuffer`.
|
2017-03-16 04:26:14 +01:00
|
|
|
|
- version: v8.0.0
|
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/12223
|
2018-04-29 19:46:41 +02:00
|
|
|
|
description: The `buffer` parameter can be any `TypedArray` or `DataView`.
|
2017-03-16 04:26:14 +01:00
|
|
|
|
- version: v8.0.0
|
2017-03-23 03:45:03 +01:00
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/12001
|
2018-04-29 19:46:41 +02:00
|
|
|
|
description: The `buffer` parameter can be an `Uint8Array` now.
|
2016-05-18 16:30:23 +02:00
|
|
|
|
-->
|
2018-07-12 19:48:11 +02:00
|
|
|
|
|
|
|
|
|
* `buffer` {Buffer|TypedArray|DataView|ArrayBuffer|string}
|
2018-07-21 11:38:10 +02:00
|
|
|
|
* `options` {zlib options}
|
2018-07-12 19:48:11 +02:00
|
|
|
|
* `callback` {Function}
|
|
|
|
|
|
2019-12-25 00:47:04 +01:00
|
|
|
|
### `zlib.unzipSync(buffer[, options])`
|
2016-05-18 16:30:23 +02:00
|
|
|
|
<!-- YAML
|
|
|
|
|
added: v0.11.12
|
2017-03-23 03:45:03 +01:00
|
|
|
|
changes:
|
2018-01-10 01:23:55 +01:00
|
|
|
|
- version: v9.4.0
|
2017-10-06 21:19:33 +02:00
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/16042
|
2018-04-29 19:46:41 +02:00
|
|
|
|
description: The `buffer` parameter can be an `ArrayBuffer`.
|
2017-03-16 04:26:14 +01:00
|
|
|
|
- version: v8.0.0
|
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/12223
|
2018-04-29 19:46:41 +02:00
|
|
|
|
description: The `buffer` parameter can be any `TypedArray` or `DataView`.
|
2017-03-16 04:26:14 +01:00
|
|
|
|
- version: v8.0.0
|
2017-03-23 03:45:03 +01:00
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/12001
|
2018-04-29 19:46:41 +02:00
|
|
|
|
description: The `buffer` parameter can be an `Uint8Array` now.
|
2016-05-18 16:30:23 +02:00
|
|
|
|
-->
|
2015-11-05 16:40:47 +01:00
|
|
|
|
|
2018-07-12 19:48:11 +02:00
|
|
|
|
* `buffer` {Buffer|TypedArray|DataView|ArrayBuffer|string}
|
2018-07-21 11:38:10 +02:00
|
|
|
|
* `options` {zlib options}
|
2017-03-23 03:45:03 +01:00
|
|
|
|
|
2018-04-29 19:46:41 +02:00
|
|
|
|
Decompress a chunk of data with [`Unzip`][].
|
2015-11-14 04:21:49 +01:00
|
|
|
|
|
2017-05-08 18:30:13 +02:00
|
|
|
|
[`.flush()`]: #zlib_zlib_flush_kind_callback
|
2016-05-13 22:56:30 +02:00
|
|
|
|
[`Accept-Encoding`]: https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.3
|
2017-10-06 21:19:33 +02:00
|
|
|
|
[`ArrayBuffer`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer
|
2018-12-10 00:06:50 +01:00
|
|
|
|
[`BrotliCompress`]: #zlib_class_zlib_brotlicompress
|
|
|
|
|
[`BrotliDecompress`]: #zlib_class_zlib_brotlidecompress
|
2017-05-08 18:30:13 +02:00
|
|
|
|
[`Buffer`]: buffer.html#buffer_class_buffer
|
2016-05-13 22:56:30 +02:00
|
|
|
|
[`Content-Encoding`]: https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.11
|
2017-05-08 18:30:13 +02:00
|
|
|
|
[`DataView`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView
|
2018-04-29 19:46:41 +02:00
|
|
|
|
[`DeflateRaw`]: #zlib_class_zlib_deflateraw
|
2018-11-27 20:49:21 +01:00
|
|
|
|
[`Deflate`]: #zlib_class_zlib_deflate
|
2018-04-29 19:46:41 +02:00
|
|
|
|
[`Gunzip`]: #zlib_class_zlib_gunzip
|
|
|
|
|
[`Gzip`]: #zlib_class_zlib_gzip
|
|
|
|
|
[`InflateRaw`]: #zlib_class_zlib_inflateraw
|
2018-11-27 20:49:21 +01:00
|
|
|
|
[`Inflate`]: #zlib_class_zlib_inflate
|
2017-05-08 18:30:13 +02:00
|
|
|
|
[`TypedArray`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
|
2018-04-29 19:46:41 +02:00
|
|
|
|
[`Unzip`]: #zlib_class_zlib_unzip
|
2019-07-06 16:53:01 +02:00
|
|
|
|
[`deflateInit2` and `inflateInit2`]: https://zlib.net/manual.html#Advanced
|
2018-08-16 08:03:15 +02:00
|
|
|
|
[`stream.Transform`]: stream.html#stream_class_stream_transform
|
2018-03-17 16:59:54 +01:00
|
|
|
|
[`zlib.bytesWritten`]: #zlib_zlib_byteswritten
|
2018-12-10 00:06:50 +01:00
|
|
|
|
[Brotli parameters]: #zlib_brotli_constants
|
2018-04-29 19:46:41 +02:00
|
|
|
|
[Memory Usage Tuning]: #zlib_memory_usage_tuning
|
2018-12-10 00:06:50 +01:00
|
|
|
|
[RFC 7932]: https://www.rfc-editor.org/rfc/rfc7932.txt
|
2018-04-28 13:00:04 +02:00
|
|
|
|
[pool size]: cli.html#cli_uv_threadpool_size_size
|
2017-11-23 00:04:16 +01:00
|
|
|
|
[zlib documentation]: https://zlib.net/manual.html#Constants
|
2019-06-08 15:16:21 +02:00
|
|
|
|
[zlib.createGzip example]: #zlib_zlib
|