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

Function writeAll

lib/internal/fs/promises.js:763–793  ·  view source on GitHub ↗
(buf, offset, length, position, signal)

Source from the content-addressed store, hash-verified

761
762 // Write a single buffer with EAGAIN retry (up to 5 retries).
763 async function writeAll(buf, offset, length, position, signal) {
764 asyncPending = true;
765 try {
766 let retries = 0;
767 while (length > 0) {
768 const bytesWritten = (await PromisePrototypeThen(
769 binding.writeBuffer(fd, buf, offset, length, position,
770 kUsePromises),
771 undefined,
772 handleErrorFromBinding,
773 )) || 0;
774
775 signal?.throwIfAborted();
776
777 if (bytesWritten === 0) {
778 if (++retries > 5) {
779 throw new ERR_OPERATION_FAILED('write failed after retries');
780 }
781 } else {
782 retries = 0;
783 }
784
785 totalBytesWritten += bytesWritten;
786 offset += bytesWritten;
787 length -= bytesWritten;
788 if (position >= 0) position += bytesWritten;
789 }
790 } finally {
791 asyncPending = false;
792 }
793 }
794
795 // Writev with EAGAIN retry. On partial write, concatenates remaining
796 // buffers and falls back to writeAll (same approach as WriteStream).

Callers 2

writevAllFunction · 0.70
writeFunction · 0.70

Calls 1

throwIfAbortedMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…