You can access this module with:
var zlib = require('zlib');
var gzip = zlib.createGzip();
var fs = require('fs');
var inp = fs.createReadStream('input.txt');
var out = fs.createWriteStream('input.txt.gz');
inp.pipe(gzip).pipe(out);
This provides bindings to Gzip/Gunzip, Deflate/Inflate, and DeflateRaw/InflateRaw classes. Each class takes the same options, and is a readable/writable Stream.
All of the constants defined in zlib.h are also defined on
require('zlib')
. They are described in more detail in the zlib
documentation. See http://zlib.net/manual.html#Constants
for more details.
Compress data using gzip.
Decompress a gzip stream.
Compress data using deflate.
Decompress a deflate stream.
Compress data using deflate, and do not append a zlib header.
Decompress a raw deflate stream.
Decompress either a Gzip- or Deflate-compressed stream by auto-detecting the header.
Each class takes an options object. All options are optional.
Note that some options are only relevant when compressing, and are ignored by the decompression classes.
See the description of deflateInit2
and inflateInit2
at
http://zlib.net/manual.html#Advanced for more information on these.
From zlib/zconf.h
, modified to node's usage:
The memory requirements for deflate are (in bytes):
(1 << (windowBits+2)) + (1 << (memLevel+9))
that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) plus a few kilobytes for small objects.
For example, if you want to reduce the default memory requirements from 256K to 128K, set the options to:
{ windowBits: 14, memLevel: 7 }
Of course this will generally degrade compression (there's no free lunch).
The memory requirements for inflate are (in bytes)
1 << windowBits
that is, 32K for windowBits=15 (default value) plus a few kilobytes for small objects.
This is in addition to a single internal output slab buffer of size
chunkSize
, which defaults to 16K.