line-for-line.js (667B)
1 const through = require('through2'); 2 const multipipe = require('multipipe'); 3 const characterize = require('./char-for-char'); 4 const normalize = require('./normalize-newlines.js'); 5 6 module.exports = () => 7 multipipe( 8 characterize(), 9 normalize(), 10 through.obj(function(chunk, enc, cb) { 11 if (!this.buf) this.buf = Buffer.alloc(0); 12 if (chunk.toString() == '\n') { 13 this.push(this.buf); 14 this.buf = Buffer.alloc(0); 15 return cb(); 16 } 17 const buf = Buffer.alloc(this.buf.length + chunk.length); 18 this.buf.copy(buf, 0); 19 chunk.copy(buf, this.buf.length); 20 this.buf = buf; 21 cb(); 22 }) 23 )