MCPcopy Index your code
hub / github.com/nodejs/node / readSync

Method readSync

lib/internal/vfs/file_handle.js:464–487  ·  view source on GitHub ↗

* Reads data from the file synchronously. * @param {Buffer} buffer The buffer to read into * @param {number} offset The offset in the buffer to start writing * @param {number} length The number of bytes to read * @param {number|null} position The position to read from (null uses current

(buffer, offset, length, position)

Source from the content-addressed store, hash-verified

462 * @returns {number} The number of bytes read
463 */
464 readSync(buffer, offset, length, position) {
465 this.#checkClosed('read');
466 this.#checkReadable();
467
468 // Get content (resolves dynamic content providers)
469 const content = this.content;
470 const readPos = position !== null && position !== undefined ?
471 Number(position) : this.position;
472 const available = content.length - readPos;
473
474 if (available <= 0) {
475 return 0;
476 }
477
478 const bytesToRead = MathMin(length, available);
479 content.copy(buffer, offset, readPos, readPos + bytesToRead);
480
481 // Update position if not using explicit position
482 if (position === null || position === undefined) {
483 this.position = readPos + bytesToRead;
484 }
485
486 return bytesToRead;
487 }
488
489 /**
490 * Reads data from the file.

Callers 1

readMethod · 0.95

Calls 3

#checkClosedMethod · 0.95
#checkReadableMethod · 0.95
copyMethod · 0.65

Tested by

no test coverage detected