bare-fs 4.1.3 → 4.1.4

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.
Files changed (2) hide show
  1. package/index.js +55 -38
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -153,7 +153,7 @@ function open(filepath, flags, mode, cb) {
153
153
 
154
154
  const req = getReq()
155
155
  req.callback = cb
156
- binding.open(req.handle, filepath, flags, mode)
156
+ binding.open(req.handle, toNamespacedPath(filepath), flags, mode)
157
157
  }
158
158
 
159
159
  function openSync(filepath, flags = 'r', mode = 0o666) {
@@ -171,7 +171,7 @@ function openSync(filepath, flags = 'r', mode = 0o666) {
171
171
  if (typeof flags === 'string') flags = flagsToNumber(flags)
172
172
  if (typeof mode === 'string') mode = modeToNumber(mode)
173
173
 
174
- return binding.openSync(filepath, flags, mode)
174
+ return binding.openSync(toNamespacedPath(filepath), flags, mode)
175
175
  }
176
176
 
177
177
  function close(fd, cb = noop) {
@@ -263,7 +263,7 @@ function access(filepath, mode, cb) {
263
263
 
264
264
  const req = getReq()
265
265
  req.callback = cb
266
- binding.access(req.handle, filepath, mode)
266
+ binding.access(req.handle, toNamespacedPath(filepath), mode)
267
267
  }
268
268
 
269
269
  function accessSync(filepath, mode = constants.F_OK) {
@@ -278,7 +278,7 @@ function accessSync(filepath, mode = constants.F_OK) {
278
278
  )
279
279
  }
280
280
 
281
- binding.accessSync(filepath, mode)
281
+ binding.accessSync(toNamespacedPath(filepath), mode)
282
282
  }
283
283
 
284
284
  function exists(filepath, cb) {
@@ -304,7 +304,7 @@ function exists(filepath, cb) {
304
304
  )
305
305
  }
306
306
 
307
- return access(filepath, (err) => cb(!!err))
307
+ return access(toNamespacedPath(filepath), (err) => cb(!!err))
308
308
  }
309
309
 
310
310
  function existsSync(filepath) {
@@ -320,7 +320,7 @@ function existsSync(filepath) {
320
320
  }
321
321
 
322
322
  try {
323
- accessSync(filepath)
323
+ accessSync(toNamespacedPath(filepath))
324
324
  return true
325
325
  } catch {
326
326
  return false
@@ -680,7 +680,7 @@ function stat(filepath, cb) {
680
680
  else cb(null, new Stats(...data))
681
681
  }
682
682
 
683
- binding.stat(req.handle, filepath, data)
683
+ binding.stat(req.handle, toNamespacedPath(filepath), data)
684
684
  }
685
685
 
686
686
  function statSync(filepath) {
@@ -695,7 +695,7 @@ function statSync(filepath) {
695
695
  )
696
696
  }
697
697
 
698
- return new Stats(...binding.statSync(filepath))
698
+ return new Stats(...binding.statSync(toNamespacedPath(filepath)))
699
699
  }
700
700
 
701
701
  function lstat(filepath, cb) {
@@ -730,7 +730,7 @@ function lstat(filepath, cb) {
730
730
  else cb(null, new Stats(...data))
731
731
  }
732
732
 
733
- binding.lstat(req.handle, filepath, data)
733
+ binding.lstat(req.handle, toNamespacedPath(filepath), data)
734
734
  }
735
735
 
736
736
  function lstatSync(filepath) {
@@ -745,7 +745,7 @@ function lstatSync(filepath) {
745
745
  )
746
746
  }
747
747
 
748
- return new Stats(...binding.lstatSync(filepath))
748
+ return new Stats(...binding.lstatSync(toNamespacedPath(filepath)))
749
749
  }
750
750
 
751
751
  function fstat(fd, cb) {
@@ -896,7 +896,7 @@ function chmod(filepath, mode, cb) {
896
896
 
897
897
  const req = getReq()
898
898
  req.callback = cb
899
- binding.chmod(req.handle, filepath, mode)
899
+ binding.chmod(req.handle, toNamespacedPath(filepath), mode)
900
900
  }
901
901
 
902
902
  function chmodSync(filepath, mode) {
@@ -913,7 +913,7 @@ function chmodSync(filepath, mode) {
913
913
 
914
914
  if (typeof mode === 'string') mode = modeToNumber(mode)
915
915
 
916
- binding.chmodSync(filepath, mode)
916
+ binding.chmodSync(toNamespacedPath(filepath), mode)
917
917
  }
918
918
 
919
919
  function fchmod(fd, mode, cb) {
@@ -969,6 +969,8 @@ function fchmodSync(fd, mode) {
969
969
  }
970
970
 
971
971
  function mkdirRecursive(filepath, mode, cb) {
972
+ filepath = toNamespacedPath(filepath)
973
+
972
974
  mkdir(filepath, { mode }, function (err) {
973
975
  if (err === null) return cb(null, 0, null)
974
976
 
@@ -1032,8 +1034,9 @@ function mkdir(filepath, opts, cb) {
1032
1034
 
1033
1035
  const mode = typeof opts.mode === 'number' ? opts.mode : 0o777
1034
1036
 
1035
- if (opts.recursive)
1036
- return mkdirRecursive(filepath.replace(/\//g, path.sep), mode, cb)
1037
+ filepath = toNamespacedPath(filepath)
1038
+
1039
+ if (opts.recursive) return mkdirRecursive(filepath, mode, cb)
1037
1040
 
1038
1041
  const req = getReq()
1039
1042
  req.callback = cb
@@ -1041,6 +1044,8 @@ function mkdir(filepath, opts, cb) {
1041
1044
  }
1042
1045
 
1043
1046
  function mkdirRecursiveSync(filepath, mode) {
1047
+ filepath = toNamespacedPath(filepath)
1048
+
1044
1049
  try {
1045
1050
  mkdirSync(filepath, { mode })
1046
1051
  } catch (err) {
@@ -1083,8 +1088,9 @@ function mkdirSync(filepath, opts) {
1083
1088
 
1084
1089
  const mode = typeof opts.mode === 'number' ? opts.mode : 0o777
1085
1090
 
1086
- if (opts.recursive)
1087
- return mkdirRecursiveSync(filepath.replace(/\//g, path.sep), mode)
1091
+ filepath = toNamespacedPath(filepath)
1092
+
1093
+ if (opts.recursive) return mkdirRecursiveSync(filepath, mode)
1088
1094
 
1089
1095
  binding.mkdirSync(filepath, mode)
1090
1096
  }
@@ -1114,7 +1120,7 @@ function rmdir(filepath, cb) {
1114
1120
 
1115
1121
  const req = getReq()
1116
1122
  req.callback = cb
1117
- binding.rmdir(req.handle, filepath)
1123
+ binding.rmdir(req.handle, toNamespacedPath(filepath))
1118
1124
  }
1119
1125
 
1120
1126
  function rmdirSync(filepath) {
@@ -1129,10 +1135,12 @@ function rmdirSync(filepath) {
1129
1135
  )
1130
1136
  }
1131
1137
 
1132
- binding.rmdirSync(filepath)
1138
+ binding.rmdirSync(toNamespacedPath(filepath))
1133
1139
  }
1134
1140
 
1135
1141
  function rmRecursive(filepath, opts, cb) {
1142
+ filepath = toNamespacedPath(filepath)
1143
+
1136
1144
  rmdir(filepath, function (err) {
1137
1145
  if (err === null) return cb(null)
1138
1146
 
@@ -1190,6 +1198,8 @@ function rm(filepath, opts, cb) {
1190
1198
 
1191
1199
  if (!opts) opts = {}
1192
1200
 
1201
+ filepath = toNamespacedPath(filepath)
1202
+
1193
1203
  lstat(filepath, function (err, st) {
1194
1204
  if (err) {
1195
1205
  return cb(err.code === 'ENOENT' && opts.force ? null : err)
@@ -1208,6 +1218,8 @@ function rm(filepath, opts, cb) {
1208
1218
  }
1209
1219
 
1210
1220
  function rmRecursiveSync(filepath, opts) {
1221
+ filepath = toNamespacedPath(filepath)
1222
+
1211
1223
  try {
1212
1224
  rmdirSync(filepath)
1213
1225
  } catch (err) {
@@ -1237,6 +1249,8 @@ function rmSync(filepath, opts) {
1237
1249
 
1238
1250
  if (!opts) opts = {}
1239
1251
 
1252
+ filepath = toNamespacedPath(filepath)
1253
+
1240
1254
  try {
1241
1255
  const st = lstatSync(filepath)
1242
1256
 
@@ -1279,7 +1293,7 @@ function unlink(filepath, cb) {
1279
1293
 
1280
1294
  const req = getReq()
1281
1295
  req.callback = cb
1282
- binding.unlink(req.handle, filepath)
1296
+ binding.unlink(req.handle, toNamespacedPath(filepath))
1283
1297
  }
1284
1298
 
1285
1299
  function unlinkSync(filepath) {
@@ -1294,7 +1308,7 @@ function unlinkSync(filepath) {
1294
1308
  )
1295
1309
  }
1296
1310
 
1297
- binding.unlinkSync(filepath)
1311
+ binding.unlinkSync(toNamespacedPath(filepath))
1298
1312
  }
1299
1313
 
1300
1314
  function rename(src, dst, cb) {
@@ -1431,7 +1445,7 @@ function realpath(filepath, opts, cb) {
1431
1445
  cb(null, path)
1432
1446
  }
1433
1447
 
1434
- binding.realpath(req.handle, filepath, data)
1448
+ binding.realpath(req.handle, toNamespacedPath(filepath), data)
1435
1449
  }
1436
1450
 
1437
1451
  function realpathSync(filepath, opts) {
@@ -1453,7 +1467,7 @@ function realpathSync(filepath, opts) {
1453
1467
 
1454
1468
  const data = Buffer.allocUnsafe(binding.sizeofFSPath)
1455
1469
 
1456
- binding.realpathSync(filepath, data)
1470
+ binding.realpathSync(toNamespacedPath(filepath), data)
1457
1471
 
1458
1472
  filepath = data.subarray(0, data.indexOf(0))
1459
1473
  if (encoding !== 'buffer') filepath = filepath.toString(encoding)
@@ -1502,7 +1516,7 @@ function readlink(filepath, opts, cb) {
1502
1516
  cb(null, path)
1503
1517
  }
1504
1518
 
1505
- binding.readlink(req.handle, filepath, data)
1519
+ binding.readlink(req.handle, toNamespacedPath(filepath), data)
1506
1520
  }
1507
1521
 
1508
1522
  function readlinkSync(filepath, opts) {
@@ -1524,7 +1538,7 @@ function readlinkSync(filepath, opts) {
1524
1538
 
1525
1539
  const data = Buffer.allocUnsafe(binding.sizeofFSPath)
1526
1540
 
1527
- binding.readlinkSync(filepath, data)
1541
+ binding.readlinkSync(toNamespacedPath(filepath), data)
1528
1542
 
1529
1543
  filepath = data.subarray(0, data.indexOf(0))
1530
1544
  if (encoding !== 'buffer') filepath = filepath.toString(encoding)
@@ -1580,6 +1594,8 @@ function symlink(target, filepath, type, cb) {
1580
1594
  )
1581
1595
  }
1582
1596
 
1597
+ filepath = toNamespacedPath(filepath)
1598
+
1583
1599
  if (typeof type === 'string') {
1584
1600
  switch (type) {
1585
1601
  case 'file':
@@ -1620,12 +1636,7 @@ function symlink(target, filepath, type, cb) {
1620
1636
 
1621
1637
  const req = getReq()
1622
1638
  req.callback = cb
1623
- binding.symlink(
1624
- req.handle,
1625
- normalizeSymlinkTarget(target),
1626
- path.toNamespacedPath(filepath),
1627
- type
1628
- )
1639
+ binding.symlink(req.handle, normalizeSymlinkTarget(target), filepath, type)
1629
1640
  }
1630
1641
 
1631
1642
  function symlinkSync(target, filepath, type) {
@@ -1651,6 +1662,8 @@ function symlinkSync(target, filepath, type) {
1651
1662
  )
1652
1663
  }
1653
1664
 
1665
+ filepath = toNamespacedPath(filepath)
1666
+
1654
1667
  if (typeof type === 'string') {
1655
1668
  switch (type) {
1656
1669
  case 'file':
@@ -1682,11 +1695,7 @@ function symlinkSync(target, filepath, type) {
1682
1695
  }
1683
1696
  }
1684
1697
 
1685
- binding.symlinkSync(
1686
- normalizeSymlinkTarget(target),
1687
- path.toNamespacedPath(filepath),
1688
- type
1689
- )
1698
+ binding.symlinkSync(normalizeSymlinkTarget(target), filepath, type)
1690
1699
  }
1691
1700
 
1692
1701
  function opendir(filepath, opts, cb) {
@@ -1718,6 +1727,8 @@ function opendir(filepath, opts, cb) {
1718
1727
  if (typeof opts === 'string') opts = { encoding: opts }
1719
1728
  else if (!opts) opts = {}
1720
1729
 
1730
+ filepath = toNamespacedPath(filepath)
1731
+
1721
1732
  const data = Buffer.allocUnsafe(binding.sizeofFSDir)
1722
1733
 
1723
1734
  const req = getReq()
@@ -1745,6 +1756,8 @@ function opendirSync(filepath, opts) {
1745
1756
  if (typeof opts === 'string') opts = { encoding: opts }
1746
1757
  else if (!opts) opts = {}
1747
1758
 
1759
+ filepath = toNamespacedPath(filepath)
1760
+
1748
1761
  const data = Buffer.allocUnsafe(binding.sizeofFSDir)
1749
1762
  binding.opendirSync(filepath, data)
1750
1763
  return new Dir(filepath, data, opts)
@@ -1781,7 +1794,7 @@ function readdir(filepath, opts, cb) {
1781
1794
 
1782
1795
  const { withFileTypes = false } = opts
1783
1796
 
1784
- opendir(filepath, opts, async (err, dir) => {
1797
+ opendir(toNamespacedPath(filepath), opts, async (err, dir) => {
1785
1798
  if (err) return cb(err, null)
1786
1799
  const result = []
1787
1800
  for await (const entry of dir) {
@@ -1808,7 +1821,7 @@ function readdirSync(filepath, opts) {
1808
1821
 
1809
1822
  const { withFileTypes = false } = opts
1810
1823
 
1811
- const dir = opendirSync(filepath, opts)
1824
+ const dir = opendirSync(toNamespacedPath(filepath), opts)
1812
1825
  const result = []
1813
1826
 
1814
1827
  while (true) {
@@ -2140,7 +2153,7 @@ function watch(filepath, opts, cb) {
2140
2153
  if (typeof opts === 'string') opts = { encoding: opts }
2141
2154
  else if (!opts) opts = {}
2142
2155
 
2143
- const watcher = new Watcher(filepath, opts)
2156
+ const watcher = new Watcher(toNamespacedPath(filepath), opts)
2144
2157
  if (cb) watcher.on('change', cb)
2145
2158
  return watcher
2146
2159
  }
@@ -2714,3 +2727,7 @@ function promisify(fn) {
2714
2727
  function map(data) {
2715
2728
  return typeof data === 'string' ? Buffer.from(data) : data
2716
2729
  }
2730
+
2731
+ function toNamespacedPath(filepath) {
2732
+ return path.toNamespacedPath(filepath)
2733
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-fs",
3
- "version": "4.1.3",
3
+ "version": "4.1.4",
4
4
  "description": "Native file system for Javascript",
5
5
  "exports": {
6
6
  "./package": "./package.json",