@@ -903,17 +903,32 @@ fs.mkdirSync = function(path, mode) {
903
903
modeNum ( mode , 0o777 ) ) ;
904
904
} ;
905
905
906
- fs . readdir = function ( path , callback ) {
906
+ fs . readdir = function ( path , options , callback ) {
907
+ options = options || { } ;
908
+ if ( typeof options === 'function' ) {
909
+ callback = options ;
910
+ options = { } ;
911
+ } else if ( typeof options === 'string' ) {
912
+ options = { encoding : options } ;
913
+ }
914
+ if ( typeof options !== 'object' )
915
+ throw new TypeError ( '"options" must be a string or an object' ) ;
916
+
907
917
callback = makeCallback ( callback ) ;
908
918
if ( ! nullCheck ( path , callback ) ) return ;
909
919
var req = new FSReqWrap ( ) ;
910
920
req . oncomplete = callback ;
911
- binding . readdir ( pathModule . _makeLong ( path ) , req ) ;
921
+ binding . readdir ( pathModule . _makeLong ( path ) , options . encoding , req ) ;
912
922
} ;
913
923
914
- fs . readdirSync = function ( path ) {
924
+ fs . readdirSync = function ( path , options ) {
925
+ options = options || { } ;
926
+ if ( typeof options === 'string' )
927
+ options = { encoding : options } ;
928
+ if ( typeof options !== 'object' )
929
+ throw new TypeError ( '"options" must be a string or an object' ) ;
915
930
nullCheck ( path ) ;
916
- return binding . readdir ( pathModule . _makeLong ( path ) ) ;
931
+ return binding . readdir ( pathModule . _makeLong ( path ) , options . encoding ) ;
917
932
} ;
918
933
919
934
fs . fstat = function ( fd , callback ) {
@@ -952,17 +967,31 @@ fs.statSync = function(path) {
952
967
return binding . stat ( pathModule . _makeLong ( path ) ) ;
953
968
} ;
954
969
955
- fs . readlink = function ( path , callback ) {
970
+ fs . readlink = function ( path , options , callback ) {
971
+ options = options || { } ;
972
+ if ( typeof options === 'function' ) {
973
+ callback = options ;
974
+ options = { } ;
975
+ } else if ( typeof options === 'string' ) {
976
+ options = { encoding : options } ;
977
+ }
978
+ if ( typeof options !== 'object' )
979
+ throw new TypeError ( '"options" must be a string or an object' ) ;
956
980
callback = makeCallback ( callback ) ;
957
981
if ( ! nullCheck ( path , callback ) ) return ;
958
982
var req = new FSReqWrap ( ) ;
959
983
req . oncomplete = callback ;
960
- binding . readlink ( pathModule . _makeLong ( path ) , req ) ;
984
+ binding . readlink ( pathModule . _makeLong ( path ) , options . encoding , req ) ;
961
985
} ;
962
986
963
- fs . readlinkSync = function ( path ) {
987
+ fs . readlinkSync = function ( path , options ) {
988
+ options = options || { } ;
989
+ if ( typeof options === 'string' )
990
+ options = { encoding : options } ;
991
+ if ( typeof options !== 'object' )
992
+ throw new TypeError ( '"options" must be a string or an object' ) ;
964
993
nullCheck ( path ) ;
965
- return binding . readlink ( pathModule . _makeLong ( path ) ) ;
994
+ return binding . readlink ( pathModule . _makeLong ( path ) , options . encoding ) ;
966
995
} ;
967
996
968
997
function preprocessSymlinkDestination ( path , type , linkPath ) {
@@ -1363,11 +1392,15 @@ function FSWatcher() {
1363
1392
}
1364
1393
util . inherits ( FSWatcher , EventEmitter ) ;
1365
1394
1366
- FSWatcher . prototype . start = function ( filename , persistent , recursive ) {
1395
+ FSWatcher . prototype . start = function ( filename ,
1396
+ persistent ,
1397
+ recursive ,
1398
+ encoding ) {
1367
1399
nullCheck ( filename ) ;
1368
1400
var err = this . _handle . start ( pathModule . _makeLong ( filename ) ,
1369
1401
persistent ,
1370
- recursive ) ;
1402
+ recursive ,
1403
+ encoding ) ;
1371
1404
if ( err ) {
1372
1405
this . _handle . close ( ) ;
1373
1406
const error = errnoException ( err , `watch ${ filename } ` ) ;
@@ -1380,25 +1413,27 @@ FSWatcher.prototype.close = function() {
1380
1413
this . _handle . close ( ) ;
1381
1414
} ;
1382
1415
1383
- fs . watch = function ( filename ) {
1416
+ fs . watch = function ( filename , options , listener ) {
1384
1417
nullCheck ( filename ) ;
1385
- var watcher ;
1386
- var options ;
1387
- var listener ;
1388
1418
1389
- if ( arguments [ 1 ] !== null && typeof arguments [ 1 ] === 'object' ) {
1390
- options = arguments [ 1 ] ;
1391
- listener = arguments [ 2 ] ;
1392
- } else {
1419
+ options = options || { } ;
1420
+ if ( typeof options === 'function' ) {
1421
+ listener = options ;
1393
1422
options = { } ;
1394
- listener = arguments [ 1 ] ;
1423
+ } else if ( typeof options === 'string' ) {
1424
+ options = { encoding : options } ;
1395
1425
}
1426
+ if ( typeof options !== 'object' )
1427
+ throw new TypeError ( '"options" must be a string or an object' ) ;
1396
1428
1397
1429
if ( options . persistent === undefined ) options . persistent = true ;
1398
1430
if ( options . recursive === undefined ) options . recursive = false ;
1399
1431
1400
- watcher = new FSWatcher ( ) ;
1401
- watcher . start ( filename , options . persistent , options . recursive ) ;
1432
+ const watcher = new FSWatcher ( ) ;
1433
+ watcher . start ( filename ,
1434
+ options . persistent ,
1435
+ options . recursive ,
1436
+ options . encoding ) ;
1402
1437
1403
1438
if ( listener ) {
1404
1439
watcher . addListener ( 'change' , listener ) ;
@@ -2139,10 +2174,19 @@ SyncWriteStream.prototype.destroy = function() {
2139
2174
2140
2175
SyncWriteStream . prototype . destroySoon = SyncWriteStream . prototype . destroy ;
2141
2176
2142
- fs . mkdtemp = function ( prefix , callback ) {
2143
- if ( typeof callback !== 'function' ) {
2144
- throw new TypeError ( '"callback" argument must be a function' ) ;
2177
+ fs . mkdtemp = function ( prefix , options , callback ) {
2178
+ if ( ! prefix || typeof prefix !== 'string' )
2179
+ throw new TypeError ( 'filename prefix is required' ) ;
2180
+
2181
+ options = options || { } ;
2182
+ if ( typeof options === 'function' ) {
2183
+ callback = options ;
2184
+ options = { } ;
2185
+ } else if ( typeof options === 'string' ) {
2186
+ options = { encoding : options } ;
2145
2187
}
2188
+ if ( typeof options !== 'object' )
2189
+ throw new TypeError ( '"options" must be a string or an object' ) ;
2146
2190
2147
2191
if ( ! nullCheck ( prefix , callback ) ) {
2148
2192
return ;
@@ -2151,11 +2195,19 @@ fs.mkdtemp = function(prefix, callback) {
2151
2195
var req = new FSReqWrap ( ) ;
2152
2196
req . oncomplete = callback ;
2153
2197
2154
- binding . mkdtemp ( prefix + 'XXXXXX' , req ) ;
2198
+ binding . mkdtemp ( prefix + 'XXXXXX' , options . encoding , req ) ;
2155
2199
} ;
2156
2200
2157
- fs . mkdtempSync = function ( prefix ) {
2201
+ fs . mkdtempSync = function ( prefix , options ) {
2202
+ if ( ! prefix || typeof prefix !== 'string' )
2203
+ throw new TypeError ( 'filename prefix is required' ) ;
2204
+
2205
+ options = options || { } ;
2206
+ if ( typeof options === 'string' )
2207
+ options = { encoding : options } ;
2208
+ if ( typeof options !== 'object' )
2209
+ throw new TypeError ( '"options" must be a string or an object' ) ;
2158
2210
nullCheck ( prefix ) ;
2159
2211
2160
- return binding . mkdtemp ( prefix + 'XXXXXX' ) ;
2212
+ return binding . mkdtemp ( prefix + 'XXXXXX' , options . encoding ) ;
2161
2213
} ;
0 commit comments