All files / node-unzipper/lib BufferStream.js

92.86% Statements 13/14
75% Branches 3/4
100% Functions 4/4
92.86% Lines 13/14

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 21 22 23 24 2524x 24x 24x     24x     24x 19x 19x 19x   17x       19x 16x 16x   19x      
var Promise = require('bluebird');
var Stream = require('stream');
var Buffer = require('./Buffer');
 
// Backwards compatibility for node versions < 8
Iif (!Stream.Writable || !Stream.Writable.prototype.destroy)
  Stream = require('readable-stream');
 
module.exports = function(entry) {
  return new Promise(function(resolve,reject) {
    var buffer = Buffer.from(''),
        bufferStream = Stream.Transform()
          .on('finish',function() {
            resolve(buffer);
          })
          .on('error',reject);
        
    bufferStream._transform = function(d,e,cb) {
      buffer = Buffer.concat([buffer,d]);
      cb();
    };
    entry.on('error',reject)
      .pipe(bufferStream);
  });
};