| 27 | } |
| 28 | // Implementation of `Transform._transform` |
| 29 | _transform(buf, _, callback) { |
| 30 | if (this.state.stop === true) { |
| 31 | return; |
| 32 | } |
| 33 | const err = this.api.parse( |
| 34 | buf, |
| 35 | false, |
| 36 | (record) => { |
| 37 | this.push(record); |
| 38 | }, |
| 39 | () => { |
| 40 | this.push(null); |
| 41 | this.end(); |
| 42 | // Fix #333 and break #410 |
| 43 | // ko: api.stream.iterator.coffee |
| 44 | // ko with v21.4.0, ok with node v20.5.1: api.stream.finished # aborted (with generate()) |
| 45 | // ko: api.stream.finished # aborted (with Readable) |
| 46 | // this.destroy() |
| 47 | // Fix #410 and partially break #333 |
| 48 | // ok: api.stream.iterator.coffee |
| 49 | // ok: api.stream.finished # aborted (with generate()) |
| 50 | // broken: api.stream.finished # aborted (with Readable) |
| 51 | this.on("end", this.destroy); |
| 52 | }, |
| 53 | ); |
| 54 | if (err !== undefined) { |
| 55 | this.state.stop = true; |
| 56 | } |
| 57 | callback(err); |
| 58 | } |
| 59 | // Implementation of `Transform._flush` |
| 60 | _flush(callback) { |
| 61 | if (this.state.stop === true) { |