(fd, isUserFd, buffer, byteLengthName)
| 483 | } |
| 484 | |
| 485 | function 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. |
no test coverage detected
searching dependent graphs…