Last active
August 29, 2015 14:02
-
-
Save jstuckey/9c0e5f7f46a6922e01a5 to your computer and use it in GitHub Desktop.
Zlib Module - Demo for Node.dc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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