Skip to content

Commit 2910075

Browse files
committed
Fix node v7 incompatibility
1 parent 8eece0e commit 2910075

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/JsonStreamStringify.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ function quoteString(string: string) {
112112

113113
function readAsPromised(stream: Readable, size?) {
114114
const value = stream.read(size);
115-
if (value === null && !stream.readableEnded) {
115+
if (value === null && !(stream.readableEnded || (stream as any)._readableState?.ended)) {
116116
return new Promise((resolve, reject) => {
117117
const endListener = () => resolve(null);
118118
stream.once('end', endListener);

test-src/JsonStreamStringify.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,17 +418,19 @@ describe('JsonStreamStringify', function () {
418418
a.on('data', (data) => {
419419
out += data.toString();
420420
}).pause();
421+
let ended = false;
421422
read();
422423
function read() {
423424
if (a.readableEnded) return;
424425
for (let i = 0; i < 10; i++) {
425426
a._read(); // simulate bad forced read
426427
a.read(); // legitimate read call
427428
a._read(); // simulate bad forced read
428-
if (!p.writableEnded && i === 8) p.write(c++);
429+
if (!(p.writableEnded || ended) && i === 8) p.write(c++);
429430
a._read(); // simulate bad forced read
430431
}
431-
if (!p.writableEnded && c > 3) {
432+
if (!(p.writableEnded || ended) && c > 3) {
433+
ended = true;
432434
p.end();
433435
// p.read();
434436
setTimeout(read, 10);

0 commit comments

Comments
 (0)