如何在nodejs中gunzipstream?

我试图完成一个相当简单的任务,但我有点困惑,并陷入在nodejs中使用zlib。 我正在构build的function,包括我从aws S3下载文件gziped,解压缩并逐行阅读。 我想完成所有这些使用stream,因为我相信在nodejs中可以这样做。

这是我目前的代码库:

//downloading zipped file from aws s3: //params are configured correctly to access my aws s3 bucket and file s3.getObject(params, function(err, data) { if (err) { console.log(err); } else { //trying to unzip received stream: //data.Body is a buffer from s3 zlib.gunzip(data.Body, function(err, unzippedStream) { if (err) { console.log(err); } else { //reading line by line unzziped stream: var lineReader = readline.createInterface({ input: unzippedStream }); lineReader.on('line', function(lines) { console.log(lines); }); } }); } }); 

我得到一个错误说:

  readline.js:113 input.on('data', ondata); ^ TypeError: input.on is not a function 

我相信一个问题可能是在解压过程中,但我不太确定有什么问题,任何帮助,将不胜感激。

我没有S3帐户来testing,但阅读文档表明, s3.getObject()可以返回一个stream,在这种情况下,我认为这可能工作:

 var lineReader = readline.createInterface({ input: s3.getObject(params).pipe(zlib.createGunzip()) }); lineReader.on('line', function(lines) { console.log(lines); }); 

编辑 :看起来像API可能已经改变,你现在需要手动实例化stream对象,然后才能通过其他任何东西pipe道:

 s3.getObject(params).createReadStream().pipe(...)