Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
atlowChemi committed Aug 17, 2023
1 parent 0c3382e commit 60d7cf3
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/internal/fs/streams.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const {
ERR_INVALID_ARG_TYPE,
ERR_OUT_OF_RANGE,
ERR_METHOD_NOT_IMPLEMENTED,
ERR_SYSTEM_ERROR,
} = require('internal/errors').codes;
const {
deprecate,
Expand Down Expand Up @@ -409,8 +410,9 @@ function writeAll(data, size, pos, cb, retries = 0) {
size -= bytesWritten;
pos += bytesWritten;

// Try writing non-zero number of bytes up to 5 times.
if (retries > 5) {
cb(new Error('writev failed'));
cb(new ERR_SYSTEM_ERROR('write failed'));
} else if (size) {
writeAll(buffer.slice(bytesWritten), size, pos, cb, retries);
} else {
Expand All @@ -436,8 +438,9 @@ function writevAll(chunks, size, pos, cb, retries = 0) {
size -= bytesWritten;
pos += bytesWritten;

// Try writing non-zero number of bytes up to 5 times.
if (retries > 5) {
cb(new Error('writev failed'));
cb(new ERR_SYSTEM_ERROR('writev failed'));
} else if (size) {
writevAll([Buffer.concat(buffers).slice(bytesWritten)], size, pos, cb, retries);
} else {
Expand All @@ -448,7 +451,7 @@ function writevAll(chunks, size, pos, cb, retries = 0) {

WriteStream.prototype._write = function(data, encoding, cb) {
this[kIsPerformingIO] = true;
writeAll.call(this, data.length, data, this.pos, (er) => {
writeAll.call(this, data, data.length, this.pos, (er) => {
this[kIsPerformingIO] = false;
if (this.destroyed) {
// Tell ._destroy() that it's safe to close the fd now.
Expand Down Expand Up @@ -476,7 +479,7 @@ WriteStream.prototype._writev = function(data, cb) {
}

this[kIsPerformingIO] = true;
writevAll.call(this, size, chunks, this.pos, (er) => {
writevAll.call(this, chunks, size, this.pos, (er) => {
this[kIsPerformingIO] = false;
if (this.destroyed) {
// Tell ._destroy() that it's safe to close the fd now.
Expand Down

0 comments on commit 60d7cf3

Please sign in to comment.