node.js zlib returning 'Check Headers' error when gunzipping stream -


so working on nodeschool.io stream-adventure tutorial track , i'm having trouble last problem. instructions say:

an encrypted, gzipped tar file piped in on process.stdin. beat challenge, each file in tar input, print hex-encoded md5 hash of file contents followed single space followed filename, newline.  receive cipher name process.argv[2] , cipher passphrase process.argv[3]. can pass these arguments directly through `crypto.createdecipher()`.  built-in zlib library when `require('zlib')` has `zlib.creategunzip()` returns stream gunzipping.  `tar` module npm has `tar.parse()` function emits `'entry'` events each file in tar input. each `entry` object readable stream of file contents archive and:  `entry.type` kind of file ('file', 'directory', etc) `entry.path` file path  using tar module looks like:      var tar = require('tar');     var parser = tar.parse();     parser.on('entry', function (e) {         console.dir(e);     });     var fs = require('fs');     fs.createreadstream('file.tar').pipe(parser);  use `crypto.createhash('md5', { encoding: 'hex' })` generate stream outputs hex md5 hash content written it. 

this attempt far work on it:

var tar = require('tar'); var crypto = require('crypto'); var zlib = require('zlib'); var map = require('through2-map');  var cipheralg = process.argv[2]; var passphrase = process.argv[3];  var cryptostream = crypto.createdecipher(cipheralg, passphrase); var parser = tar.parse(); //emits 'entry' events per file in tar input var gunzip = zlib.creategunzip();  parser.on('entry', function(e) {     e.pipe(cryptostream).pipe(map(function(chunk) {         console.log(chunk.tostring());     })); });  process.stdin     .pipe(gunzip)     .pipe(parser); 

i know it's not complete yet, issue when try run this, input never gets piped tar file parsing part. seems hang on piping gunzip. exact error:

events.js:72         throw er; // unhandled 'error' event               ^ error: incorrect header check     @ zlib._binding.onerror (zlib.js:295:17) 

i'm totally stumped because node documentation zlib has no mention of headers except when has examples http/request modules. there number of other questions regarding error node, use buffers rather streams, couldn't find relevant answer problem. appreciated

i figured out, supposed decrypt stream before unzipping it.

so instead of:

process.stdin     .pipe(gunzip)     .pipe(parser); 

it should be:

process.stdin     .pipe(cryptostream)     .pipe(gunzip)     .pipe(parser); 

Comments