2012-02-27 20:09:35 +01:00
|
|
|
# Zlib
|
2011-09-07 01:13:05 +02:00
|
|
|
|
2015-02-25 01:15:26 +01: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-05-13 22:56:30 +02:00
|
|
|
Compressing or decompressing a stream (such as a file) can be accomplished by
|
|
|
|
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
|
|
|
|
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`
|
|
|
|
content-encoding mechanisms defined by
|
|
|
|
[HTTP](https://tools.ietf.org/html/rfc7230#section-4.2).
|
|
|
|
|
|
|
|
The HTTP [`Accept-Encoding`][] header is used within an http request to identify
|
|
|
|
the compression encodings accepted by the client. The [`Content-Encoding`][]
|
|
|
|
header is used to identify the compression encodings actually applied to a
|
|
|
|
message.
|
2011-10-14 18:20:05 +02:00
|
|
|
|
2016-05-13 22:56:30 +02:00
|
|
|
**Note: the examples given below are drastically simplified to show
|
|
|
|
the basic concept.** Using `zlib` encoding can be expensive, and the results
|
2016-01-05 11:49:54 +01:00
|
|
|
ought to be cached. See [Memory Usage Tuning][] for more information
|
2016-05-13 22:56:30 +02:00
|
|
|
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',
|
2016-01-17 18:39:07 +01:00
|
|
|
path: '/',
|
|
|
|
port: 80,
|
2016-05-13 22:56:30 +02:00
|
|
|
headers: { 'Accept-Encoding': 'gzip,deflate' } });
|
2016-01-17 18:39:07 +01:00
|
|
|
request.on('response', (response) => {
|
2016-05-13 22:56:30 +02:00
|
|
|
var 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;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// 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) => {
|
|
|
|
var raw = fs.createReadStream('index.html');
|
|
|
|
var acceptEncoding = request.headers['accept-encoding'];
|
|
|
|
if (!acceptEncoding) {
|
|
|
|
acceptEncoding = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Note: this is not a conformant accept-encoding parser.
|
|
|
|
// See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.3
|
|
|
|
if (acceptEncoding.match(/\bdeflate\b/)) {
|
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);
|
|
|
|
} else if (acceptEncoding.match(/\bgzip\b/)) {
|
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-05-13 22:56:30 +02:00
|
|
|
By default, the `zlib` methods with 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
|
|
|
|
method that is used to compressed the last chunk of input data:
|
|
|
|
|
|
|
|
```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
|
|
|
|
2016-06-07 23:38:00 +02:00
|
|
|
zlib.unzip(buffer,
|
|
|
|
{finishFlush: zlib.constants.Z_SYNC_FLUSH},
|
|
|
|
(err, buffer) => {
|
2016-04-06 00:54:34 +02:00
|
|
|
if (!err) {
|
|
|
|
console.log(buffer.toString());
|
|
|
|
} else {
|
|
|
|
// handle error
|
|
|
|
}
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
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
|
|
|
|
2015-08-13 18:14:34 +02: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):
|
|
|
|
|
2016-01-17 18:39:07 +01:00
|
|
|
```
|
|
|
|
(1 << (windowBits+2)) + (1 << (memLevel+9))
|
|
|
|
```
|
2011-09-07 01:13:05 +02:00
|
|
|
|
2016-05-13 22:56:30 +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
|
|
|
|
options shoud be set to:
|
2011-09-07 01:13:05 +02:00
|
|
|
|
2016-01-17 18:39:07 +01:00
|
|
|
```
|
|
|
|
{ windowBits: 14, memLevel: 7 }
|
|
|
|
```
|
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
|
|
|
|
|
|
|
The memory requirements for inflate are (in bytes)
|
|
|
|
|
2016-01-17 18:39:07 +01:00
|
|
|
```
|
|
|
|
1 << windowBits
|
|
|
|
```
|
2011-09-07 01:13:05 +02:00
|
|
|
|
2016-05-13 22:56:30 +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
|
2011-10-14 18:20:05 +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
|
|
|
|
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
|
|
|
|
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
|
|
|
|
necessary to use these constants. They are documented so that their presence is
|
|
|
|
not surprising. This section is taken almost directly from the
|
|
|
|
[zlib documentation][]. See <http://zlib.net/manual.html#Constants> for more
|
|
|
|
details.
|
|
|
|
|
|
|
|
*Note*: 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 should be considered
|
|
|
|
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
|
|
|
|
|
|
|
## Class Options
|
2016-05-18 16:30:23 +02:00
|
|
|
<!-- YAML
|
|
|
|
added: v0.11.1
|
|
|
|
-->
|
2015-11-05 16:40:47 +01:00
|
|
|
|
|
|
|
<!--type=misc-->
|
|
|
|
|
2016-05-13 22:56:30 +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.
|
|
|
|
|
2016-06-07 23:38:00 +02:00
|
|
|
* `flush` (default: `zlib.constants.Z_NO_FLUSH`)
|
|
|
|
* `finishFlush` (default: `zlib.constants.Z_FINISH`)
|
2016-05-13 22:56:30 +02:00
|
|
|
* `chunkSize` (default: 16*1024)
|
|
|
|
* `windowBits`
|
|
|
|
* `level` (compression only)
|
|
|
|
* `memLevel` (compression only)
|
|
|
|
* `strategy` (compression only)
|
|
|
|
* `dictionary` (deflate/inflate only, empty dictionary by default)
|
2015-11-05 16:40:47 +01:00
|
|
|
|
|
|
|
See the description of `deflateInit2` and `inflateInit2` at
|
|
|
|
<http://zlib.net/manual.html#Advanced> for more information on these.
|
|
|
|
|
|
|
|
## 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
|
|
|
|
-->
|
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
|
|
|
|
-->
|
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
|
|
|
|
-->
|
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.
|
|
|
|
|
|
|
|
### 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
|
|
|
|
2016-06-07 23:38:00 +02:00
|
|
|
`kind` defaults to `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-06-07 23:38:00 +02:00
|
|
|
## zlib.constants
|
|
|
|
|
|
|
|
Provides an object enumerating Zlib-related [constants][].
|
|
|
|
|
2015-11-05 16:40:47 +01:00
|
|
|
Reset the compressor/decompressor to factory defaults. Only applicable to
|
|
|
|
the inflate and deflate algorithms.
|
|
|
|
|
|
|
|
## zlib.createDeflate([options])
|
2016-05-18 16:30:23 +02:00
|
|
|
<!-- YAML
|
|
|
|
added: v0.5.8
|
|
|
|
-->
|
2015-11-05 16:40:47 +01:00
|
|
|
|
2015-11-14 04:21:49 +01:00
|
|
|
Returns a new [Deflate][] object with an [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
|
|
|
|
2015-11-14 04:21:49 +01:00
|
|
|
Returns a new [DeflateRaw][] object with an [options][].
|
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
|
|
|
|
2015-11-14 04:21:49 +01:00
|
|
|
Returns a new [Gunzip][] object with an [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
|
|
|
|
2015-11-14 04:21:49 +01:00
|
|
|
Returns a new [Gzip][] object with an [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
|
|
|
|
2015-11-14 04:21:49 +01:00
|
|
|
Returns a new [Inflate][] object with an [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
|
|
|
|
2015-11-14 04:21:49 +01:00
|
|
|
Returns a new [InflateRaw][] object with an [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
|
|
|
|
2015-11-14 04:21:49 +01:00
|
|
|
Returns a new [Unzip][] object with an [options][].
|
2015-11-05 16:40:47 +01:00
|
|
|
|
|
|
|
## Convenience Methods
|
|
|
|
|
|
|
|
<!--type=misc-->
|
|
|
|
|
2016-05-13 22:56:30 +02:00
|
|
|
All of these take a [Buffer][] 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.
|
|
|
|
|
|
|
|
### zlib.deflate(buf[, options], callback)
|
2016-05-18 16:30:23 +02:00
|
|
|
<!-- YAML
|
|
|
|
added: v0.6.0
|
|
|
|
-->
|
2016-03-13 17:16:15 +01:00
|
|
|
### zlib.deflateSync(buf[, options])
|
2016-05-18 16:30:23 +02:00
|
|
|
<!-- YAML
|
|
|
|
added: v0.11.12
|
|
|
|
-->
|
2015-11-05 16:40:47 +01:00
|
|
|
|
2016-03-13 17:16:15 +01:00
|
|
|
Compress a Buffer or string with Deflate.
|
2015-11-05 16:40:47 +01:00
|
|
|
|
|
|
|
### zlib.deflateRaw(buf[, options], callback)
|
2016-05-18 16:30:23 +02:00
|
|
|
<!-- YAML
|
|
|
|
added: v0.6.0
|
|
|
|
-->
|
2015-11-05 16:40:47 +01:00
|
|
|
### zlib.deflateRawSync(buf[, options])
|
2016-05-18 16:30:23 +02:00
|
|
|
<!-- YAML
|
|
|
|
added: v0.11.12
|
|
|
|
-->
|
2015-11-05 16:40:47 +01:00
|
|
|
|
2016-03-13 17:16:15 +01:00
|
|
|
Compress a Buffer or string with DeflateRaw.
|
2015-11-05 16:40:47 +01:00
|
|
|
|
|
|
|
### zlib.gunzip(buf[, options], callback)
|
2016-05-18 16:30:23 +02:00
|
|
|
<!-- YAML
|
|
|
|
added: v0.6.0
|
|
|
|
-->
|
2015-11-05 16:40:47 +01:00
|
|
|
### zlib.gunzipSync(buf[, options])
|
2016-05-18 16:30:23 +02:00
|
|
|
<!-- YAML
|
|
|
|
added: v0.11.12
|
|
|
|
-->
|
2015-11-05 16:40:47 +01:00
|
|
|
|
2016-03-13 17:16:15 +01:00
|
|
|
Decompress a Buffer or string with Gunzip.
|
2015-11-05 16:40:47 +01:00
|
|
|
|
|
|
|
### zlib.gzip(buf[, options], callback)
|
2016-05-18 16:30:23 +02:00
|
|
|
<!-- YAML
|
|
|
|
added: v0.6.0
|
|
|
|
-->
|
2015-11-05 16:40:47 +01:00
|
|
|
### zlib.gzipSync(buf[, options])
|
2016-05-18 16:30:23 +02:00
|
|
|
<!-- YAML
|
|
|
|
added: v0.11.12
|
|
|
|
-->
|
2015-11-05 16:40:47 +01:00
|
|
|
|
2016-03-13 17:16:15 +01:00
|
|
|
Compress a Buffer or string with Gzip.
|
2015-11-05 16:40:47 +01:00
|
|
|
|
|
|
|
### zlib.inflate(buf[, options], callback)
|
2016-05-18 16:30:23 +02:00
|
|
|
<!-- YAML
|
|
|
|
added: v0.6.0
|
|
|
|
-->
|
2016-03-13 17:16:15 +01:00
|
|
|
### zlib.inflateSync(buf[, options])
|
2016-05-18 16:30:23 +02:00
|
|
|
<!-- YAML
|
|
|
|
added: v0.11.12
|
|
|
|
-->
|
2015-11-05 16:40:47 +01:00
|
|
|
|
2016-03-13 17:16:15 +01:00
|
|
|
Decompress a Buffer or string with Inflate.
|
2015-11-05 16:40:47 +01:00
|
|
|
|
|
|
|
### zlib.inflateRaw(buf[, options], callback)
|
2016-05-18 16:30:23 +02:00
|
|
|
<!-- YAML
|
|
|
|
added: v0.6.0
|
|
|
|
-->
|
2015-11-05 16:40:47 +01:00
|
|
|
### zlib.inflateRawSync(buf[, options])
|
2016-05-18 16:30:23 +02:00
|
|
|
<!-- YAML
|
|
|
|
added: v0.11.12
|
|
|
|
-->
|
2015-11-05 16:40:47 +01:00
|
|
|
|
2016-03-13 17:16:15 +01:00
|
|
|
Decompress a Buffer or string with InflateRaw.
|
2015-11-05 16:40:47 +01:00
|
|
|
|
|
|
|
### zlib.unzip(buf[, options], callback)
|
2016-05-18 16:30:23 +02:00
|
|
|
<!-- YAML
|
|
|
|
added: v0.6.0
|
|
|
|
-->
|
2015-11-05 16:40:47 +01:00
|
|
|
### zlib.unzipSync(buf[, options])
|
2016-05-18 16:30:23 +02:00
|
|
|
<!-- YAML
|
|
|
|
added: v0.11.12
|
|
|
|
-->
|
2015-11-05 16:40:47 +01:00
|
|
|
|
2016-03-13 17:16:15 +01:00
|
|
|
Decompress a Buffer or string with Unzip.
|
2015-11-14 04:21:49 +01:00
|
|
|
|
2016-05-13 22:56:30 +02:00
|
|
|
[`Accept-Encoding`]: https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.3
|
|
|
|
[`Content-Encoding`]: https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.11
|
2015-11-14 04:21:49 +01:00
|
|
|
[Memory Usage Tuning]: #zlib_memory_usage_tuning
|
|
|
|
[zlib documentation]: http://zlib.net/manual.html#Constants
|
2015-11-20 20:28:11 +01:00
|
|
|
[options]: #zlib_class_options
|
2015-11-14 04:21:49 +01:00
|
|
|
[Deflate]: #zlib_class_zlib_deflate
|
|
|
|
[DeflateRaw]: #zlib_class_zlib_deflateraw
|
|
|
|
[Gunzip]: #zlib_class_zlib_gunzip
|
|
|
|
[Gzip]: #zlib_class_zlib_gzip
|
|
|
|
[Inflate]: #zlib_class_zlib_inflate
|
|
|
|
[InflateRaw]: #zlib_class_zlib_inflateraw
|
|
|
|
[Unzip]: #zlib_class_zlib_unzip
|
2016-04-19 10:04:07 +02:00
|
|
|
[`.flush()`]: #zlib_zlib_flush_kind_callback
|
2016-03-13 17:16:15 +01:00
|
|
|
[Buffer]: buffer.html
|
2016-06-07 23:38:00 +02:00
|
|
|
[constants]: #constants_constants
|