Skip to content

Commit

Permalink
Merge pull request #182 from jsnajdr/speedup-entry-buffer
Browse files Browse the repository at this point in the history
BufferStream: improve performance by running concat only once at the end
  • Loading branch information
ZJONSSON committed Feb 28, 2020
2 parents d9a785a + 16868c3 commit 210c85f
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions lib/BufferStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ if (!Stream.Writable || !Stream.Writable.prototype.destroy)

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);
var chunks = [];
var bufferStream = Stream.Transform()
.on('finish',function() {
resolve(Buffer.concat(chunks));
})
.on('error',reject);

bufferStream._transform = function(d,e,cb) {
buffer = Buffer.concat([buffer,d]);
chunks.push(d);
cb();
};
entry.on('error',reject)
.pipe(bufferStream);
});
};
};

0 comments on commit 210c85f

Please sign in to comment.