UNPKG

stream-tail

Version:

Through stream that emits the last few chunks of input

27 lines (20 loc) 483 B
const through2 = require("through2"); function tailStream(count) { var buffer = []; return through2.obj( function (chunk, enc, cb) { buffer.push(chunk); if (buffer.length > count) { buffer.shift(); } cb(); }, function (cb) { buffer.forEach((chunk) => { this.push(chunk); }); cb(); } ); } module.exports = tailStream;