(dataCallback)
| 31 | } |
| 32 | |
| 33 | function makeBufferingDataCallback(dataCallback) { |
| 34 | let buffer = Buffer.alloc(0); |
| 35 | return (data) => { |
| 36 | const newData = Buffer.concat([buffer, data]); |
| 37 | const str = newData.toString('utf8'); |
| 38 | const lines = str.replace(/\r/g, '').split('\n'); |
| 39 | if (str.endsWith('\n')) |
| 40 | buffer = Buffer.alloc(0); |
| 41 | else |
| 42 | buffer = Buffer.from(lines.pop(), 'utf8'); |
| 43 | for (const line of lines) |
| 44 | dataCallback(line); |
| 45 | }; |
| 46 | } |
| 47 | |
| 48 | function tearDown(child, err) { |
| 49 | child.kill(); |