MCPcopy Create free account
hub / github.com/denoland/std / readFromSync

Method readFromSync

io/buffer.ts:474–496  ·  view source on GitHub ↗

Reads data from `r` until EOF (`null`) and appends it to the buffer, * growing the buffer as needed. It returns the number of bytes read. If the * buffer becomes too large, `.readFromSync()` will throw an error. * * Based on Go Lang's * {@link https://golang.org/pkg/bytes/#Buffer.Read

(r: ReaderSync)

Source from the content-addressed store, hash-verified

472 * @returns The number of bytes read.
473 */
474 readFromSync(r: ReaderSync): number {
475 let n = 0;
476 const tmp = new Uint8Array(MIN_READ);
477 while (true) {
478 const shouldGrow = this.capacity - this.length < MIN_READ;
479 // read into tmp buffer if there's not enough room
480 // otherwise read directly into the internal buffer
481 const buf = shouldGrow
482 ? tmp
483 : new Uint8Array(this.#buf.buffer, this.length);
484
485 const nread = r.readSync(buf);
486 if (nread === null) {
487 return n;
488 }
489
490 // write will grow if needed
491 if (shouldGrow) this.writeSync(buf.subarray(0, nread));
492 else this.#reslice(this.length + nread);
493
494 n += nread;
495 }
496 }
497}

Callers 2

fnFunction · 0.95
buffer_test.tsFile · 0.80

Calls 3

writeSyncMethod · 0.95
#resliceMethod · 0.95
readSyncMethod · 0.65

Tested by

no test coverage detected