1 | 'use strict'
|
2 |
|
3 | let stream = require('stream')
|
4 |
|
5 |
|
6 | let transform = new stream.Transform({decodeStrings: false})
|
7 | transform._transform = function (chunk, encoding, next) {
|
8 | let data = chunk
|
9 | if (this._lastLineData) data = this._lastLineData + data
|
10 |
|
11 | let lines = data.split('\n')
|
12 | this._lastLineData = lines.splice(lines.length - 1, 1)[0]
|
13 |
|
14 | lines.forEach(this.push.bind(this))
|
15 | next()
|
16 | }
|
17 |
|
18 | transform._flush = function (done) {
|
19 | if (this._lastLineData) this.push(this._lastLineData)
|
20 | this._lastLineData = null
|
21 | done()
|
22 | }
|
23 |
|
24 | module.exports = transform
|