66const constants = process . binding ( 'constants' ) . fs ;
77const util = require ( 'util' ) ;
88const pathModule = require ( 'path' ) ;
9+ const { isUint8Array } = process . binding ( 'util' ) ;
910
1011const binding = process . binding ( 'fs' ) ;
1112const fs = exports ;
@@ -559,7 +560,7 @@ fs.openSync = function(path, flags, mode) {
559560
560561var readWarned = false ;
561562fs . read = function ( fd , buffer , offset , length , position , callback ) {
562- if ( ! ( buffer instanceof Buffer ) ) {
563+ if ( ! isUint8Array ( buffer ) ) {
563564 // legacy string interface (fd, length, position, encoding, callback)
564565 if ( ! readWarned ) {
565566 readWarned = true ;
@@ -623,7 +624,7 @@ fs.readSync = function(fd, buffer, offset, length, position) {
623624 var legacy = false ;
624625 var encoding ;
625626
626- if ( ! ( buffer instanceof Buffer ) ) {
627+ if ( ! isUint8Array ( buffer ) ) {
627628 // legacy string interface (fd, length, position, encoding, callback)
628629 if ( ! readSyncWarned ) {
629630 readSyncWarned = true ;
@@ -674,7 +675,7 @@ fs.write = function(fd, buffer, offset, length, position, callback) {
674675 var req = new FSReqWrap ( ) ;
675676 req . oncomplete = wrapper ;
676677
677- if ( buffer instanceof Buffer ) {
678+ if ( isUint8Array ( buffer ) ) {
678679 callback = maybeCallback ( callback || position || length || offset ) ;
679680 if ( typeof offset !== 'number' ) {
680681 offset = 0 ;
@@ -708,7 +709,7 @@ fs.write = function(fd, buffer, offset, length, position, callback) {
708709// OR
709710// fs.writeSync(fd, string[, position[, encoding]]);
710711fs . writeSync = function ( fd , buffer , offset , length , position ) {
711- if ( buffer instanceof Buffer ) {
712+ if ( isUint8Array ( buffer ) ) {
712713 if ( position === undefined )
713714 position = null ;
714715 if ( typeof offset !== 'number' )
@@ -1206,7 +1207,7 @@ fs.writeFile = function(path, data, options, callback) {
12061207 } ) ;
12071208
12081209 function writeFd ( fd , isUserFd ) {
1209- var buffer = ( data instanceof Buffer ) ?
1210+ var buffer = isUint8Array ( data ) ?
12101211 data : Buffer . from ( '' + data , options . encoding || 'utf8' ) ;
12111212 var position = / a / . test ( flag ) ? null : 0 ;
12121213
@@ -1221,7 +1222,7 @@ fs.writeFileSync = function(path, data, options) {
12211222 var isUserFd = isFd ( path ) ; // file descriptor ownership
12221223 var fd = isUserFd ? path : fs . openSync ( path , flag , options . mode ) ;
12231224
1224- if ( ! ( data instanceof Buffer ) ) {
1225+ if ( ! isUint8Array ( data ) ) {
12251226 data = Buffer . from ( '' + data , options . encoding || 'utf8' ) ;
12261227 }
12271228 var offset = 0 ;
0 commit comments