diff --git a/package.json b/package.json index 34d9828..b49c8ed 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "json-stream-stringify", "description": "JSON.Stringify as a readable stream", - "version": "3.1.2", + "version": "3.1.3", "license": "MIT", "author": "Faleij (https://github.com/faleij)", "repository": { @@ -71,7 +71,7 @@ "typescript": "^4.7.4" }, "volta": { - "node": "18.16.0" + "node": "16.20.2" }, "engines": { "node": ">=7.10.1" diff --git a/src/JsonStreamStringify.ts b/src/JsonStreamStringify.ts index 2d7af26..ea97f06 100644 --- a/src/JsonStreamStringify.ts +++ b/src/JsonStreamStringify.ts @@ -494,11 +494,12 @@ export class JsonStreamStringify extends Readable { this.readState = ReadState.Reading; this.pushCalled = false; let p; - while (!this.pushCalled && this.item !== this.root && !this.destroyed) { + while (!this.pushCalled && this.item !== this.root && this.buffer !== undefined) { p = this.item.read(size); // eslint-disable-next-line no-await-in-loop if (p) await p; } + if (this.buffer === undefined) return; if (this.item === this.root) { if (this.buffer.length) this.push(this.buffer); this.push(null); @@ -513,6 +514,7 @@ export class JsonStreamStringify extends Readable { } private cleanup() { + this.readState = ReadState.Consumed; this.buffer = undefined; this.visited = undefined; this.item = undefined;