@@ -83,7 +83,14 @@ const {
83
83
84
84
const { FSReqCallback } = binding ;
85
85
const { toPathIfFileURL } = require ( 'internal/url' ) ;
86
- const internalUtil = require ( 'internal/util' ) ;
86
+ const {
87
+ customPromisifyArgs : kCustomPromisifyArgsSymbol ,
88
+ deprecate,
89
+ kEmptyObject,
90
+ promisify : {
91
+ custom : kCustomPromisifiedSymbol ,
92
+ } ,
93
+ } = require ( 'internal/util' ) ;
87
94
const {
88
95
constants : {
89
96
kIoMaxLength,
@@ -164,7 +171,7 @@ const isWindows = process.platform === 'win32';
164
171
const isOSX = process . platform === 'darwin' ;
165
172
166
173
167
- const showStringCoercionDeprecation = internalUtil . deprecate (
174
+ const showStringCoercionDeprecation = deprecate (
168
175
( ) => { } ,
169
176
'Implicit coercion of objects with own toString property is deprecated.' ,
170
177
'DEP0162'
@@ -276,7 +283,7 @@ function exists(path, callback) {
276
283
}
277
284
}
278
285
279
- ObjectDefineProperty ( exists , internalUtil . promisify . custom , {
286
+ ObjectDefineProperty ( exists , kCustomPromisifiedSymbol , {
280
287
__proto__ : null ,
281
288
value : function exists ( path ) { // eslint-disable-line func-name-matching
282
289
return new Promise ( ( resolve ) => fs . exists ( path , resolve ) ) ;
@@ -623,7 +630,7 @@ function read(fd, buffer, offsetOrOptions, length, position, callback) {
623
630
if ( ! isArrayBufferView ( buffer ) ) {
624
631
// This is fs.read(fd, params, callback)
625
632
params = buffer ;
626
- ( { buffer = Buffer . alloc ( 16384 ) } = params ?? ObjectCreate ( null ) ) ;
633
+ ( { buffer = Buffer . alloc ( 16384 ) } = params ?? kEmptyObject ) ;
627
634
}
628
635
callback = offsetOrOptions ;
629
636
} else {
@@ -636,7 +643,7 @@ function read(fd, buffer, offsetOrOptions, length, position, callback) {
636
643
offset = 0 ,
637
644
length = buffer . byteLength - offset ,
638
645
position = null ,
639
- } = params ?? ObjectCreate ( null ) ) ;
646
+ } = params ?? kEmptyObject ) ;
640
647
}
641
648
642
649
validateBuffer ( buffer ) ;
@@ -679,7 +686,7 @@ function read(fd, buffer, offsetOrOptions, length, position, callback) {
679
686
binding . read ( fd , buffer , offset , length , position , req ) ;
680
687
}
681
688
682
- ObjectDefineProperty ( read , internalUtil . customPromisifyArgs ,
689
+ ObjectDefineProperty ( read , kCustomPromisifyArgsSymbol ,
683
690
{ __proto__ : null , value : [ 'bytesRead' , 'buffer' ] , enumerable : false } ) ;
684
691
685
692
/**
@@ -701,7 +708,7 @@ function readSync(fd, buffer, offset, length, position) {
701
708
702
709
if ( arguments . length <= 3 ) {
703
710
// Assume fs.readSync(fd, buffer, options)
704
- const options = offset || ObjectCreate ( null ) ;
711
+ const options = offset || kEmptyObject ;
705
712
706
713
( {
707
714
offset = 0 ,
@@ -772,7 +779,7 @@ function readv(fd, buffers, position, callback) {
772
779
return binding . readBuffers ( fd , buffers , position , req ) ;
773
780
}
774
781
775
- ObjectDefineProperty ( readv , internalUtil . customPromisifyArgs ,
782
+ ObjectDefineProperty ( readv , kCustomPromisifyArgsSymbol ,
776
783
{ __proto__ : null , value : [ 'bytesRead' , 'buffers' ] , enumerable : false } ) ;
777
784
778
785
/**
@@ -829,7 +836,7 @@ function write(fd, buffer, offsetOrOptions, length, position, callback) {
829
836
offset = 0 ,
830
837
length = buffer . byteLength - offset ,
831
838
position = null ,
832
- } = offsetOrOptions ?? ObjectCreate ( null ) ) ;
839
+ } = offsetOrOptions ?? kEmptyObject ) ;
833
840
}
834
841
835
842
if ( offset == null || typeof offset === 'function' ) {
@@ -872,7 +879,7 @@ function write(fd, buffer, offsetOrOptions, length, position, callback) {
872
879
return binding . writeString ( fd , str , offset , length , req ) ;
873
880
}
874
881
875
- ObjectDefineProperty ( write , internalUtil . customPromisifyArgs ,
882
+ ObjectDefineProperty ( write , kCustomPromisifyArgsSymbol ,
876
883
{ __proto__ : null , value : [ 'bytesWritten' , 'buffer' ] , enumerable : false } ) ;
877
884
878
885
/**
@@ -899,7 +906,7 @@ function writeSync(fd, buffer, offsetOrOptions, length, position) {
899
906
offset = 0 ,
900
907
length = buffer . byteLength - offset ,
901
908
position = null ,
902
- } = offsetOrOptions ?? ObjectCreate ( null ) ) ;
909
+ } = offsetOrOptions ?? kEmptyObject ) ;
903
910
}
904
911
if ( position === undefined )
905
912
position = null ;
@@ -962,7 +969,7 @@ function writev(fd, buffers, position, callback) {
962
969
return binding . writeBuffers ( fd , buffers , position , req ) ;
963
970
}
964
971
965
- ObjectDefineProperty ( writev , internalUtil . customPromisifyArgs , {
972
+ ObjectDefineProperty ( writev , kCustomPromisifyArgsSymbol , {
966
973
__proto__ : null ,
967
974
value : [ 'bytesWritten' , 'buffer' ] ,
968
975
enumerable : false
@@ -1405,7 +1412,7 @@ function mkdirSync(path, options) {
1405
1412
*/
1406
1413
function readdir ( path , options , callback ) {
1407
1414
callback = makeCallback ( typeof options === 'function' ? options : callback ) ;
1408
- options = getOptions ( options , { } ) ;
1415
+ options = getOptions ( options ) ;
1409
1416
path = getValidatedPath ( path ) ;
1410
1417
1411
1418
const req = new FSReqCallback ( ) ;
@@ -1434,7 +1441,7 @@ function readdir(path, options, callback) {
1434
1441
* @returns {string | Buffer[] | Dirent[] }
1435
1442
*/
1436
1443
function readdirSync ( path , options ) {
1437
- options = getOptions ( options , { } ) ;
1444
+ options = getOptions ( options ) ;
1438
1445
path = getValidatedPath ( path ) ;
1439
1446
const ctx = { path } ;
1440
1447
const result = binding . readdir ( pathModule . toNamespacedPath ( path ) ,
@@ -1458,7 +1465,7 @@ function readdirSync(path, options) {
1458
1465
function fstat ( fd , options = { bigint : false } , callback ) {
1459
1466
if ( typeof options === 'function' ) {
1460
1467
callback = options ;
1461
- options = { } ;
1468
+ options = kEmptyObject ;
1462
1469
}
1463
1470
fd = getValidatedFd ( fd ) ;
1464
1471
callback = makeStatsCallback ( callback ) ;
@@ -1482,7 +1489,7 @@ function fstat(fd, options = { bigint: false }, callback) {
1482
1489
function lstat ( path , options = { bigint : false } , callback ) {
1483
1490
if ( typeof options === 'function' ) {
1484
1491
callback = options ;
1485
- options = { } ;
1492
+ options = kEmptyObject ;
1486
1493
}
1487
1494
callback = makeStatsCallback ( callback ) ;
1488
1495
path = getValidatedPath ( path ) ;
@@ -1505,7 +1512,7 @@ function lstat(path, options = { bigint: false }, callback) {
1505
1512
function stat ( path , options = { bigint : false } , callback ) {
1506
1513
if ( typeof options === 'function' ) {
1507
1514
callback = options ;
1508
- options = { } ;
1515
+ options = kEmptyObject ;
1509
1516
}
1510
1517
callback = makeStatsCallback ( callback ) ;
1511
1518
path = getValidatedPath ( path ) ;
@@ -1603,7 +1610,7 @@ function statSync(path, options = { bigint: false, throwIfNoEntry: true }) {
1603
1610
*/
1604
1611
function readlink ( path , options , callback ) {
1605
1612
callback = makeCallback ( typeof options === 'function' ? options : callback ) ;
1606
- options = getOptions ( options , { } ) ;
1613
+ options = getOptions ( options ) ;
1607
1614
path = getValidatedPath ( path , 'oldPath' ) ;
1608
1615
const req = new FSReqCallback ( ) ;
1609
1616
req . oncomplete = callback ;
@@ -1618,7 +1625,7 @@ function readlink(path, options, callback) {
1618
1625
* @returns {string | Buffer }
1619
1626
*/
1620
1627
function readlinkSync ( path , options ) {
1621
- options = getOptions ( options , { } ) ;
1628
+ options = getOptions ( options ) ;
1622
1629
path = getValidatedPath ( path , 'oldPath' ) ;
1623
1630
const ctx = { path } ;
1624
1631
const result = binding . readlink ( pathModule . toNamespacedPath ( path ) ,
@@ -2295,7 +2302,7 @@ function watch(filename, options, listener) {
2295
2302
if ( typeof options === 'function' ) {
2296
2303
listener = options ;
2297
2304
}
2298
- options = getOptions ( options , { } ) ;
2305
+ options = getOptions ( options ) ;
2299
2306
2300
2307
// Don't make changes directly on options object
2301
2308
options = copyObject ( options ) ;
@@ -2458,16 +2465,14 @@ if (isWindows) {
2458
2465
} ;
2459
2466
}
2460
2467
2461
- const emptyObj = ObjectCreate ( null ) ;
2462
-
2463
2468
/**
2464
2469
* Returns the resolved pathname.
2465
2470
* @param {string | Buffer | URL } p
2466
2471
* @param {string | { encoding?: string | null; } } [options]
2467
2472
* @returns {string | Buffer }
2468
2473
*/
2469
2474
function realpathSync ( p , options ) {
2470
- options = getOptions ( options , emptyObj ) ;
2475
+ options = getOptions ( options ) ;
2471
2476
p = toPathIfFileURL ( p ) ;
2472
2477
if ( typeof p !== 'string' ) {
2473
2478
p += '' ;
@@ -2604,7 +2609,7 @@ function realpathSync(p, options) {
2604
2609
* @returns {string | Buffer }
2605
2610
*/
2606
2611
realpathSync . native = ( path , options ) => {
2607
- options = getOptions ( options , { } ) ;
2612
+ options = getOptions ( options ) ;
2608
2613
path = getValidatedPath ( path ) ;
2609
2614
const ctx = { path } ;
2610
2615
const result = binding . realpath ( path , options . encoding , undefined , ctx ) ;
@@ -2625,7 +2630,7 @@ realpathSync.native = (path, options) => {
2625
2630
*/
2626
2631
function realpath ( p , options , callback ) {
2627
2632
callback = typeof options === 'function' ? options : maybeCallback ( callback ) ;
2628
- options = getOptions ( options , { } ) ;
2633
+ options = getOptions ( options ) ;
2629
2634
p = toPathIfFileURL ( p ) ;
2630
2635
2631
2636
if ( typeof p !== 'string' ) {
@@ -2763,7 +2768,7 @@ function realpath(p, options, callback) {
2763
2768
*/
2764
2769
realpath . native = ( path , options , callback ) => {
2765
2770
callback = makeCallback ( callback || options ) ;
2766
- options = getOptions ( options , { } ) ;
2771
+ options = getOptions ( options ) ;
2767
2772
path = getValidatedPath ( path ) ;
2768
2773
const req = new FSReqCallback ( ) ;
2769
2774
req . oncomplete = callback ;
@@ -2782,7 +2787,7 @@ realpath.native = (path, options, callback) => {
2782
2787
*/
2783
2788
function mkdtemp ( prefix , options , callback ) {
2784
2789
callback = makeCallback ( typeof options === 'function' ? options : callback ) ;
2785
- options = getOptions ( options , { } ) ;
2790
+ options = getOptions ( options ) ;
2786
2791
2787
2792
validateString ( prefix , 'prefix' ) ;
2788
2793
nullCheck ( prefix , 'prefix' ) ;
@@ -2799,7 +2804,7 @@ function mkdtemp(prefix, options, callback) {
2799
2804
* @returns {string }
2800
2805
*/
2801
2806
function mkdtempSync ( prefix , options ) {
2802
- options = getOptions ( options , { } ) ;
2807
+ options = getOptions ( options ) ;
2803
2808
2804
2809
validateString ( prefix , 'prefix' ) ;
2805
2810
nullCheck ( prefix , 'prefix' ) ;
0 commit comments