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

Function tryReadSyncWithUserBuffer

lib/fs.js:485–513  ·  view source on GitHub ↗
(fd, isUserFd, buffer, byteLengthName)

Source from the content-addressed store, hash-verified

483}
484
485function tryReadSyncWithUserBuffer(fd, isUserFd, buffer, byteLengthName) {
486 let pos = 0;
487 let bytesRead = 0;
488
489 while (pos < buffer.byteLength) {
490 bytesRead = tryReadSync(fd, isUserFd, buffer, pos, buffer.byteLength - pos);
491 pos += bytesRead;
492
493 if (bytesRead === 0) {
494 return pos;
495 }
496 }
497
498 const extraBuffer = tryCreateBuffer(1, fd, isUserFd);
499 bytesRead = tryReadSync(fd, isUserFd, extraBuffer, 0, 1);
500
501 if (bytesRead !== 0) {
502 if (!isUserFd) {
503 fs.closeSync(fd);
504 }
505 throw new ERR_INVALID_ARG_VALUE(
506 byteLengthName,
507 buffer.byteLength,
508 'is too small to contain the entire file',
509 );
510 }
511
512 return pos;
513}
514
515/**
516 * Synchronously reads the entire contents of a file.

Callers 1

readFileSyncFunction · 0.85

Calls 3

tryReadSyncFunction · 0.85
tryCreateBufferFunction · 0.85
closeSyncMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…