You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
669 B
26 lines
669 B
4 years ago
|
var Promise = require('bluebird');
|
||
|
var Stream = require('stream');
|
||
|
var Buffer = require('./Buffer');
|
||
|
|
||
|
// Backwards compatibility for node versions < 8
|
||
|
if (!Stream.Writable || !Stream.Writable.prototype.destroy)
|
||
|
Stream = require('readable-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);
|
||
|
});
|
||
|
};
|