(chunk)
| 18 | // done: all lines emitted |
| 19 | |
| 20 | write(chunk) { |
| 21 | // find line or lines in chunk and emit them if not corked |
| 22 | // or queue them if corked |
| 23 | const data = this.buffer ? this.buffer + chunk : chunk; |
| 24 | const lines = data.split(/\r?\n/g); |
| 25 | |
| 26 | // save the last line |
| 27 | this.buffer = lines.pop(); |
| 28 | |
| 29 | lines.forEach(function(line) { |
| 30 | if (this.corked) { |
| 31 | this.queue.push(line); |
| 32 | } else { |
| 33 | this.emit('line', line); |
| 34 | } |
| 35 | }); |
| 36 | |
| 37 | return !this.corked; |
| 38 | } |
| 39 | |
| 40 | cork() { |
| 41 | this.corked = true; |