bare-fs 4.4.4 → 4.4.6

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 (3) hide show
  1. package/binding.c +1 -7
  2. package/index.js +38 -33
  3. package/package.json +1 -1
package/binding.c CHANGED
@@ -1976,13 +1976,7 @@ bare_fs_watcher_init(js_env_t *env, js_callback_info_t *info) {
1976
1976
  }
1977
1977
 
1978
1978
  err = uv_fs_event_start(&watcher->handle, bare_fs__on_watcher_event, (char *) path, recursive ? UV_FS_EVENT_RECURSIVE : 0);
1979
-
1980
- if (err < 0) {
1981
- err = js_throw_error(env, uv_err_name(err), uv_strerror(err));
1982
- assert(err == 0);
1983
-
1984
- return NULL;
1985
- }
1979
+ assert(err == 0);
1986
1980
 
1987
1981
  watcher->env = env;
1988
1982
  watcher->closing = false;
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- const FastFIFO = require('fast-fifo')
1
+ const FIFO = require('fast-fifo')
2
2
  const EventEmitter = require('bare-events')
3
3
  const path = require('bare-path')
4
4
  const { fileURLToPath } = require('bare-url')
@@ -737,31 +737,36 @@ 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 ((await stat(filepath)).isDirectory()) {
745
+ if (err.code !== 'ENOENT' && (await stat(filepath)).isDirectory()) {
757
746
  return ok(cb)
758
747
  }
759
748
 
760
- return fail(err, cb)
749
+ while (filepath.endsWith(path.sep)) filepath = filepath.slice(0, -1)
750
+ const i = filepath.lastIndexOf(path.sep)
751
+ if (i <= 0) return fail(err, cb)
752
+
753
+ await mkdir(filepath.slice(0, i), { mode, recursive: true })
754
+
755
+ try {
756
+ await mkdir(filepath, { mode })
757
+ } catch (err) {
758
+ if ((await stat(filepath)).isDirectory()) {
759
+ return ok(cb)
760
+ }
761
+
762
+ return fail(err, cb)
763
+ }
761
764
  }
765
+ } catch (e) {
766
+ err = e
762
767
  }
763
768
 
764
- return ok(cb)
769
+ return done(err, cb)
765
770
  }
766
771
 
767
772
  using req = FileRequest.borrow()
@@ -878,6 +883,7 @@ async function rm(filepath, opts, cb) {
878
883
 
879
884
  filepath = toNamespacedPath(filepath)
880
885
 
886
+ let err = null
881
887
  try {
882
888
  const st = await lstat(filepath)
883
889
 
@@ -897,21 +903,20 @@ async function rm(filepath, opts, cb) {
897
903
  await rmdir(filepath)
898
904
  }
899
905
  } else {
900
- fail(
901
- new FileError('is a directory', {
902
- operation: 'rm',
903
- code: 'EISDIR',
904
- path: filepath
905
- }),
906
- cb
907
- )
906
+ throw new FileError('is a directory', {
907
+ operation: 'rm',
908
+ code: 'EISDIR',
909
+ path: filepath
910
+ })
908
911
  }
909
912
  } else {
910
913
  await unlink(filepath)
911
914
  }
912
- } catch (err) {
913
- if (err.code !== 'ENOENT' || !opts.force) fail(err, cb)
915
+ } catch (e) {
916
+ if (e.code !== 'ENOENT' || !opts.force) err = e
914
917
  }
918
+
919
+ return done(err, cb)
915
920
  }
916
921
 
917
922
  function rmSync(filepath, opts) {
@@ -1683,7 +1688,7 @@ class Dir {
1683
1688
 
1684
1689
  this._encoding = encoding
1685
1690
  this._capacity = bufferSize
1686
- this._buffer = new FastFIFO()
1691
+ this._buffer = new FIFO()
1687
1692
  this._ended = false
1688
1693
  this._handle = handle
1689
1694
  }
@@ -1869,7 +1874,9 @@ class Dirent {
1869
1874
 
1870
1875
  class FileReadStream extends Readable {
1871
1876
  constructor(path, opts = {}) {
1872
- super()
1877
+ const { eagerOpen = true } = opts
1878
+
1879
+ super({ eagerOpen, ...opts })
1873
1880
 
1874
1881
  this.path = path
1875
1882
  this.fd = typeof opts.fd === 'number' ? opts.fd : -1
@@ -1965,7 +1972,9 @@ class FileReadStream extends Readable {
1965
1972
 
1966
1973
  class FileWriteStream extends Writable {
1967
1974
  constructor(path, opts = {}) {
1968
- super({ map })
1975
+ const { eagerOpen = true } = opts
1976
+
1977
+ super({ eagerOpen, ...opts })
1969
1978
 
1970
1979
  this.path = path
1971
1980
  this.fd = typeof opts.fd === 'number' ? opts.fd : -1
@@ -2237,10 +2246,6 @@ exports.createWriteStream = function createWriteStream(path, opts) {
2237
2246
  return new FileWriteStream(path, opts)
2238
2247
  }
2239
2248
 
2240
- function map(data) {
2241
- return typeof data === 'string' ? Buffer.from(data) : data
2242
- }
2243
-
2244
2249
  function toNamespacedPath(filepath) {
2245
2250
  if (typeof filepath !== 'string') {
2246
2251
  if (URL.isURL(filepath)) filepath = fileURLToPath(filepath)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-fs",
3
- "version": "4.4.4",
3
+ "version": "4.4.6",
4
4
  "description": "Native file system operations for Javascript",
5
5
  "exports": {
6
6
  "./package": "./package.json",