Skip to content

Commit cbdcf88

Browse files
committed
Should resolve #39
Rename _destroy to cleanup
1 parent bd70bb3 commit cbdcf88

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/JsonStreamStringify.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,7 @@ export class JsonStreamStringify extends Readable {
486486
readMore = false;
487487
readState: ReadState = ReadState.NotReading;
488488
async _read(size?: number) {
489+
if (this.readState === ReadState.Consumed) return;
489490
if (this.readState !== ReadState.NotReading) {
490491
this.readState = ReadState.ReadMore;
491492
return;
@@ -502,7 +503,7 @@ export class JsonStreamStringify extends Readable {
502503
if (this.buffer.length) this.push(this.buffer);
503504
this.push(null);
504505
this.readState = ReadState.Consumed;
505-
this._destroy();
506+
this.cleanup();
506507
}
507508
if (this.readState === <any>ReadState.ReadMore) {
508509
this.readState = ReadState.NotReading;
@@ -511,18 +512,18 @@ export class JsonStreamStringify extends Readable {
511512
this.readState = ReadState.NotReading;
512513
}
513514

514-
_destroy() {
515-
this.destroyed = true;
515+
private cleanup() {
516516
this.buffer = undefined;
517517
this.visited = undefined;
518518
this.item = undefined;
519+
this.root = undefined;
519520
this.prePush = undefined;
520521
}
521522

522523
destroy(error?: Error): this {
523524
if (error) this.emit('error', error);
524525
super.destroy?.();
525-
this._destroy();
526+
this.cleanup();
526527
return this;
527528
}
528529
}

0 commit comments

Comments
 (0)