bare-fs 1.13.3 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/binding.js +1 -1
- package/index.js +213 -184
- package/package.json +9 -3
package/README.md
CHANGED
|
@@ -17,6 +17,7 @@ fs.access
|
|
|
17
17
|
fs.chmod
|
|
18
18
|
fs.close
|
|
19
19
|
fs.chmod
|
|
20
|
+
fs.exists
|
|
20
21
|
fs.fstat
|
|
21
22
|
fs.ftruncate
|
|
22
23
|
fs.lstat
|
|
@@ -63,6 +64,7 @@ fs.createWriteStream
|
|
|
63
64
|
fs.accessSync
|
|
64
65
|
fs.chmodSync
|
|
65
66
|
fs.closeSync
|
|
67
|
+
fs.existsSync
|
|
66
68
|
fs.fchmodSync
|
|
67
69
|
fs.fstatSync
|
|
68
70
|
fs.lstatSync
|
package/binding.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
module.exports =
|
|
1
|
+
module.exports = require.addon()
|
package/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
1
|
+
/* global Bare */
|
|
2
|
+
const EventEmitter = require('bare-events')
|
|
3
|
+
const os = require('bare-os')
|
|
4
|
+
const path = require('bare-path')
|
|
3
5
|
const { Readable, Writable } = require('streamx')
|
|
4
6
|
const binding = require('./binding')
|
|
5
7
|
|
|
6
|
-
const isWindows =
|
|
8
|
+
const isWindows = os.platform() === 'win32'
|
|
7
9
|
|
|
8
10
|
const constants = exports.constants = {
|
|
9
11
|
O_RDWR: binding.O_RDWR,
|
|
@@ -59,7 +61,7 @@ const fs = {
|
|
|
59
61
|
|
|
60
62
|
binding.init(fs.handle, fs, onresponse)
|
|
61
63
|
|
|
62
|
-
|
|
64
|
+
Bare.on('exit', () => binding.destroy(fs.handle))
|
|
63
65
|
|
|
64
66
|
// Lightly-modified from the Node FS internal utils.
|
|
65
67
|
function flagsToNumber (flags) {
|
|
@@ -143,9 +145,9 @@ function onresponse (id, err, result) {
|
|
|
143
145
|
callback(err, result)
|
|
144
146
|
}
|
|
145
147
|
|
|
146
|
-
function open (
|
|
147
|
-
if (typeof
|
|
148
|
-
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof
|
|
148
|
+
function open (filepath, flags, mode, cb) {
|
|
149
|
+
if (typeof filepath !== 'string') {
|
|
150
|
+
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
|
|
149
151
|
}
|
|
150
152
|
|
|
151
153
|
if (typeof cb !== 'function') {
|
|
@@ -166,18 +168,18 @@ function open (path, flags, mode, cb) {
|
|
|
166
168
|
|
|
167
169
|
const req = getReq()
|
|
168
170
|
req.callback = cb
|
|
169
|
-
binding.open(req.handle,
|
|
171
|
+
binding.open(req.handle, filepath, flags, mode)
|
|
170
172
|
}
|
|
171
173
|
|
|
172
|
-
function openSync (
|
|
173
|
-
if (typeof
|
|
174
|
-
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof
|
|
174
|
+
function openSync (filepath, flags = 'r', mode = 0o666) {
|
|
175
|
+
if (typeof filepath !== 'string') {
|
|
176
|
+
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
|
|
175
177
|
}
|
|
176
178
|
|
|
177
179
|
if (typeof flags === 'string') flags = flagsToNumber(flags)
|
|
178
180
|
if (typeof mode === 'string') mode = modeToNumber(mode)
|
|
179
181
|
|
|
180
|
-
return binding.openSync(
|
|
182
|
+
return binding.openSync(filepath, flags, mode)
|
|
181
183
|
}
|
|
182
184
|
|
|
183
185
|
function close (fd, cb = noop) {
|
|
@@ -210,9 +212,9 @@ function closeSync (fd) {
|
|
|
210
212
|
return binding.closeSync(fd)
|
|
211
213
|
}
|
|
212
214
|
|
|
213
|
-
function access (
|
|
214
|
-
if (typeof
|
|
215
|
-
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof
|
|
215
|
+
function access (filepath, mode, cb) {
|
|
216
|
+
if (typeof filepath !== 'string') {
|
|
217
|
+
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
|
|
216
218
|
}
|
|
217
219
|
|
|
218
220
|
if (typeof cb !== 'function') {
|
|
@@ -226,15 +228,40 @@ function access (path, mode, cb) {
|
|
|
226
228
|
|
|
227
229
|
const req = getReq()
|
|
228
230
|
req.callback = cb
|
|
229
|
-
binding.access(req.handle,
|
|
231
|
+
binding.access(req.handle, filepath, mode)
|
|
230
232
|
}
|
|
231
233
|
|
|
232
|
-
function accessSync (
|
|
233
|
-
if (typeof
|
|
234
|
-
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof
|
|
234
|
+
function accessSync (filepath, mode = constants.F_OK) {
|
|
235
|
+
if (typeof filepath !== 'string') {
|
|
236
|
+
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
|
|
235
237
|
}
|
|
236
238
|
|
|
237
|
-
binding.accessSync(
|
|
239
|
+
binding.accessSync(filepath, mode)
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function exists (filepath, cb) {
|
|
243
|
+
if (typeof filepath !== 'string') {
|
|
244
|
+
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
if (typeof cb !== 'function') {
|
|
248
|
+
throw typeError('ERR_INVALID_ARG_TYPE', 'Callback must be a function. Received type ' + (typeof cb) + ' (' + cb + ')')
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
return access(filepath, (err) => cb(!!err)) // eslint-disable-line n/no-callback-literal
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function existsSync (filepath) {
|
|
255
|
+
if (typeof filepath !== 'string') {
|
|
256
|
+
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
try {
|
|
260
|
+
accessSync(filepath)
|
|
261
|
+
return true
|
|
262
|
+
} catch {
|
|
263
|
+
return false
|
|
264
|
+
}
|
|
238
265
|
}
|
|
239
266
|
|
|
240
267
|
function read (fd, buffer, offset, len, pos, cb) {
|
|
@@ -391,9 +418,9 @@ function writev (fd, buffers, pos, cb) {
|
|
|
391
418
|
binding.writev(req.handle, fd, buffers, pos)
|
|
392
419
|
}
|
|
393
420
|
|
|
394
|
-
function stat (
|
|
395
|
-
if (typeof
|
|
396
|
-
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof
|
|
421
|
+
function stat (filepath, cb) {
|
|
422
|
+
if (typeof filepath !== 'string') {
|
|
423
|
+
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
|
|
397
424
|
}
|
|
398
425
|
|
|
399
426
|
if (typeof cb !== 'function') {
|
|
@@ -409,20 +436,20 @@ function stat (path, cb) {
|
|
|
409
436
|
else cb(null, new Stats(...data))
|
|
410
437
|
}
|
|
411
438
|
|
|
412
|
-
binding.stat(req.handle,
|
|
439
|
+
binding.stat(req.handle, filepath, data)
|
|
413
440
|
}
|
|
414
441
|
|
|
415
|
-
function statSync (
|
|
416
|
-
if (typeof
|
|
417
|
-
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof
|
|
442
|
+
function statSync (filepath) {
|
|
443
|
+
if (typeof filepath !== 'string') {
|
|
444
|
+
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
|
|
418
445
|
}
|
|
419
446
|
|
|
420
|
-
return new Stats(...binding.statSync(
|
|
447
|
+
return new Stats(...binding.statSync(filepath))
|
|
421
448
|
}
|
|
422
449
|
|
|
423
|
-
function lstat (
|
|
424
|
-
if (typeof
|
|
425
|
-
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof
|
|
450
|
+
function lstat (filepath, cb) {
|
|
451
|
+
if (typeof filepath !== 'string') {
|
|
452
|
+
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
|
|
426
453
|
}
|
|
427
454
|
|
|
428
455
|
if (typeof cb !== 'function') {
|
|
@@ -438,15 +465,15 @@ function lstat (path, cb) {
|
|
|
438
465
|
else cb(null, new Stats(...data))
|
|
439
466
|
}
|
|
440
467
|
|
|
441
|
-
binding.lstat(req.handle,
|
|
468
|
+
binding.lstat(req.handle, filepath, data)
|
|
442
469
|
}
|
|
443
470
|
|
|
444
|
-
function lstatSync (
|
|
445
|
-
if (typeof
|
|
446
|
-
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof
|
|
471
|
+
function lstatSync (filepath) {
|
|
472
|
+
if (typeof filepath !== 'string') {
|
|
473
|
+
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
|
|
447
474
|
}
|
|
448
475
|
|
|
449
|
-
return new Stats(...binding.lstatSync(
|
|
476
|
+
return new Stats(...binding.lstatSync(filepath))
|
|
450
477
|
}
|
|
451
478
|
|
|
452
479
|
function fstat (fd, cb) {
|
|
@@ -507,26 +534,26 @@ function ftruncate (fd, len, cb) {
|
|
|
507
534
|
binding.ftruncate(req.handle, fd, len)
|
|
508
535
|
}
|
|
509
536
|
|
|
510
|
-
function chmod (
|
|
511
|
-
if (typeof
|
|
512
|
-
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof
|
|
537
|
+
function chmod (filepath, mode, cb) {
|
|
538
|
+
if (typeof filepath !== 'string') {
|
|
539
|
+
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
|
|
513
540
|
}
|
|
514
541
|
|
|
515
542
|
if (typeof mode === 'string') mode = modeToNumber(mode)
|
|
516
543
|
|
|
517
544
|
const req = getReq()
|
|
518
545
|
req.callback = cb
|
|
519
|
-
binding.chmod(req.handle,
|
|
546
|
+
binding.chmod(req.handle, filepath, mode)
|
|
520
547
|
}
|
|
521
548
|
|
|
522
|
-
function chmodSync (
|
|
523
|
-
if (typeof
|
|
524
|
-
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof
|
|
549
|
+
function chmodSync (filepath, mode) {
|
|
550
|
+
if (typeof filepath !== 'string') {
|
|
551
|
+
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
|
|
525
552
|
}
|
|
526
553
|
|
|
527
554
|
if (typeof mode === 'string') mode = modeToNumber(mode)
|
|
528
555
|
|
|
529
|
-
binding.chmodSync(
|
|
556
|
+
binding.chmodSync(filepath, mode)
|
|
530
557
|
}
|
|
531
558
|
|
|
532
559
|
function fchmod (fd, mode, cb) {
|
|
@@ -559,12 +586,12 @@ function fchmodSync (fd, mode) {
|
|
|
559
586
|
binding.fchmodSync(fd, mode)
|
|
560
587
|
}
|
|
561
588
|
|
|
562
|
-
function mkdirRecursive (
|
|
563
|
-
mkdir(
|
|
589
|
+
function mkdirRecursive (filepath, mode, cb) {
|
|
590
|
+
mkdir(filepath, { mode }, function (err) {
|
|
564
591
|
if (err === null) return cb(null, 0, null)
|
|
565
592
|
|
|
566
593
|
if (err.code !== 'ENOENT') {
|
|
567
|
-
stat(
|
|
594
|
+
stat(filepath, function (e, st) {
|
|
568
595
|
if (e) return cb(e, e.errno, null)
|
|
569
596
|
if (st.isDirectory()) return cb(null, 0, null)
|
|
570
597
|
cb(err, err.errno, null)
|
|
@@ -572,20 +599,20 @@ function mkdirRecursive (path, mode, cb) {
|
|
|
572
599
|
return
|
|
573
600
|
}
|
|
574
601
|
|
|
575
|
-
while (
|
|
576
|
-
const i =
|
|
602
|
+
while (filepath.endsWith(path.sep)) filepath = filepath.slice(0, -1)
|
|
603
|
+
const i = filepath.lastIndexOf(path.sep)
|
|
577
604
|
if (i <= 0) return cb(err, err.errno, null)
|
|
578
605
|
|
|
579
|
-
mkdirRecursive(
|
|
606
|
+
mkdirRecursive(filepath.slice(0, i), mode, function (err) {
|
|
580
607
|
if (err) return cb(err, err.errno, null)
|
|
581
|
-
mkdir(
|
|
608
|
+
mkdir(filepath, { mode }, cb)
|
|
582
609
|
})
|
|
583
610
|
})
|
|
584
611
|
}
|
|
585
612
|
|
|
586
|
-
function mkdir (
|
|
587
|
-
if (typeof
|
|
588
|
-
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof
|
|
613
|
+
function mkdir (filepath, opts, cb) {
|
|
614
|
+
if (typeof filepath !== 'string') {
|
|
615
|
+
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
|
|
589
616
|
}
|
|
590
617
|
|
|
591
618
|
if (typeof opts === 'function') {
|
|
@@ -600,33 +627,33 @@ function mkdir (path, opts, cb) {
|
|
|
600
627
|
|
|
601
628
|
const mode = typeof opts.mode === 'number' ? opts.mode : 0o777
|
|
602
629
|
|
|
603
|
-
if (opts.recursive) return mkdirRecursive(
|
|
630
|
+
if (opts.recursive) return mkdirRecursive(filepath, mode, cb)
|
|
604
631
|
|
|
605
632
|
const req = getReq()
|
|
606
633
|
req.callback = cb
|
|
607
|
-
binding.mkdir(req.handle,
|
|
634
|
+
binding.mkdir(req.handle, filepath, mode)
|
|
608
635
|
}
|
|
609
636
|
|
|
610
|
-
function mkdirResursiveSync (
|
|
637
|
+
function mkdirResursiveSync (filepath, mode) {
|
|
611
638
|
try {
|
|
612
|
-
mkdirSync(
|
|
639
|
+
mkdirSync(filepath, { mode })
|
|
613
640
|
} catch (err) {
|
|
614
|
-
if (err.code !== 'ENOENT' && statSync(
|
|
641
|
+
if (err.code !== 'ENOENT' && statSync(filepath).isDirectory()) {
|
|
615
642
|
return
|
|
616
643
|
}
|
|
617
644
|
|
|
618
|
-
while (
|
|
619
|
-
const i =
|
|
645
|
+
while (filepath.endsWith(path.sep)) filepath = filepath.slice(0, -1)
|
|
646
|
+
const i = filepath.lastIndexOf(path.sep)
|
|
620
647
|
if (i <= 0) throw err
|
|
621
648
|
|
|
622
|
-
mkdirResursiveSync(
|
|
623
|
-
mkdirSync(
|
|
649
|
+
mkdirResursiveSync(filepath.slice(0, i), { mode })
|
|
650
|
+
mkdirSync(filepath, { mode })
|
|
624
651
|
}
|
|
625
652
|
}
|
|
626
653
|
|
|
627
|
-
function mkdirSync (
|
|
628
|
-
if (typeof
|
|
629
|
-
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof
|
|
654
|
+
function mkdirSync (filepath, opts) {
|
|
655
|
+
if (typeof filepath !== 'string') {
|
|
656
|
+
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
|
|
630
657
|
}
|
|
631
658
|
|
|
632
659
|
if (typeof opts === 'number') opts = { mode: opts }
|
|
@@ -634,14 +661,14 @@ function mkdirSync (path, opts) {
|
|
|
634
661
|
|
|
635
662
|
const mode = typeof opts.mode === 'number' ? opts.mode : 0o777
|
|
636
663
|
|
|
637
|
-
if (opts.recursive) return mkdirResursiveSync(
|
|
664
|
+
if (opts.recursive) return mkdirResursiveSync(filepath, mode)
|
|
638
665
|
|
|
639
|
-
binding.mkdirSync(
|
|
666
|
+
binding.mkdirSync(filepath, mode)
|
|
640
667
|
}
|
|
641
668
|
|
|
642
|
-
function rmdir (
|
|
643
|
-
if (typeof
|
|
644
|
-
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof
|
|
669
|
+
function rmdir (filepath, cb) {
|
|
670
|
+
if (typeof filepath !== 'string') {
|
|
671
|
+
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
|
|
645
672
|
}
|
|
646
673
|
|
|
647
674
|
if (typeof cb !== 'function') {
|
|
@@ -650,33 +677,33 @@ function rmdir (path, cb) {
|
|
|
650
677
|
|
|
651
678
|
const req = getReq()
|
|
652
679
|
req.callback = cb
|
|
653
|
-
binding.rmdir(req.handle,
|
|
680
|
+
binding.rmdir(req.handle, filepath)
|
|
654
681
|
}
|
|
655
682
|
|
|
656
|
-
function rmdirSync (
|
|
657
|
-
if (typeof
|
|
658
|
-
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof
|
|
683
|
+
function rmdirSync (filepath) {
|
|
684
|
+
if (typeof filepath !== 'string') {
|
|
685
|
+
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
|
|
659
686
|
}
|
|
660
687
|
|
|
661
|
-
binding.rmdirSync(
|
|
688
|
+
binding.rmdirSync(filepath)
|
|
662
689
|
}
|
|
663
690
|
|
|
664
|
-
function rmRecursive (
|
|
665
|
-
rmdir(
|
|
691
|
+
function rmRecursive (filepath, opts, cb) {
|
|
692
|
+
rmdir(filepath, function (err) {
|
|
666
693
|
if (err === null) return cb(null)
|
|
667
694
|
|
|
668
695
|
if (err.code !== 'ENOTEMPTY') return cb(err)
|
|
669
696
|
|
|
670
|
-
readdir(
|
|
697
|
+
readdir(filepath, function (err, files) {
|
|
671
698
|
if (err) return cb(err)
|
|
672
699
|
|
|
673
|
-
if (files.length === 0) return rmdir(
|
|
700
|
+
if (files.length === 0) return rmdir(filepath, cb)
|
|
674
701
|
|
|
675
702
|
let missing = files.length
|
|
676
703
|
let done = false
|
|
677
704
|
|
|
678
705
|
for (const file of files) {
|
|
679
|
-
rm(
|
|
706
|
+
rm(filepath + path.sep + file, opts, function (err) {
|
|
680
707
|
if (done) return
|
|
681
708
|
|
|
682
709
|
if (err) {
|
|
@@ -684,16 +711,16 @@ function rmRecursive (path, opts, cb) {
|
|
|
684
711
|
return cb(err)
|
|
685
712
|
}
|
|
686
713
|
|
|
687
|
-
if (--missing === 0) rmdir(
|
|
714
|
+
if (--missing === 0) rmdir(filepath, cb)
|
|
688
715
|
})
|
|
689
716
|
}
|
|
690
717
|
})
|
|
691
718
|
})
|
|
692
719
|
}
|
|
693
720
|
|
|
694
|
-
function rm (
|
|
695
|
-
if (typeof
|
|
696
|
-
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof
|
|
721
|
+
function rm (filepath, opts, cb) {
|
|
722
|
+
if (typeof filepath !== 'string') {
|
|
723
|
+
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
|
|
697
724
|
}
|
|
698
725
|
|
|
699
726
|
if (typeof opts === 'function') {
|
|
@@ -705,66 +732,66 @@ function rm (path, opts, cb) {
|
|
|
705
732
|
|
|
706
733
|
if (!opts) opts = {}
|
|
707
734
|
|
|
708
|
-
lstat(
|
|
735
|
+
lstat(filepath, function (err, st) {
|
|
709
736
|
if (err) {
|
|
710
737
|
return cb(err.code === 'ENOENT' && opts.force ? null : err)
|
|
711
738
|
}
|
|
712
739
|
|
|
713
740
|
if (st.isDirectory()) {
|
|
714
|
-
if (opts.recursive) return rmRecursive(
|
|
741
|
+
if (opts.recursive) return rmRecursive(filepath, opts, cb)
|
|
715
742
|
|
|
716
743
|
const err = new Error('is a directory')
|
|
717
744
|
err.code = 'EISDIR'
|
|
718
745
|
return cb(err)
|
|
719
746
|
}
|
|
720
747
|
|
|
721
|
-
unlink(
|
|
748
|
+
unlink(filepath, cb)
|
|
722
749
|
})
|
|
723
750
|
}
|
|
724
751
|
|
|
725
|
-
function rmRecursiveSync (
|
|
752
|
+
function rmRecursiveSync (filepath, opts) {
|
|
726
753
|
try {
|
|
727
|
-
rmdirSync(
|
|
754
|
+
rmdirSync(filepath)
|
|
728
755
|
} catch (err) {
|
|
729
756
|
if (err.code !== 'ENOTEMPTY') throw err
|
|
730
757
|
|
|
731
|
-
const files = readdirSync(
|
|
758
|
+
const files = readdirSync(filepath)
|
|
732
759
|
|
|
733
760
|
for (const file of files) {
|
|
734
|
-
rmSync(
|
|
761
|
+
rmSync(filepath + path.sep + file, opts)
|
|
735
762
|
}
|
|
736
763
|
|
|
737
|
-
rmdirSync(
|
|
764
|
+
rmdirSync(filepath)
|
|
738
765
|
}
|
|
739
766
|
}
|
|
740
767
|
|
|
741
|
-
function rmSync (
|
|
742
|
-
if (typeof
|
|
743
|
-
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof
|
|
768
|
+
function rmSync (filepath, opts) {
|
|
769
|
+
if (typeof filepath !== 'string') {
|
|
770
|
+
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
|
|
744
771
|
}
|
|
745
772
|
|
|
746
773
|
if (!opts) opts = {}
|
|
747
774
|
|
|
748
775
|
try {
|
|
749
|
-
const st = lstatSync(
|
|
776
|
+
const st = lstatSync(filepath)
|
|
750
777
|
|
|
751
778
|
if (st.isDirectory()) {
|
|
752
|
-
if (opts.recursive) return rmRecursiveSync(
|
|
779
|
+
if (opts.recursive) return rmRecursiveSync(filepath, opts)
|
|
753
780
|
|
|
754
781
|
const err = new Error('is a directory')
|
|
755
782
|
err.code = 'EISDIR'
|
|
756
783
|
throw err
|
|
757
784
|
}
|
|
758
785
|
|
|
759
|
-
unlinkSync(
|
|
786
|
+
unlinkSync(filepath)
|
|
760
787
|
} catch (err) {
|
|
761
788
|
if (err.code !== 'ENOENT' || !opts.force) throw err
|
|
762
789
|
}
|
|
763
790
|
}
|
|
764
791
|
|
|
765
|
-
function unlink (
|
|
766
|
-
if (typeof
|
|
767
|
-
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof
|
|
792
|
+
function unlink (filepath, cb) {
|
|
793
|
+
if (typeof filepath !== 'string') {
|
|
794
|
+
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
|
|
768
795
|
}
|
|
769
796
|
|
|
770
797
|
if (typeof cb !== 'function') {
|
|
@@ -773,15 +800,15 @@ function unlink (path, cb) {
|
|
|
773
800
|
|
|
774
801
|
const req = getReq()
|
|
775
802
|
req.callback = cb
|
|
776
|
-
binding.unlink(req.handle,
|
|
803
|
+
binding.unlink(req.handle, filepath)
|
|
777
804
|
}
|
|
778
805
|
|
|
779
|
-
function unlinkSync (
|
|
780
|
-
if (typeof
|
|
781
|
-
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof
|
|
806
|
+
function unlinkSync (filepath) {
|
|
807
|
+
if (typeof filepath !== 'string') {
|
|
808
|
+
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
|
|
782
809
|
}
|
|
783
810
|
|
|
784
|
-
binding.unlinkSync(
|
|
811
|
+
binding.unlinkSync(filepath)
|
|
785
812
|
}
|
|
786
813
|
|
|
787
814
|
function rename (src, dst, cb) {
|
|
@@ -814,9 +841,9 @@ function renameSync (src, dst) {
|
|
|
814
841
|
binding.renameSync(src, dst)
|
|
815
842
|
}
|
|
816
843
|
|
|
817
|
-
function realpath (
|
|
818
|
-
if (typeof
|
|
819
|
-
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof
|
|
844
|
+
function realpath (filepath, opts, cb) {
|
|
845
|
+
if (typeof filepath !== 'string') {
|
|
846
|
+
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
|
|
820
847
|
}
|
|
821
848
|
|
|
822
849
|
if (typeof opts === 'function') {
|
|
@@ -844,12 +871,12 @@ function realpath (path, opts, cb) {
|
|
|
844
871
|
cb(null, path)
|
|
845
872
|
}
|
|
846
873
|
|
|
847
|
-
binding.realpath(req.handle,
|
|
874
|
+
binding.realpath(req.handle, filepath, data)
|
|
848
875
|
}
|
|
849
876
|
|
|
850
|
-
function realpathSync (
|
|
851
|
-
if (typeof
|
|
852
|
-
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof
|
|
877
|
+
function realpathSync (filepath, opts) {
|
|
878
|
+
if (typeof filepath !== 'string') {
|
|
879
|
+
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
|
|
853
880
|
}
|
|
854
881
|
|
|
855
882
|
if (typeof opts === 'string') opts = { encoding: opts }
|
|
@@ -861,16 +888,16 @@ function realpathSync (path, opts) {
|
|
|
861
888
|
|
|
862
889
|
const data = Buffer.allocUnsafe(binding.sizeofFSPath)
|
|
863
890
|
|
|
864
|
-
binding.realpathSync(
|
|
891
|
+
binding.realpathSync(filepath, data)
|
|
865
892
|
|
|
866
|
-
|
|
867
|
-
if (encoding !== 'buffer')
|
|
868
|
-
return
|
|
893
|
+
filepath = data.subarray(0, data.indexOf(0))
|
|
894
|
+
if (encoding !== 'buffer') filepath = filepath.toString(encoding)
|
|
895
|
+
return filepath
|
|
869
896
|
}
|
|
870
897
|
|
|
871
|
-
function readlink (
|
|
872
|
-
if (typeof
|
|
873
|
-
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof
|
|
898
|
+
function readlink (filepath, opts, cb) {
|
|
899
|
+
if (typeof filepath !== 'string') {
|
|
900
|
+
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
|
|
874
901
|
}
|
|
875
902
|
|
|
876
903
|
if (typeof opts === 'function') {
|
|
@@ -898,12 +925,12 @@ function readlink (path, opts, cb) {
|
|
|
898
925
|
cb(null, path)
|
|
899
926
|
}
|
|
900
927
|
|
|
901
|
-
binding.readlink(req.handle,
|
|
928
|
+
binding.readlink(req.handle, filepath, data)
|
|
902
929
|
}
|
|
903
930
|
|
|
904
|
-
function readlinkSync (
|
|
905
|
-
if (typeof
|
|
906
|
-
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof
|
|
931
|
+
function readlinkSync (filepath, opts) {
|
|
932
|
+
if (typeof filepath !== 'string') {
|
|
933
|
+
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
|
|
907
934
|
}
|
|
908
935
|
|
|
909
936
|
if (typeof opts === 'string') opts = { encoding: opts }
|
|
@@ -915,32 +942,32 @@ function readlinkSync (path, opts) {
|
|
|
915
942
|
|
|
916
943
|
const data = Buffer.allocUnsafe(binding.sizeofFSPath)
|
|
917
944
|
|
|
918
|
-
binding.readlinkSync(
|
|
945
|
+
binding.readlinkSync(filepath, data)
|
|
919
946
|
|
|
920
|
-
|
|
921
|
-
if (encoding !== 'buffer')
|
|
922
|
-
return
|
|
947
|
+
filepath = data.subarray(0, data.indexOf(0))
|
|
948
|
+
if (encoding !== 'buffer') filepath = filepath.toString(encoding)
|
|
949
|
+
return filepath
|
|
923
950
|
}
|
|
924
951
|
|
|
925
|
-
function normalizeSymlinkTarget (target, type,
|
|
952
|
+
function normalizeSymlinkTarget (target, type, filepath) {
|
|
926
953
|
if (isWindows) {
|
|
927
|
-
if (type === 'junction') target = resolve(
|
|
954
|
+
if (type === 'junction') target = path.resolve(filepath, '..', target)
|
|
928
955
|
|
|
929
|
-
if (isAbsolute(target)) return toNamespacedPath(target)
|
|
956
|
+
if (path.isAbsolute(target)) return path.toNamespacedPath(target)
|
|
930
957
|
|
|
931
|
-
return target.replace(/\//g, sep)
|
|
958
|
+
return target.replace(/\//g, path.sep)
|
|
932
959
|
}
|
|
933
960
|
|
|
934
961
|
return target
|
|
935
962
|
}
|
|
936
963
|
|
|
937
|
-
function symlink (target,
|
|
964
|
+
function symlink (target, filepath, type, cb) {
|
|
938
965
|
if (typeof target !== 'string') {
|
|
939
|
-
throw typeError('ERR_INVALID_ARG_TYPE', 'Target must be a string. Received type ' + (typeof
|
|
966
|
+
throw typeError('ERR_INVALID_ARG_TYPE', 'Target must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
|
|
940
967
|
}
|
|
941
968
|
|
|
942
|
-
if (typeof
|
|
943
|
-
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof
|
|
969
|
+
if (typeof filepath !== 'string') {
|
|
970
|
+
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
|
|
944
971
|
}
|
|
945
972
|
|
|
946
973
|
if (typeof type === 'function') {
|
|
@@ -966,12 +993,12 @@ function symlink (target, path, type, cb) {
|
|
|
966
993
|
}
|
|
967
994
|
} else if (typeof type !== 'number') {
|
|
968
995
|
if (isWindows) {
|
|
969
|
-
target = resolve(
|
|
996
|
+
target = path.resolve(filepath, '..', target)
|
|
970
997
|
|
|
971
998
|
stat(target, (err, st) => {
|
|
972
999
|
type = err === null && st.isDirectory() ? constants.UV_FS_SYMLINK_DIR : constants.UV_FS_SYMLINK_JUNCTION
|
|
973
1000
|
|
|
974
|
-
symlink(target,
|
|
1001
|
+
symlink(target, filepath, type, filepath, cb)
|
|
975
1002
|
})
|
|
976
1003
|
|
|
977
1004
|
return
|
|
@@ -982,16 +1009,16 @@ function symlink (target, path, type, cb) {
|
|
|
982
1009
|
|
|
983
1010
|
const req = getReq()
|
|
984
1011
|
req.callback = cb
|
|
985
|
-
binding.symlink(req.handle, normalizeSymlinkTarget(target), toNamespacedPath(
|
|
1012
|
+
binding.symlink(req.handle, normalizeSymlinkTarget(target), path.toNamespacedPath(filepath), type)
|
|
986
1013
|
}
|
|
987
1014
|
|
|
988
|
-
function symlinkSync (target,
|
|
1015
|
+
function symlinkSync (target, filepath, type) {
|
|
989
1016
|
if (typeof target !== 'string') {
|
|
990
|
-
throw typeError('ERR_INVALID_ARG_TYPE', 'Target must be a string. Received type ' + (typeof
|
|
1017
|
+
throw typeError('ERR_INVALID_ARG_TYPE', 'Target must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
|
|
991
1018
|
}
|
|
992
1019
|
|
|
993
|
-
if (typeof
|
|
994
|
-
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof
|
|
1020
|
+
if (typeof filepath !== 'string') {
|
|
1021
|
+
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
|
|
995
1022
|
}
|
|
996
1023
|
|
|
997
1024
|
if (typeof type === 'string') {
|
|
@@ -1010,7 +1037,7 @@ function symlinkSync (target, path, type) {
|
|
|
1010
1037
|
}
|
|
1011
1038
|
} else if (typeof type !== 'number') {
|
|
1012
1039
|
if (isWindows) {
|
|
1013
|
-
target = resolve(
|
|
1040
|
+
target = path.resolve(filepath, '..', target)
|
|
1014
1041
|
|
|
1015
1042
|
type = statSync(target).isDirectory() ? constants.UV_FS_SYMLINK_DIR : constants.UV_FS_SYMLINK_JUNCTION
|
|
1016
1043
|
} else {
|
|
@@ -1018,12 +1045,12 @@ function symlinkSync (target, path, type) {
|
|
|
1018
1045
|
}
|
|
1019
1046
|
}
|
|
1020
1047
|
|
|
1021
|
-
binding.symlinkSync(normalizeSymlinkTarget(target), toNamespacedPath(
|
|
1048
|
+
binding.symlinkSync(normalizeSymlinkTarget(target), path.toNamespacedPath(filepath), type)
|
|
1022
1049
|
}
|
|
1023
1050
|
|
|
1024
|
-
function opendir (
|
|
1025
|
-
if (typeof
|
|
1026
|
-
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof
|
|
1051
|
+
function opendir (filepath, opts, cb) {
|
|
1052
|
+
if (typeof filepath !== 'string') {
|
|
1053
|
+
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
|
|
1027
1054
|
}
|
|
1028
1055
|
|
|
1029
1056
|
if (typeof opts === 'function') {
|
|
@@ -1042,28 +1069,28 @@ function opendir (path, opts, cb) {
|
|
|
1042
1069
|
|
|
1043
1070
|
req.callback = function (err, _) {
|
|
1044
1071
|
if (err) return cb(err, null)
|
|
1045
|
-
cb(null, new Dir(
|
|
1072
|
+
cb(null, new Dir(filepath, data, opts))
|
|
1046
1073
|
}
|
|
1047
1074
|
|
|
1048
|
-
binding.opendir(req.handle,
|
|
1075
|
+
binding.opendir(req.handle, filepath, data)
|
|
1049
1076
|
}
|
|
1050
1077
|
|
|
1051
|
-
function opendirSync (
|
|
1052
|
-
if (typeof
|
|
1053
|
-
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof
|
|
1078
|
+
function opendirSync (filepath, opts) {
|
|
1079
|
+
if (typeof filepath !== 'string') {
|
|
1080
|
+
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
|
|
1054
1081
|
}
|
|
1055
1082
|
|
|
1056
1083
|
if (typeof opts === 'string') opts = { encoding: opts }
|
|
1057
1084
|
else if (!opts) opts = {}
|
|
1058
1085
|
|
|
1059
1086
|
const data = Buffer.allocUnsafe(binding.sizeofFSDir)
|
|
1060
|
-
binding.opendirSync(
|
|
1061
|
-
return new Dir(
|
|
1087
|
+
binding.opendirSync(filepath, data)
|
|
1088
|
+
return new Dir(filepath, data, opts)
|
|
1062
1089
|
}
|
|
1063
1090
|
|
|
1064
|
-
function readdir (
|
|
1065
|
-
if (typeof
|
|
1066
|
-
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof
|
|
1091
|
+
function readdir (filepath, opts, cb) {
|
|
1092
|
+
if (typeof filepath !== 'string') {
|
|
1093
|
+
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
|
|
1067
1094
|
}
|
|
1068
1095
|
|
|
1069
1096
|
if (typeof opts === 'function') {
|
|
@@ -1080,7 +1107,7 @@ function readdir (path, opts, cb) {
|
|
|
1080
1107
|
withFileTypes = false
|
|
1081
1108
|
} = opts
|
|
1082
1109
|
|
|
1083
|
-
opendir(
|
|
1110
|
+
opendir(filepath, opts, async (err, dir) => {
|
|
1084
1111
|
if (err) return cb(err, null)
|
|
1085
1112
|
const result = []
|
|
1086
1113
|
for await (const entry of dir) {
|
|
@@ -1090,9 +1117,9 @@ function readdir (path, opts, cb) {
|
|
|
1090
1117
|
})
|
|
1091
1118
|
}
|
|
1092
1119
|
|
|
1093
|
-
function readdirSync (
|
|
1094
|
-
if (typeof
|
|
1095
|
-
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof
|
|
1120
|
+
function readdirSync (filepath, opts) {
|
|
1121
|
+
if (typeof filepath !== 'string') {
|
|
1122
|
+
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
|
|
1096
1123
|
}
|
|
1097
1124
|
|
|
1098
1125
|
if (typeof opts === 'string') opts = { encoding: opts }
|
|
@@ -1102,7 +1129,7 @@ function readdirSync (path, opts) {
|
|
|
1102
1129
|
withFileTypes = false
|
|
1103
1130
|
} = opts
|
|
1104
1131
|
|
|
1105
|
-
const dir = opendirSync(
|
|
1132
|
+
const dir = opendirSync(filepath, opts)
|
|
1106
1133
|
const result = []
|
|
1107
1134
|
|
|
1108
1135
|
while (true) {
|
|
@@ -1114,9 +1141,9 @@ function readdirSync (path, opts) {
|
|
|
1114
1141
|
return result
|
|
1115
1142
|
}
|
|
1116
1143
|
|
|
1117
|
-
function readFile (
|
|
1118
|
-
if (typeof
|
|
1119
|
-
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof
|
|
1144
|
+
function readFile (filepath, opts, cb) {
|
|
1145
|
+
if (typeof filepath !== 'string') {
|
|
1146
|
+
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
|
|
1120
1147
|
}
|
|
1121
1148
|
|
|
1122
1149
|
if (typeof opts === 'function') {
|
|
@@ -1133,7 +1160,7 @@ function readFile (path, opts, cb) {
|
|
|
1133
1160
|
encoding = 'buffer'
|
|
1134
1161
|
} = opts
|
|
1135
1162
|
|
|
1136
|
-
open(
|
|
1163
|
+
open(filepath, opts.flag || 'r', function (err, fd) {
|
|
1137
1164
|
if (err) return cb(err)
|
|
1138
1165
|
|
|
1139
1166
|
fstat(fd, function (err, st) {
|
|
@@ -1169,9 +1196,9 @@ function readFile (path, opts, cb) {
|
|
|
1169
1196
|
})
|
|
1170
1197
|
}
|
|
1171
1198
|
|
|
1172
|
-
function readFileSync (
|
|
1173
|
-
if (typeof
|
|
1174
|
-
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof
|
|
1199
|
+
function readFileSync (filepath, opts) {
|
|
1200
|
+
if (typeof filepath !== 'string') {
|
|
1201
|
+
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
|
|
1175
1202
|
}
|
|
1176
1203
|
|
|
1177
1204
|
if (typeof opts === 'string') opts = { encoding: opts }
|
|
@@ -1181,7 +1208,7 @@ function readFileSync (path, opts) {
|
|
|
1181
1208
|
encoding = 'buffer'
|
|
1182
1209
|
} = opts
|
|
1183
1210
|
|
|
1184
|
-
const fd = openSync(
|
|
1211
|
+
const fd = openSync(filepath, opts.flag || 'r')
|
|
1185
1212
|
|
|
1186
1213
|
try {
|
|
1187
1214
|
const st = fstatSync(fd)
|
|
@@ -1205,9 +1232,9 @@ function readFileSync (path, opts) {
|
|
|
1205
1232
|
}
|
|
1206
1233
|
}
|
|
1207
1234
|
|
|
1208
|
-
function writeFile (
|
|
1209
|
-
if (typeof
|
|
1210
|
-
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof
|
|
1235
|
+
function writeFile (filepath, data, opts, cb) {
|
|
1236
|
+
if (typeof filepath !== 'string') {
|
|
1237
|
+
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
|
|
1211
1238
|
}
|
|
1212
1239
|
|
|
1213
1240
|
if (typeof data !== 'string' && !Buffer.isBuffer(data) && !ArrayBuffer.isView(data)) {
|
|
@@ -1226,7 +1253,7 @@ function writeFile (path, data, opts, cb) {
|
|
|
1226
1253
|
|
|
1227
1254
|
if (typeof data === 'string') data = Buffer.from(data, opts.encoding)
|
|
1228
1255
|
|
|
1229
|
-
open(
|
|
1256
|
+
open(filepath, opts.flag || 'w', opts.mode || 0o666, function (err, fd) {
|
|
1230
1257
|
if (err) return cb(err)
|
|
1231
1258
|
|
|
1232
1259
|
write(fd, data, loop)
|
|
@@ -1252,9 +1279,9 @@ function writeFile (path, data, opts, cb) {
|
|
|
1252
1279
|
})
|
|
1253
1280
|
}
|
|
1254
1281
|
|
|
1255
|
-
function writeFileSync (
|
|
1256
|
-
if (typeof
|
|
1257
|
-
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof
|
|
1282
|
+
function writeFileSync (filepath, data, opts) {
|
|
1283
|
+
if (typeof filepath !== 'string') {
|
|
1284
|
+
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
|
|
1258
1285
|
}
|
|
1259
1286
|
|
|
1260
1287
|
if (typeof data !== 'string' && !Buffer.isBuffer(data) && !ArrayBuffer.isView(data)) {
|
|
@@ -1266,7 +1293,7 @@ function writeFileSync (path, data, opts) {
|
|
|
1266
1293
|
|
|
1267
1294
|
if (typeof data === 'string') data = Buffer.from(data, opts.encoding)
|
|
1268
1295
|
|
|
1269
|
-
const fd = openSync(
|
|
1296
|
+
const fd = openSync(filepath, opts.flag || 'w', opts.mode)
|
|
1270
1297
|
|
|
1271
1298
|
try {
|
|
1272
1299
|
let len = 0
|
|
@@ -1282,9 +1309,9 @@ function writeFileSync (path, data, opts) {
|
|
|
1282
1309
|
}
|
|
1283
1310
|
}
|
|
1284
1311
|
|
|
1285
|
-
function watch (
|
|
1286
|
-
if (typeof
|
|
1287
|
-
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof
|
|
1312
|
+
function watch (filepath, opts, cb) {
|
|
1313
|
+
if (typeof filepath !== 'string') {
|
|
1314
|
+
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
|
|
1288
1315
|
}
|
|
1289
1316
|
|
|
1290
1317
|
if (typeof opts === 'function') {
|
|
@@ -1295,7 +1322,7 @@ function watch (path, opts, cb) {
|
|
|
1295
1322
|
if (typeof opts === 'string') opts = { encoding: opts }
|
|
1296
1323
|
else if (!opts) opts = {}
|
|
1297
1324
|
|
|
1298
|
-
const watcher = new Watcher(
|
|
1325
|
+
const watcher = new Watcher(filepath, opts)
|
|
1299
1326
|
if (cb) watcher.on('change', cb)
|
|
1300
1327
|
return watcher
|
|
1301
1328
|
}
|
|
@@ -1740,6 +1767,7 @@ function noop () {}
|
|
|
1740
1767
|
exports.access = access
|
|
1741
1768
|
exports.chmod = chmod
|
|
1742
1769
|
exports.close = close
|
|
1770
|
+
exports.exists = exists
|
|
1743
1771
|
exports.fchmod = fchmod
|
|
1744
1772
|
exports.fstat = fstat
|
|
1745
1773
|
exports.ftruncate = ftruncate
|
|
@@ -1767,6 +1795,7 @@ exports.writev = writev
|
|
|
1767
1795
|
exports.accessSync = accessSync
|
|
1768
1796
|
exports.chmodSync = chmodSync
|
|
1769
1797
|
exports.closeSync = closeSync
|
|
1798
|
+
exports.existsSync = existsSync
|
|
1770
1799
|
exports.fchmodSync = fchmodSync
|
|
1771
1800
|
exports.fstatSync = fstatSync
|
|
1772
1801
|
exports.lstatSync = lstatSync
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bare-fs",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Native file system for Javascript",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"files": [
|
|
@@ -11,12 +11,15 @@
|
|
|
11
11
|
"CMakeLists.txt",
|
|
12
12
|
"prebuilds"
|
|
13
13
|
],
|
|
14
|
+
"imports": {
|
|
15
|
+
"events": "bare-events"
|
|
16
|
+
},
|
|
14
17
|
"scripts": {
|
|
15
|
-
"test": "standard && bare test.js"
|
|
18
|
+
"test": "standard && bare -m package.json test.js"
|
|
16
19
|
},
|
|
17
20
|
"repository": {
|
|
18
21
|
"type": "git",
|
|
19
|
-
"url": "https://github.com/holepunchto/bare-fs.git"
|
|
22
|
+
"url": "git+https://github.com/holepunchto/bare-fs.git"
|
|
20
23
|
},
|
|
21
24
|
"author": "Holepunch",
|
|
22
25
|
"license": "Apache-2.0",
|
|
@@ -25,6 +28,9 @@
|
|
|
25
28
|
},
|
|
26
29
|
"homepage": "https://github.com/holepunchto/bare-fs#readme",
|
|
27
30
|
"dependencies": {
|
|
31
|
+
"bare-events": "^2.0.0",
|
|
32
|
+
"bare-os": "^2.0.0",
|
|
33
|
+
"bare-path": "^2.0.0",
|
|
28
34
|
"streamx": "^2.13.0"
|
|
29
35
|
},
|
|
30
36
|
"devDependencies": {
|