Skip to content

Instantly share code, notes, and snippets.

@jstuckey
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jstuckey/9c0e5f7f46a6922e01a5 to your computer and use it in GitHub Desktop.
Save jstuckey/9c0e5f7f46a6922e01a5 to your computer and use it in GitHub Desktop.
Zlib Module - Demo for Node.dc
// Zlib - Node wrapper around the zlib compression library
var zlib = require('zlib');
var gzip = zlib.createGzip();
var gunzip = zlib.createGunzip();
var fs = require('fs');
var inStream1 = fs.createReadStream('input.txt');
var outStream1 = fs.createWriteStream('tmp/output.txt.gz');
// Compress input.txt using gzip
inStream1
.pipe(gzip)
.pipe(outStream1);
// Uncompress ouput.txt.gz using gunzip
outStream1.on('finish', function() {
var inStream2 = fs.createReadStream('tmp/output.txt.gz');
var outStream2 = fs.createWriteStream('tmp/output.txt');
inStream2
.pipe(gunzip)
.pipe(outStream2);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment