UNPKG

693 BJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const stream = require("stream");
4// this splits a stream into lines
5let transform = new stream.Transform({ decodeStrings: false });
6transform._transform = function (chunk, _encoding, next) {
7 let data = chunk;
8 if (this._lastLineData)
9 data = this._lastLineData + data;
10 let lines = data.split('\n');
11 this._lastLineData = lines.splice(lines.length - 1, 1)[0];
12 lines.forEach(this.push.bind(this));
13 next();
14};
15transform._flush = function (done) {
16 if (this._lastLineData)
17 this.push(this._lastLineData);
18 this._lastLineData = null;
19 done();
20};
21exports.default = transform;