@@ -41,7 +41,7 @@ const {
4141
4242const { _extend } = require ( 'util' ) ;
4343const pathModule = require ( 'path' ) ;
44- const { isUint8Array } = require ( 'internal/util/types' ) ;
44+ const { isArrayBufferView } = require ( 'internal/util/types' ) ;
4545const binding = process . binding ( 'fs' ) ;
4646const { Buffer, kMaxLength } = require ( 'buffer' ) ;
4747const errors = require ( 'internal/errors' ) ;
@@ -450,7 +450,7 @@ function read(fd, buffer, offset, length, position, callback) {
450450 } ) ;
451451 }
452452
453- validateOffsetLengthRead ( offset , length , buffer . length ) ;
453+ validateOffsetLengthRead ( offset , length , buffer . byteLength ) ;
454454
455455 if ( ! Number . isSafeInteger ( position ) )
456456 position = - 1 ;
@@ -480,7 +480,7 @@ function readSync(fd, buffer, offset, length, position) {
480480 return 0 ;
481481 }
482482
483- validateOffsetLengthRead ( offset , length , buffer . length ) ;
483+ validateOffsetLengthRead ( offset , length , buffer . byteLength ) ;
484484
485485 if ( ! Number . isSafeInteger ( position ) )
486486 position = - 1 ;
@@ -507,7 +507,7 @@ function write(fd, buffer, offset, length, position, callback) {
507507 const req = new FSReqWrap ( ) ;
508508 req . oncomplete = wrapper ;
509509
510- if ( isUint8Array ( buffer ) ) {
510+ if ( isArrayBufferView ( buffer ) ) {
511511 callback = maybeCallback ( callback || position || length || offset ) ;
512512 if ( typeof offset !== 'number' )
513513 offset = 0 ;
@@ -545,13 +545,13 @@ function writeSync(fd, buffer, offset, length, position) {
545545 validateUint32 ( fd , 'fd' ) ;
546546 const ctx = { } ;
547547 let result ;
548- if ( isUint8Array ( buffer ) ) {
548+ if ( isArrayBufferView ( buffer ) ) {
549549 if ( position === undefined )
550550 position = null ;
551551 if ( typeof offset !== 'number' )
552552 offset = 0 ;
553553 if ( typeof length !== 'number' )
554- length = buffer . length - offset ;
554+ length = buffer . byteLength - offset ;
555555 validateOffsetLengthWrite ( offset , length , buffer . byteLength ) ;
556556 result = binding . writeBuffer ( fd , buffer , offset , length , position ,
557557 undefined , ctx ) ;
@@ -1171,11 +1171,11 @@ function writeFile(path, data, options, callback) {
11711171 } ) ;
11721172
11731173 function writeFd ( fd , isUserFd ) {
1174- const buffer = isUint8Array ( data ) ?
1174+ const buffer = isArrayBufferView ( data ) ?
11751175 data : Buffer . from ( '' + data , options . encoding || 'utf8' ) ;
11761176 const position = / a / . test ( flag ) ? null : 0 ;
11771177
1178- writeAll ( fd , isUserFd , buffer , 0 , buffer . length , position , callback ) ;
1178+ writeAll ( fd , isUserFd , buffer , 0 , buffer . byteLength , position , callback ) ;
11791179 }
11801180}
11811181
@@ -1186,11 +1186,11 @@ function writeFileSync(path, data, options) {
11861186 const isUserFd = isFd ( path ) ; // file descriptor ownership
11871187 const fd = isUserFd ? path : fs . openSync ( path , flag , options . mode ) ;
11881188
1189- if ( ! isUint8Array ( data ) ) {
1189+ if ( ! isArrayBufferView ( data ) ) {
11901190 data = Buffer . from ( '' + data , options . encoding || 'utf8' ) ;
11911191 }
11921192 let offset = 0 ;
1193- let length = data . length ;
1193+ let length = data . byteLength ;
11941194 let position = / a / . test ( flag ) ? null : 0 ;
11951195 try {
11961196 while ( length > 0 ) {
0 commit comments