bare-fs 4.4.5 → 4.4.10
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/index.js +55 -57
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -219,10 +219,10 @@ async function access(filepath, mode = constants.F_OK, cb) {
|
|
|
219
219
|
}
|
|
220
220
|
|
|
221
221
|
function accessSync(filepath, mode = constants.F_OK) {
|
|
222
|
-
using req = FileRequest.borrow()
|
|
223
|
-
|
|
224
222
|
filepath = toNamespacedPath(filepath)
|
|
225
223
|
|
|
224
|
+
using req = FileRequest.borrow()
|
|
225
|
+
|
|
226
226
|
try {
|
|
227
227
|
binding.accessSync(req.handle, filepath, mode)
|
|
228
228
|
} catch (e) {
|
|
@@ -737,31 +737,32 @@ async function mkdir(filepath, opts, cb) {
|
|
|
737
737
|
filepath = toNamespacedPath(filepath)
|
|
738
738
|
|
|
739
739
|
if (opts.recursive) {
|
|
740
|
+
let err = null
|
|
740
741
|
try {
|
|
741
|
-
await mkdir(filepath, { mode })
|
|
742
|
-
} catch (err) {
|
|
743
|
-
if (err.code !== 'ENOENT' && (await stat(filepath)).isDirectory()) {
|
|
744
|
-
return ok(cb)
|
|
745
|
-
}
|
|
746
|
-
|
|
747
|
-
while (filepath.endsWith(path.sep)) filepath = filepath.slice(0, -1)
|
|
748
|
-
const i = filepath.lastIndexOf(path.sep)
|
|
749
|
-
if (i <= 0) return fail(err, cb)
|
|
750
|
-
|
|
751
|
-
await mkdir(filepath.slice(0, i), { mode, recursive: true })
|
|
752
|
-
|
|
753
742
|
try {
|
|
754
743
|
await mkdir(filepath, { mode })
|
|
755
744
|
} catch (err) {
|
|
756
|
-
if (
|
|
757
|
-
|
|
745
|
+
if (err.code !== 'ENOENT') {
|
|
746
|
+
if (!(await stat(filepath)).isDirectory()) throw err
|
|
747
|
+
} else {
|
|
748
|
+
while (filepath.endsWith(path.sep)) filepath = filepath.slice(0, -1)
|
|
749
|
+
const i = filepath.lastIndexOf(path.sep)
|
|
750
|
+
if (i <= 0) throw err
|
|
751
|
+
|
|
752
|
+
await mkdir(filepath.slice(0, i), { mode, recursive: true })
|
|
753
|
+
|
|
754
|
+
try {
|
|
755
|
+
await mkdir(filepath, { mode })
|
|
756
|
+
} catch (err) {
|
|
757
|
+
if (!(await stat(filepath)).isDirectory()) throw err
|
|
758
|
+
}
|
|
758
759
|
}
|
|
759
|
-
|
|
760
|
-
return fail(err, cb)
|
|
761
760
|
}
|
|
761
|
+
} catch (e) {
|
|
762
|
+
err = e
|
|
762
763
|
}
|
|
763
764
|
|
|
764
|
-
return
|
|
765
|
+
return done(err, cb)
|
|
765
766
|
}
|
|
766
767
|
|
|
767
768
|
using req = FileRequest.borrow()
|
|
@@ -794,24 +795,20 @@ function mkdirSync(filepath, opts) {
|
|
|
794
795
|
try {
|
|
795
796
|
mkdirSync(filepath, { mode })
|
|
796
797
|
} catch (err) {
|
|
797
|
-
if (err.code !== 'ENOENT'
|
|
798
|
-
|
|
799
|
-
}
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
if (i <= 0) throw err
|
|
798
|
+
if (err.code !== 'ENOENT') {
|
|
799
|
+
if (!statSync(filepath).isDirectory()) throw err
|
|
800
|
+
} else {
|
|
801
|
+
while (filepath.endsWith(path.sep)) filepath = filepath.slice(0, -1)
|
|
802
|
+
const i = filepath.lastIndexOf(path.sep)
|
|
803
|
+
if (i <= 0) throw err
|
|
804
804
|
|
|
805
|
-
|
|
805
|
+
mkdirSync(filepath.slice(0, i), { mode, recursive: true })
|
|
806
806
|
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
return
|
|
807
|
+
try {
|
|
808
|
+
mkdirSync(filepath, { mode })
|
|
809
|
+
} catch (err) {
|
|
810
|
+
if (!statSync(filepath).isDirectory()) throw err
|
|
812
811
|
}
|
|
813
|
-
|
|
814
|
-
throw err
|
|
815
812
|
}
|
|
816
813
|
}
|
|
817
814
|
|
|
@@ -878,6 +875,7 @@ async function rm(filepath, opts, cb) {
|
|
|
878
875
|
|
|
879
876
|
filepath = toNamespacedPath(filepath)
|
|
880
877
|
|
|
878
|
+
let err = null
|
|
881
879
|
try {
|
|
882
880
|
const st = await lstat(filepath)
|
|
883
881
|
|
|
@@ -897,21 +895,20 @@ async function rm(filepath, opts, cb) {
|
|
|
897
895
|
await rmdir(filepath)
|
|
898
896
|
}
|
|
899
897
|
} else {
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
}),
|
|
906
|
-
cb
|
|
907
|
-
)
|
|
898
|
+
throw new FileError('is a directory', {
|
|
899
|
+
operation: 'rm',
|
|
900
|
+
code: 'EISDIR',
|
|
901
|
+
path: filepath
|
|
902
|
+
})
|
|
908
903
|
}
|
|
909
904
|
} else {
|
|
910
905
|
await unlink(filepath)
|
|
911
906
|
}
|
|
912
|
-
} catch (
|
|
913
|
-
if (
|
|
907
|
+
} catch (e) {
|
|
908
|
+
if (e.code !== 'ENOENT' || !opts.force) err = e
|
|
914
909
|
}
|
|
910
|
+
|
|
911
|
+
return done(err, cb)
|
|
915
912
|
}
|
|
916
913
|
|
|
917
914
|
function rmSync(filepath, opts) {
|
|
@@ -1432,12 +1429,13 @@ async function readFile(filepath, opts, cb) {
|
|
|
1432
1429
|
const { encoding = 'buffer' } = opts
|
|
1433
1430
|
|
|
1434
1431
|
let fd = -1
|
|
1432
|
+
let buffer = null
|
|
1433
|
+
let err = null
|
|
1435
1434
|
try {
|
|
1436
1435
|
fd = await open(filepath, opts.flag || 'r')
|
|
1437
1436
|
|
|
1438
1437
|
const st = await fstat(fd)
|
|
1439
1438
|
|
|
1440
|
-
let buffer
|
|
1441
1439
|
let len = 0
|
|
1442
1440
|
|
|
1443
1441
|
if (st.size === 0) {
|
|
@@ -1465,13 +1463,13 @@ async function readFile(filepath, opts, cb) {
|
|
|
1465
1463
|
}
|
|
1466
1464
|
|
|
1467
1465
|
if (encoding !== 'buffer') buffer = buffer.toString(encoding)
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
} catch (err) {
|
|
1471
|
-
fail(err, cb)
|
|
1466
|
+
} catch (e) {
|
|
1467
|
+
err = e
|
|
1472
1468
|
} finally {
|
|
1473
1469
|
if (fd !== -1) await close(fd)
|
|
1474
1470
|
}
|
|
1471
|
+
|
|
1472
|
+
return done(err, buffer, cb)
|
|
1475
1473
|
}
|
|
1476
1474
|
|
|
1477
1475
|
function readFileSync(filepath, opts) {
|
|
@@ -1533,22 +1531,22 @@ async function writeFile(filepath, data, opts, cb) {
|
|
|
1533
1531
|
if (typeof data === 'string') data = Buffer.from(data, opts.encoding)
|
|
1534
1532
|
|
|
1535
1533
|
let fd = -1
|
|
1534
|
+
let len = 0
|
|
1535
|
+
let err = null
|
|
1536
1536
|
try {
|
|
1537
1537
|
fd = await open(filepath, opts.flag || 'w', opts.mode || 0o666)
|
|
1538
1538
|
|
|
1539
|
-
let len = 0
|
|
1540
|
-
|
|
1541
1539
|
while (true) {
|
|
1542
1540
|
len += await write(fd, len ? data.subarray(len) : data)
|
|
1543
1541
|
if (len === data.byteLength) break
|
|
1544
1542
|
}
|
|
1545
|
-
|
|
1546
|
-
return ok(cb)
|
|
1547
1543
|
} catch (err) {
|
|
1548
|
-
|
|
1544
|
+
err = e
|
|
1549
1545
|
} finally {
|
|
1550
1546
|
if (fd !== -1) await close(fd)
|
|
1551
1547
|
}
|
|
1548
|
+
|
|
1549
|
+
return done(err, len, cb)
|
|
1552
1550
|
}
|
|
1553
1551
|
|
|
1554
1552
|
function writeFileSync(filepath, data, opts) {
|
|
@@ -1939,16 +1937,16 @@ class FileReadStream extends Readable {
|
|
|
1939
1937
|
err = e
|
|
1940
1938
|
}
|
|
1941
1939
|
|
|
1942
|
-
if (err) return
|
|
1940
|
+
if (err) return this.destroy(err)
|
|
1943
1941
|
|
|
1944
1942
|
if (len === 0) return this.push(null)
|
|
1945
1943
|
|
|
1946
1944
|
if (this._missing < len) len = this._missing
|
|
1947
1945
|
|
|
1948
|
-
this.push(data.subarray(0, len))
|
|
1949
|
-
|
|
1950
1946
|
this._missing -= len
|
|
1951
1947
|
this._offset += len
|
|
1948
|
+
|
|
1949
|
+
this.push(data.subarray(0, len))
|
|
1952
1950
|
}
|
|
1953
1951
|
|
|
1954
1952
|
async _destroy(err, cb) {
|