@@ -15,6 +15,7 @@ const {
15
15
ERR_INVALID_ARG_TYPE ,
16
16
ERR_OUT_OF_RANGE ,
17
17
ERR_METHOD_NOT_IMPLEMENTED ,
18
+ ERR_SYSTEM_ERROR ,
18
19
} = require ( 'internal/errors' ) . codes ;
19
20
const {
20
21
deprecate,
@@ -409,8 +410,9 @@ function writeAll(data, size, pos, cb, retries = 0) {
409
410
size -= bytesWritten ;
410
411
pos += bytesWritten ;
411
412
413
+ // Try writing non-zero number of bytes up to 5 times.
412
414
if ( retries > 5 ) {
413
- cb ( new Error ( 'writev failed') ) ;
415
+ cb ( new ERR_SYSTEM_ERROR ( 'write failed') ) ;
414
416
} else if ( size ) {
415
417
writeAll ( buffer . slice ( bytesWritten ) , size , pos , cb , retries ) ;
416
418
} else {
@@ -436,8 +438,9 @@ function writevAll(chunks, size, pos, cb, retries = 0) {
436
438
size -= bytesWritten ;
437
439
pos += bytesWritten ;
438
440
441
+ // Try writing non-zero number of bytes up to 5 times.
439
442
if ( retries > 5 ) {
440
- cb ( new Error ( 'writev failed' ) ) ;
443
+ cb ( new ERR_SYSTEM_ERROR ( 'writev failed' ) ) ;
441
444
} else if ( size ) {
442
445
writevAll ( [ Buffer . concat ( buffers ) . slice ( bytesWritten ) ] , size , pos , cb , retries ) ;
443
446
} else {
@@ -448,7 +451,7 @@ function writevAll(chunks, size, pos, cb, retries = 0) {
448
451
449
452
WriteStream . prototype . _write = function ( data , encoding , cb ) {
450
453
this [ kIsPerformingIO ] = true ;
451
- writeAll . call ( this , data . length , data , this . pos , ( er ) => {
454
+ writeAll . call ( this , data , data . length , this . pos , ( er ) => {
452
455
this [ kIsPerformingIO ] = false ;
453
456
if ( this . destroyed ) {
454
457
// Tell ._destroy() that it's safe to close the fd now.
@@ -476,7 +479,7 @@ WriteStream.prototype._writev = function(data, cb) {
476
479
}
477
480
478
481
this [ kIsPerformingIO ] = true ;
479
- writevAll . call ( this , size , chunks , this . pos , ( er ) => {
482
+ writevAll . call ( this , chunks , size , this . pos , ( er ) => {
480
483
this [ kIsPerformingIO ] = false ;
481
484
if ( this . destroyed ) {
482
485
// Tell ._destroy() that it's safe to close the fd now.
0 commit comments