| 410 | WriteStream.prototype._construct = _construct; |
| 411 | |
| 412 | function writeAll(data, size, pos, cb, retries = 0) { |
| 413 | this[kFs].write(this.fd, data, 0, size, pos, (er, bytesWritten, buffer) => { |
| 414 | // No data currently available and operation should be retried later. |
| 415 | if (er?.code === 'EAGAIN') { |
| 416 | er = null; |
| 417 | bytesWritten = 0; |
| 418 | } |
| 419 | |
| 420 | if (this.destroyed || er) { |
| 421 | return cb(er || new ERR_STREAM_DESTROYED('write')); |
| 422 | } |
| 423 | |
| 424 | this.bytesWritten += bytesWritten; |
| 425 | |
| 426 | retries = bytesWritten ? 0 : retries + 1; |
| 427 | size -= bytesWritten; |
| 428 | pos += bytesWritten; |
| 429 | |
| 430 | // Try writing non-zero number of bytes up to 5 times. |
| 431 | if (retries > 5) { |
| 432 | cb(new ERR_SYSTEM_ERROR('write failed')); |
| 433 | } else if (size) { |
| 434 | writeAll.call(this, buffer.slice(bytesWritten), size, pos, cb, retries); |
| 435 | } else { |
| 436 | cb(); |
| 437 | } |
| 438 | }); |
| 439 | } |
| 440 | |
| 441 | function writevAll(chunks, size, pos, cb, retries = 0) { |
| 442 | this[kFs].writev(this.fd, chunks, this.pos, (er, bytesWritten, buffers) => { |