bare-fs 4.7.0 → 4.7.1

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 CHANGED
@@ -540,7 +540,8 @@ Options include:
540
540
  ```js
541
541
  options = {
542
542
  encoding: 'utf8',
543
- withFileTypes: false
543
+ withFileTypes: false,
544
+ recursive: false
544
545
  }
545
546
  ```
546
547
 
package/index.js CHANGED
@@ -286,6 +286,8 @@ async function read(fd, buffer, offset = 0, len = buffer.byteLength - offset, po
286
286
  try {
287
287
  binding.read(req.handle, fd, buffer, offset, len, pos)
288
288
 
289
+ req.retain(buffer)
290
+
289
291
  bytes = await req
290
292
  } catch (e) {
291
293
  err = new FileError(e.message, { operation: 'read', code: e.code, fd })
@@ -323,6 +325,8 @@ async function readv(fd, buffers, pos = -1, cb) {
323
325
  try {
324
326
  binding.readv(req.handle, fd, buffers, pos)
325
327
 
328
+ req.retain(buffers)
329
+
326
330
  bytes = await req
327
331
  } catch (e) {
328
332
  err = new FileError(e.message, { operation: 'readv', code: e.code, fd })
@@ -395,6 +399,8 @@ async function write(fd, data, offset, len, pos = -1, cb) {
395
399
  try {
396
400
  binding.write(req.handle, fd, data, offset, len, pos)
397
401
 
402
+ req.retain(data)
403
+
398
404
  bytes = await req
399
405
  } catch (e) {
400
406
  err = new FileError(e.message, { operation: 'write', code: e.code, fd })
@@ -450,6 +456,8 @@ async function writev(fd, buffers, pos = -1, cb) {
450
456
  try {
451
457
  binding.writev(req.handle, fd, buffers, pos)
452
458
 
459
+ req.retain(buffers)
460
+
453
461
  bytes = await req
454
462
  } catch (e) {
455
463
  err = new FileError(e.message, { operation: 'writev', code: e.code, fd })
@@ -1878,17 +1886,28 @@ async function readdir(filepath, opts, cb) {
1878
1886
  if (typeof opts === 'string') opts = { encoding: opts }
1879
1887
  else if (!opts) opts = {}
1880
1888
 
1881
- const { withFileTypes = false } = opts
1889
+ const { withFileTypes = false, recursive = false } = opts
1882
1890
 
1883
1891
  filepath = toNamespacedPath(filepath)
1884
1892
 
1893
+ const queue = [filepath]
1885
1894
  let result = []
1886
1895
  let err = null
1887
1896
  try {
1888
- const dir = await opendir(filepath)
1897
+ while (queue.length !== 0) {
1898
+ const dir = await opendir(queue.pop())
1899
+
1900
+ for await (const entry of dir) {
1901
+ const entryPath = path.join(entry.parentPath, entry.name)
1902
+
1903
+ if (withFileTypes) {
1904
+ result.push(entry)
1905
+ } else {
1906
+ result.push(path.relative(filepath, entryPath))
1907
+ }
1889
1908
 
1890
- for await (const entry of dir) {
1891
- result.push(withFileTypes ? entry : entry.name)
1909
+ if (recursive && entry.isDirectory()) queue.push(entryPath)
1910
+ }
1892
1911
  }
1893
1912
  } catch (e) {
1894
1913
  result = []
@@ -1902,15 +1921,27 @@ function readdirSync(filepath, opts) {
1902
1921
  if (typeof opts === 'string') opts = { encoding: opts }
1903
1922
  else if (!opts) opts = {}
1904
1923
 
1905
- const { withFileTypes = false } = opts
1924
+ const { withFileTypes = false, recursive = false } = opts
1906
1925
 
1907
1926
  filepath = toNamespacedPath(filepath)
1908
1927
 
1909
- const dir = opendirSync(filepath, opts)
1928
+ const queue = [filepath]
1910
1929
  const result = []
1911
1930
 
1912
- for (const entry of dir) {
1913
- result.push(withFileTypes ? entry : entry.name)
1931
+ while (queue.length !== 0) {
1932
+ const dir = opendirSync(queue.pop(), opts)
1933
+
1934
+ for (const entry of dir) {
1935
+ const entryPath = path.join(entry.parentPath, entry.name)
1936
+
1937
+ if (withFileTypes) {
1938
+ result.push(entry)
1939
+ } else {
1940
+ result.push(path.relative(filepath, entryPath))
1941
+ }
1942
+
1943
+ if (recursive && entry.isDirectory()) queue.push(entryPath)
1944
+ }
1914
1945
  }
1915
1946
 
1916
1947
  return result
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-fs",
3
- "version": "4.7.0",
3
+ "version": "4.7.1",
4
4
  "description": "Native file system operations for Bare",
5
5
  "exports": {
6
6
  "./package": "./package.json",
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file