Skip to content

Commit bef5a30

Browse files
committed
Merge branch 'mmsqe-master'
2 parents d41f1e0 + 927fcc6 commit bef5a30

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/JsonStreamStringify.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,9 @@ class JsonStreamStringify extends Readable {
189189
obj.isEmpty = !obj.unread.length;
190190
} else if (type === 'Array') {
191191
this.depth += 1;
192-
obj.unread = Array.from(Array(realValue.length).keys());
193-
obj.isEmpty = !obj.unread.length;
192+
obj.unread = realValue.length;
193+
obj.arrayLength = obj.unread;
194+
obj.isEmpty = !obj.unread;
194195
} else if (type.startsWith('Readable')) {
195196
this.depth += 1;
196197
if (realValue._readableState.ended) {
@@ -267,12 +268,20 @@ class JsonStreamStringify extends Readable {
267268
}
268269
const key = current.unread.shift();
269270
const value = current.value[key];
270-
271-
this.addToStack(value, current.type === 'Object' && key, current.type === 'Array' && key, current);
271+
this.addToStack(value, key, undefined, current);
272272
}
273273

274274
processArray(current) {
275-
return this.processObject(current);
275+
const key = current.unread;
276+
if (!key) {
277+
this.removeFromStack(current);
278+
return;
279+
}
280+
const index = current.arrayLength - key;
281+
const value = current.value[index];
282+
/* eslint-disable-next-line no-param-reassign */
283+
current.unread -= 1;
284+
this.addToStack(value, undefined, index, current);
276285
}
277286

278287
processPrimitive(current) {

0 commit comments

Comments
 (0)