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
|
|
|
|
Deflate/Inflate. 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
|
|
|
|
2016-01-17 18:39:07 +01:00
|
|
|
inp.pipe(gzip).pipe(out);
|
|
|
|
```
|
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
|
|
|
|
|
|
|
|
Note that all zlib APIs except those that are explicitly synchronous use libuv's
|
|
|
|
threadpool, which can have surprising and negative performance implications for
|
|
|
|
some applications, see the [`UV_THREADPOOL_SIZE`][] documentation for more
|
|
|
|
information.
|
|
|
|
|
2016-05-13 22:56:30 +02:00
|
|
|
## Compressing HTTP requests and responses
|
|
|
|
|
|
|
|
The `zlib` module can be used to implement support for the `gzip` and `deflate`
|
2016-11-15 18:56:15 +01:00
|
|
|
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
|
|
|
|
// client request example
|
|
|
|
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,
|
|
|
|
headers: { 'Accept-Encoding': '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']) {
|
|
|
|
// or, just use zlib.createUnzip() to handle both cases
|
|
|
|
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');
|
|
|
|
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);
|
|
|
|
} 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,
|
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-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-02 07:38:48 +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-02 07:38:48 +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
|
|
|
|
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:
|
|
|
|
```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-->
|
|
|
|
|
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
|
2018-04-02 07:38:48 +02:00
|
|
|
[zlib documentation][]. See <https://zlib.net/manual.html#Constants> for more
|
2016-06-07 23:38:00 +02:00
|
|
|
details.
|
|
|
|
|
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-04-10 12:09:47 +02: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
|
|
|
|
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
|
|
|
|
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-04-02 07:38:48 +02:00
|
|
|
Each class takes an `options` object. All options are optional.
|
2015-11-05 16:40:47 +01:00
|
|
|
|
|
|
|
Note that some options are only relevant when compressing, and are
|
|
|
|
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
|
|
|
|
|
|
|
See the description of `deflateInit2` and `inflateInit2` at
|
2017-11-23 00:04:16 +01:00
|
|
|
<https://zlib.net/manual.html#Advanced> for more information on these.
|
2015-11-05 16:40:47 +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.
|
|
|
|
|
|
|
|
## 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
|
|
|
|
|
|
|
## 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.
|
|
|
|
|
|
|
|
## 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.
|
|
|
|
|
|
|
|
## 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.
|
|
|
|
|
|
|
|
## 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.
|
|
|
|
|
|
|
|
## 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.
|
|
|
|
|
|
|
|
## Class: zlib.Zlib
|
2016-05-18 16:30:23 +02:00
|
|
|
<!-- YAML
|
|
|
|
added: v0.5.8
|
|
|
|
-->
|
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.
|
|
|
|
|
2017-05-18 02:09:00 +02:00
|
|
|
### zlib.bytesRead
|
|
|
|
<!-- 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.
|
|
|
|
|
|
|
|
### zlib.bytesWritten
|
|
|
|
<!-- 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
|
|
|
|
2017-10-29 18:35:52 +01:00
|
|
|
### zlib.close([callback])
|
|
|
|
<!-- YAML
|
|
|
|
added: v0.9.4
|
|
|
|
-->
|
|
|
|
|
|
|
|
Close the underlying handle.
|
|
|
|
|
2015-11-05 16:40:47 +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-04-02 03:44:32 +02:00
|
|
|
* `kind` **Default:** `zlib.constants.Z_FULL_FLUSH`
|
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.
|
|
|
|
|
2015-11-05 16:40:47 +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
|
|
|
|
|
|
|
Dynamically update the compression level and compression strategy.
|
|
|
|
Only applicable to deflate algorithm.
|
|
|
|
|
|
|
|
### 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.
|
|
|
|
|
2016-06-07 23:38:00 +02: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
|
|
|
|
2015-11-05 16:40:47 +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-04-10 12:09:47 +02:00
|
|
|
Creates and returns a new [Deflate][] object with the given [`options`][].
|
2015-11-05 16:40:47 +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-04-10 12:09:47 +02:00
|
|
|
Creates and returns a new [DeflateRaw][] object with the given [`options`][].
|
2015-11-05 16:40:47 +01:00
|
|
|
|
2018-02-06 06:55:16 +01:00
|
|
|
An upgrade of zlib from 1.2.8 to 1.2.11 changed behavior when windowBits
|
2017-10-26 12:32:23 +02:00
|
|
|
is set to 8 for raw deflate streams. zlib would automatically set windowBits
|
|
|
|
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
|
|
|
|
2015-11-05 16:40:47 +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-04-10 12:09:47 +02:00
|
|
|
Creates and returns a new [Gunzip][] object with the given [`options`][].
|
2015-11-05 16:40:47 +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-04-10 12:09:47 +02:00
|
|
|
Creates and returns a new [Gzip][] object with the given [`options`][].
|
2015-11-05 16:40:47 +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-04-10 12:09:47 +02:00
|
|
|
Creates and returns a new [Inflate][] object with the given [`options`][].
|
2015-11-05 16:40:47 +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-04-10 12:09:47 +02:00
|
|
|
Creates and returns a new [InflateRaw][] object with the given [`options`][].
|
2015-11-05 16:40:47 +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-04-10 12:09:47 +02:00
|
|
|
Creates and returns a new [Unzip][] object with the given [`options`][].
|
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.
|
|
|
|
|
2017-03-23 03:45:03 +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
|
|
|
|
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
|
2017-04-04 03:15:13 +02:00
|
|
|
description: The `buffer` parameter can be any TypedArray or DataView now.
|
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
|
|
|
|
description: The `buffer` parameter can be an Uint8Array now.
|
2016-05-18 16:30:23 +02:00
|
|
|
-->
|
2017-03-23 03:45:03 +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
|
|
|
|
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
|
2017-04-04 03:15:13 +02:00
|
|
|
description: The `buffer` parameter can be any TypedArray or DataView now.
|
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
|
|
|
|
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
|
|
|
|
2017-10-06 21:19:33 +02:00
|
|
|
- `buffer` {Buffer|TypedArray|DataView|ArrayBuffer|string}
|
2017-03-23 03:45:03 +01:00
|
|
|
|
|
|
|
Compress a chunk of data with [Deflate][].
|
2015-11-05 16:40:47 +01:00
|
|
|
|
2017-03-23 03:45:03 +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
|
2017-04-04 03:15:13 +02:00
|
|
|
description: The `buffer` parameter can be any TypedArray or DataView now.
|
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
|
|
|
|
description: The `buffer` parameter can be an Uint8Array now.
|
2016-05-18 16:30:23 +02:00
|
|
|
-->
|
2017-03-23 03:45:03 +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
|
|
|
|
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
|
2017-04-04 03:15:13 +02:00
|
|
|
description: The `buffer` parameter can be any TypedArray or DataView now.
|
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
|
|
|
|
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
|
|
|
|
2017-10-06 21:19:33 +02:00
|
|
|
- `buffer` {Buffer|TypedArray|DataView|ArrayBuffer|string}
|
2017-03-23 03:45:03 +01:00
|
|
|
|
|
|
|
Compress a chunk of data with [DeflateRaw][].
|
2015-11-05 16:40:47 +01:00
|
|
|
|
2017-03-23 03:45:03 +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
|
|
|
|
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
|
2017-04-04 03:15:13 +02:00
|
|
|
description: The `buffer` parameter can be any TypedArray or DataView now.
|
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
|
|
|
|
description: The `buffer` parameter can be an Uint8Array now.
|
2016-05-18 16:30:23 +02:00
|
|
|
-->
|
2017-03-23 03:45:03 +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
|
|
|
|
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
|
2017-04-04 03:15:13 +02:00
|
|
|
description: The `buffer` parameter can be any TypedArray or DataView now.
|
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
|
|
|
|
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
|
|
|
|
2017-10-06 21:19:33 +02:00
|
|
|
- `buffer` {Buffer|TypedArray|DataView|ArrayBuffer|string}
|
2017-03-23 03:45:03 +01:00
|
|
|
|
|
|
|
Decompress a chunk of data with [Gunzip][].
|
2015-11-05 16:40:47 +01:00
|
|
|
|
2017-03-23 03:45:03 +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
|
|
|
|
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
|
2017-04-04 03:15:13 +02:00
|
|
|
description: The `buffer` parameter can be any TypedArray or DataView now.
|
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
|
|
|
|
description: The `buffer` parameter can be an Uint8Array now.
|
2016-05-18 16:30:23 +02:00
|
|
|
-->
|
2017-03-23 03:45:03 +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
|
|
|
|
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
|
2017-04-04 03:15:13 +02:00
|
|
|
description: The `buffer` parameter can be any TypedArray or DataView now.
|
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
|
|
|
|
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
|
|
|
|
2017-10-06 21:19:33 +02:00
|
|
|
- `buffer` {Buffer|TypedArray|DataView|ArrayBuffer|string}
|
2015-11-05 16:40:47 +01:00
|
|
|
|
2017-03-23 03:45:03 +01:00
|
|
|
Compress a chunk of data with [Gzip][].
|
|
|
|
|
|
|
|
### 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
|
|
|
|
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
|
2017-04-04 03:15:13 +02:00
|
|
|
description: The `buffer` parameter can be any TypedArray or DataView now.
|
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
|
|
|
|
description: The `buffer` parameter can be an Uint8Array now.
|
2016-05-18 16:30:23 +02:00
|
|
|
-->
|
2017-03-23 03:45:03 +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
|
|
|
|
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
|
2017-04-04 03:15:13 +02:00
|
|
|
description: The `buffer` parameter can be any TypedArray or DataView now.
|
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
|
|
|
|
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
|
|
|
|
2017-10-06 21:19:33 +02:00
|
|
|
- `buffer` {Buffer|TypedArray|DataView|ArrayBuffer|string}
|
2015-11-05 16:40:47 +01:00
|
|
|
|
2017-03-23 03:45:03 +01:00
|
|
|
Decompress a chunk of data with [Inflate][].
|
|
|
|
|
|
|
|
### 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
|
|
|
|
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
|
2017-04-04 03:15:13 +02:00
|
|
|
description: The `buffer` parameter can be any TypedArray or DataView now.
|
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
|
|
|
|
description: The `buffer` parameter can be an Uint8Array now.
|
2016-05-18 16:30:23 +02:00
|
|
|
-->
|
2017-03-23 03:45:03 +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
|
|
|
|
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
|
2017-04-04 03:15:13 +02:00
|
|
|
description: The `buffer` parameter can be any TypedArray or DataView now.
|
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
|
|
|
|
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
|
|
|
|
2017-10-06 21:19:33 +02:00
|
|
|
- `buffer` {Buffer|TypedArray|DataView|ArrayBuffer|string}
|
2017-03-23 03:45:03 +01:00
|
|
|
|
|
|
|
Decompress a chunk of data with [InflateRaw][].
|
2015-11-05 16:40:47 +01:00
|
|
|
|
2017-03-23 03:45:03 +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
|
|
|
|
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
|
2017-04-04 03:15:13 +02:00
|
|
|
description: The `buffer` parameter can be any TypedArray or DataView now.
|
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
|
|
|
|
description: The `buffer` parameter can be an Uint8Array now.
|
2016-05-18 16:30:23 +02:00
|
|
|
-->
|
2017-03-23 03:45:03 +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
|
|
|
|
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
|
2017-04-04 03:15:13 +02:00
|
|
|
description: The `buffer` parameter can be any TypedArray or DataView now.
|
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
|
|
|
|
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
|
|
|
|
2017-10-06 21:19:33 +02:00
|
|
|
- `buffer` {Buffer|TypedArray|DataView|ArrayBuffer|string}
|
2017-03-23 03:45:03 +01: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
|
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
|
|
|
|
[`TypedArray`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
|
2018-04-10 12:09:47 +02:00
|
|
|
[`options`]: #zlib_class_options
|
2015-11-14 04:21:49 +01:00
|
|
|
[DeflateRaw]: #zlib_class_zlib_deflateraw
|
2017-05-08 18:30:13 +02:00
|
|
|
[Deflate]: #zlib_class_zlib_deflate
|
2015-11-14 04:21:49 +01:00
|
|
|
[Gunzip]: #zlib_class_zlib_gunzip
|
|
|
|
[Gzip]: #zlib_class_zlib_gzip
|
|
|
|
[InflateRaw]: #zlib_class_zlib_inflateraw
|
2017-05-08 18:30:13 +02:00
|
|
|
[Inflate]: #zlib_class_zlib_inflate
|
|
|
|
[Memory Usage Tuning]: #zlib_memory_usage_tuning
|
2015-11-14 04:21:49 +01:00
|
|
|
[Unzip]: #zlib_class_zlib_unzip
|
2017-10-13 22:40:42 +02:00
|
|
|
[`UV_THREADPOOL_SIZE`]: cli.html#cli_uv_threadpool_size_size
|
2018-03-17 16:59:54 +01:00
|
|
|
[`zlib.bytesWritten`]: #zlib_zlib_byteswritten
|
2017-11-23 00:04:16 +01:00
|
|
|
[zlib documentation]: https://zlib.net/manual.html#Constants
|