Skip to content

Commit c6473a9

Browse files
committed
fix(csv-parse): premature close error
1 parent 061062c commit c6473a9

File tree

7 files changed

+41
-11
lines changed

7 files changed

+41
-11
lines changed

packages/csv-parse/dist/cjs/index.cjs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1324,15 +1324,18 @@ class Parser extends stream.Transform {
13241324
this.info = this.api.info;
13251325
}
13261326
// Implementation of `Transform._transform`
1327-
_transform(buf, encoding, callback){
1327+
_transform(buf, _, callback){
13281328
if(this.state.stop === true){
13291329
return;
13301330
}
13311331
const err = this.api.parse(buf, false, (record) => {
13321332
this.push(record);
13331333
}, () => {
13341334
this.push(null);
1335-
this.on('end', this.destroy);
1335+
this.end();
1336+
this.destroy();
1337+
// Note 231005, end wasnt used and destroy was called as:
1338+
// this.on('end', this.destroy);
13361339
});
13371340
if(err !== undefined){
13381341
this.state.stop = true;

packages/csv-parse/dist/esm/index.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -6446,15 +6446,18 @@ class Parser extends Transform {
64466446
this.info = this.api.info;
64476447
}
64486448
// Implementation of `Transform._transform`
6449-
_transform(buf, encoding, callback){
6449+
_transform(buf, _, callback){
64506450
if(this.state.stop === true){
64516451
return;
64526452
}
64536453
const err = this.api.parse(buf, false, (record) => {
64546454
this.push(record);
64556455
}, () => {
64566456
this.push(null);
6457-
this.on('end', this.destroy);
6457+
this.end();
6458+
this.destroy();
6459+
// Note 231005, end wasnt used and destroy was called as:
6460+
// this.on('end', this.destroy);
64586461
});
64596462
if(err !== undefined){
64606463
this.state.stop = true;

packages/csv-parse/dist/iife/index.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -6449,15 +6449,18 @@ var csv_parse = (function (exports) {
64496449
this.info = this.api.info;
64506450
}
64516451
// Implementation of `Transform._transform`
6452-
_transform(buf, encoding, callback){
6452+
_transform(buf, _, callback){
64536453
if(this.state.stop === true){
64546454
return;
64556455
}
64566456
const err = this.api.parse(buf, false, (record) => {
64576457
this.push(record);
64586458
}, () => {
64596459
this.push(null);
6460-
this.on('end', this.destroy);
6460+
this.end();
6461+
this.destroy();
6462+
// Note 231005, end wasnt used and destroy was called as:
6463+
// this.on('end', this.destroy);
64616464
});
64626465
if(err !== undefined){
64636466
this.state.stop = true;

packages/csv-parse/dist/umd/index.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -6452,15 +6452,18 @@
64526452
this.info = this.api.info;
64536453
}
64546454
// Implementation of `Transform._transform`
6455-
_transform(buf, encoding, callback){
6455+
_transform(buf, _, callback){
64566456
if(this.state.stop === true){
64576457
return;
64586458
}
64596459
const err = this.api.parse(buf, false, (record) => {
64606460
this.push(record);
64616461
}, () => {
64626462
this.push(null);
6463-
this.on('end', this.destroy);
6463+
this.end();
6464+
this.destroy();
6465+
// Note 231005, end wasnt used and destroy was called as:
6466+
// this.on('end', this.destroy);
64646467
});
64656468
if(err !== undefined){
64666469
this.state.stop = true;

packages/csv-parse/lib/index.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,18 @@ class Parser extends Transform {
2424
this.info = this.api.info;
2525
}
2626
// Implementation of `Transform._transform`
27-
_transform(buf, encoding, callback){
27+
_transform(buf, _, callback){
2828
if(this.state.stop === true){
2929
return;
3030
}
3131
const err = this.api.parse(buf, false, (record) => {
3232
this.push(record);
3333
}, () => {
3434
this.push(null);
35-
this.on('end', this.destroy);
35+
this.end();
36+
this.destroy();
37+
// Note 231005, end wasnt used and destroy was called as:
38+
// this.on('end', this.destroy);
3639
});
3740
if(err !== undefined){
3841
this.state.stop = true;

packages/csv-parse/test/api.stream.finished.coffee

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11

22
import * as stream from 'node:stream/promises'
3-
import { Readable } from 'stream'
43
import { generate } from 'csv-generate'
54
import { parse } from '../lib/index.js'
65

packages/csv-parse/test/option.to_line.coffee

+16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11

2+
import { Readable } from 'stream'
3+
import { finished } from 'node:stream/promises'
24
import { parse } from '../lib/index.js'
5+
import { generate } from 'csv-generate'
36

47
describe 'Option `to_line`', ->
58

@@ -97,3 +100,16 @@ describe 'Option `to_line`', ->
97100
[ 'd','e','f' ]
98101
] unless err
99102
next err
103+
104+
it 'resolved with `to_line`', ->
105+
# Prevent `Error [ERR_STREAM_PREMATURE_CLOSE]: Premature close`
106+
reader = new Readable
107+
highWaterMark: 100
108+
read: (size) ->
109+
setImmediate =>
110+
for i in [0...size]
111+
this.push "#{size},#{i}\n"
112+
parser = reader.pipe parse to_line: 3
113+
parser.on 'readable', () =>
114+
while parser.read() isnt null then true
115+
await finished parser

0 commit comments

Comments
 (0)