MCPcopy Create free account
hub / github.com/Faleij/json-stream-stringify / _read

Method _read

src/JsonStreamStringify.ts:475–503  ·  view source on GitHub ↗
(size?: number)

Source from the content-addressed store, hash-verified

473
474 readState: ReadState = ReadState.Inactive;
475 async _read(size?: number): Promise<void> {
476 if (this.readState === ReadState.Consumed) return;
477 if (this.readState !== ReadState.Inactive) {
478 this.readState = ReadState.ReadMore;
479 return;
480 }
481 this.readState = ReadState.Reading;
482 this.pushCalled = false;
483 let p;
484 while (!this.pushCalled && this.item !== this.root && this.buffer !== undefined) {
485 p = this.item.read(size);
486 // eslint-disable-next-line no-await-in-loop
487 if (p) await p;
488 }
489 if (this.buffer === undefined) return;
490 if (this.item === this.root) {
491 if (this.buffer.length) this.push(this.buffer);
492 this.push(null);
493 this.readState = ReadState.Consumed;
494 this.cleanup();
495 return;
496 }
497 if (this.readState === <any>ReadState.ReadMore) {
498 this.readState = ReadState.Inactive;
499 await this._read(size);
500 return;
501 }
502 this.readState = ReadState.Inactive;
503 }
504
505 private cleanup() {
506 this.readState = ReadState.Consumed;

Callers 1

readFunction · 0.80

Calls 2

cleanupMethod · 0.95
readMethod · 0.65

Tested by 1

readFunction · 0.64