All files / node-unzipper/lib BufferStream.js

100% Statements 20/20
100% Branches 5/5
100% Functions 2/2
100% Lines 20/20

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 2128x 28x 28x 28x 20x 20x 20x 20x 18x 20x 20x 20x 20x 17x 17x 20x 20x 20x 20x 28x  
var Promise = require('bluebird');
var Stream = require('stream');
 
module.exports = function(entry) {
  return new Promise(function(resolve,reject) {
    var chunks = [];
    var bufferStream = Stream.Transform()
      .on('finish',function() {
        resolve(Buffer.concat(chunks));
      })
      .on('error',reject);
        
    bufferStream._transform = function(d,e,cb) {
      chunks.push(d);
      cb();
    };
    entry.on('error',reject)
      .pipe(bufferStream);
  });
};