bare-fs 4.7.0 → 4.7.2

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.d.ts CHANGED
@@ -7,9 +7,9 @@ import constants from './lib/constants'
7
7
 
8
8
  export { promises, constants }
9
9
 
10
- type Path = string | Buffer | URL
10
+ export type Path = string | Buffer | URL
11
11
 
12
- type Flag =
12
+ export type Flag =
13
13
  | 'a'
14
14
  | 'a+'
15
15
  | 'as'
@@ -55,7 +55,7 @@ export class Dir {
55
55
  }
56
56
 
57
57
  export interface Dirent<T extends string | Buffer = string | Buffer> {
58
- readonly path: string
58
+ readonly parentPath: string
59
59
  readonly name: T
60
60
  readonly type: number
61
61
 
@@ -69,7 +69,7 @@ export interface Dirent<T extends string | Buffer = string | Buffer> {
69
69
  }
70
70
 
71
71
  export class Dirent<T extends string | Buffer = string | Buffer> {
72
- private constructor(path: string, name: T, type: number)
72
+ private constructor(parentPath: string, name: T, type: number)
73
73
  }
74
74
 
75
75
  export interface Stats {
@@ -83,10 +83,14 @@ export interface Stats {
83
83
  readonly ino: number
84
84
  readonly size: number
85
85
  readonly blocks: number
86
- readonly atimeMs: Date
87
- readonly mtimeMs: Date
88
- readonly ctimeMs: Date
89
- readonly birthtimeMs: Date
86
+ readonly atimeMs: number
87
+ readonly mtimeMs: number
88
+ readonly ctimeMs: number
89
+ readonly birthtimeMs: number
90
+ readonly atime: Date
91
+ readonly mtime: Date
92
+ readonly ctime: Date
93
+ readonly birthtime: Date
90
94
 
91
95
  isDirectory(): boolean
92
96
  isFile(): boolean
@@ -126,7 +130,7 @@ export interface StatFs {
126
130
  readonly ffree: number
127
131
  }
128
132
 
129
- export class StatsFs {
133
+ export class StatFs {
130
134
  private constructor(
131
135
  type: number,
132
136
  bsize: number,
@@ -154,7 +158,7 @@ export interface ReadStream extends Readable {
154
158
  }
155
159
 
156
160
  export class ReadStream {
157
- private constructor(path: Path | null, opts?: WriteStreamOptions)
161
+ private constructor(path: Path | null, opts?: ReadStreamOptions)
158
162
  }
159
163
 
160
164
  export function createReadStream(path: Path | null, opts?: ReadStreamOptions): ReadStream
@@ -644,12 +648,12 @@ export interface ReaddirOptions extends OpendirOptions {
644
648
  export function readdir(
645
649
  filepath: Path,
646
650
  opts: ReaddirOptions & { encoding?: BufferEncoding }
647
- ): Promise<Dir<string>[] | string[]>
651
+ ): Promise<Dirent<string>[] | string[]>
648
652
 
649
653
  export function readdir(
650
654
  filepath: Path,
651
655
  opts: ReaddirOptions & { encoding?: BufferEncoding; withFileTypes: true }
652
- ): Promise<Dir<string>[]>
656
+ ): Promise<Dirent<string>[]>
653
657
 
654
658
  export function readdir(
655
659
  filepath: Path,
@@ -659,12 +663,12 @@ export function readdir(
659
663
  export function readdir(
660
664
  filepath: Path,
661
665
  opts: ReaddirOptions & { encoding: 'buffer' }
662
- ): Promise<Dir<Buffer>[] | Buffer[]>
666
+ ): Promise<Dirent<Buffer>[] | Buffer[]>
663
667
 
664
668
  export function readdir(
665
669
  filepath: Path,
666
670
  opts: ReaddirOptions & { encoding: 'buffer'; withFileTypes: true }
667
- ): Promise<Dir<Buffer>[]>
671
+ ): Promise<Dirent<Buffer>[]>
668
672
 
669
673
  export function readdir(
670
674
  filepath: Path,
@@ -674,14 +678,17 @@ export function readdir(
674
678
  export function readdir(
675
679
  filepath: Path,
676
680
  opts: ReaddirOptions & { withFileTypes: true }
677
- ): Promise<Dir<string | Buffer>[]>
681
+ ): Promise<Dirent<string | Buffer>[]>
678
682
 
679
683
  export function readdir(
680
684
  filepath: Path,
681
685
  opts: ReaddirOptions & { withFileTypes?: false }
682
686
  ): Promise<string[] | Buffer[]>
683
687
 
684
- export function readdir(filepath: Path, opts: ReaddirOptions): Promise<Dir[] | string[] | Buffer[]>
688
+ export function readdir(
689
+ filepath: Path,
690
+ opts: ReaddirOptions
691
+ ): Promise<Dirent[] | string[] | Buffer[]>
685
692
 
686
693
  export function readdir(filepath: Path, encoding: BufferEncoding): Promise<string[]>
687
694
 
@@ -697,13 +704,13 @@ export function readdir(filepath: Path): Promise<string[]>
697
704
  export function readdir(
698
705
  filepath: Path,
699
706
  opts: ReaddirOptions & { encoding?: BufferEncoding },
700
- cb: Callback<[entries: Dir<string>[] | string[] | null]>
707
+ cb: Callback<[entries: Dirent<string>[] | string[] | null]>
701
708
  ): void
702
709
 
703
710
  export function readdir(
704
711
  filepath: Path,
705
712
  opts: ReaddirOptions & { encoding?: BufferEncoding; withFileTypes: true },
706
- cb: Callback<[entries: Dir<string>[] | null]>
713
+ cb: Callback<[entries: Dirent<string>[] | null]>
707
714
  ): void
708
715
 
709
716
  export function readdir(
@@ -715,13 +722,13 @@ export function readdir(
715
722
  export function readdir(
716
723
  filepath: Path,
717
724
  opts: ReaddirOptions & { encoding: 'buffer' },
718
- cb: Callback<[entries: Dir<Buffer>[] | Buffer[] | null]>
725
+ cb: Callback<[entries: Dirent<Buffer>[] | Buffer[] | null]>
719
726
  ): void
720
727
 
721
728
  export function readdir(
722
729
  filepath: Path,
723
730
  opts: ReaddirOptions & { encoding: 'buffer'; withFileTypes: true },
724
- cb: Callback<[entries: Dir<Buffer>[] | null]>
731
+ cb: Callback<[entries: Dirent<Buffer>[] | null]>
725
732
  ): void
726
733
 
727
734
  export function readdir(
@@ -733,7 +740,7 @@ export function readdir(
733
740
  export function readdir(
734
741
  filepath: Path,
735
742
  opts: ReaddirOptions & { withFileTypes: true },
736
- cb: Callback<[entries: Dir<string | Buffer>[] | null]>
743
+ cb: Callback<[entries: Dirent<string | Buffer>[] | null]>
737
744
  ): void
738
745
 
739
746
  export function readdir(
@@ -745,7 +752,7 @@ export function readdir(
745
752
  export function readdir(
746
753
  filepath: Path,
747
754
  opts: ReaddirOptions,
748
- cb: Callback<[entries: Dir[] | string[] | Buffer[] | null]>
755
+ cb: Callback<[entries: Dirent[] | string[] | Buffer[] | null]>
749
756
  ): void
750
757
 
751
758
  export function readdir(
@@ -771,12 +778,12 @@ export function readdir(filepath: Path, cb: Callback<[entries: string[] | null]>
771
778
  export function readdirSync(
772
779
  filepath: Path,
773
780
  opts: ReaddirOptions & { encoding?: BufferEncoding }
774
- ): Dir<string>[] | string[]
781
+ ): Dirent<string>[] | string[]
775
782
 
776
783
  export function readdirSync(
777
784
  filepath: Path,
778
785
  opts: ReaddirOptions & { encoding?: BufferEncoding; withFileTypes: true }
779
- ): Dir<string>[]
786
+ ): Dirent<string>[]
780
787
 
781
788
  export function readdirSync(
782
789
  filepath: Path,
@@ -786,12 +793,12 @@ export function readdirSync(
786
793
  export function readdirSync(
787
794
  filepath: Path,
788
795
  opts: ReaddirOptions & { encoding: 'buffer' }
789
- ): Dir<Buffer>[] | Buffer[]
796
+ ): Dirent<Buffer>[] | Buffer[]
790
797
 
791
798
  export function readdirSync(
792
799
  filepath: Path,
793
800
  opts: ReaddirOptions & { encoding: 'buffer'; withFileTypes: true }
794
- ): Dir<Buffer>[]
801
+ ): Dirent<Buffer>[]
795
802
 
796
803
  export function readdirSync(
797
804
  filepath: Path,
@@ -801,14 +808,14 @@ export function readdirSync(
801
808
  export function readdirSync(
802
809
  filepath: Path,
803
810
  opts: ReaddirOptions & { withFileTypes: true }
804
- ): Dir<string | Buffer>[]
811
+ ): Dirent<string | Buffer>[]
805
812
 
806
813
  export function readdirSync(
807
814
  filepath: Path,
808
815
  opts: ReaddirOptions & { withFileTypes?: false }
809
816
  ): string[] | Buffer[]
810
817
 
811
- export function readdirSync(filepath: Path, opts: ReaddirOptions): Dir[] | string[] | Buffer[]
818
+ export function readdirSync(filepath: Path, opts: ReaddirOptions): Dirent[] | string[] | Buffer[]
812
819
 
813
820
  export function readdirSync(filepath: Path, encoding: BufferEncoding): string[]
814
821
 
@@ -998,11 +1005,11 @@ export function realpathSync(filepath: Path, encoding: BufferEncoding | 'buffer'
998
1005
 
999
1006
  export function realpathSync(filepath: Path): string
1000
1007
 
1001
- export function rename(src: string, dst: string): Promise<void>
1008
+ export function rename(src: Path, dst: Path): Promise<void>
1002
1009
 
1003
- export function rename(src: string, dst: string, cb: Callback): void
1010
+ export function rename(src: Path, dst: Path, cb: Callback): void
1004
1011
 
1005
- export function renameSync(src: string, dst: string): void
1012
+ export function renameSync(src: Path, dst: Path): void
1006
1013
 
1007
1014
  export interface RmOptions {
1008
1015
  force?: boolean
@@ -1017,6 +1024,8 @@ export function rm(filepath: Path, cb: Callback): void
1017
1024
 
1018
1025
  export function rmSync(filepath: Path, opts?: RmOptions): void
1019
1026
 
1027
+ export function rmdir(filepath: Path): Promise<void>
1028
+
1020
1029
  export function rmdir(filepath: Path, cb: Callback): void
1021
1030
 
1022
1031
  export function rmdirSync(filepath: Path): void
@@ -1037,9 +1046,9 @@ export function symlink(target: Path, filepath: Path, type?: string | number): P
1037
1046
 
1038
1047
  export function symlink(target: Path, filepath: Path, type: string | number, cb: Callback): void
1039
1048
 
1040
- export function symlink(target: string, filepath: Path, cb: Callback): void
1049
+ export function symlink(target: Path, filepath: Path, cb: Callback): void
1041
1050
 
1042
- export function symlinkSync(target: string, filepath: Path, type?: string | number): void
1051
+ export function symlinkSync(target: Path, filepath: Path, type?: string | number): void
1043
1052
 
1044
1053
  export function truncate(filepath: Path, len?: number): Promise<void>
1045
1054
 
@@ -1076,19 +1085,19 @@ export function watch(
1076
1085
  export function watch(
1077
1086
  filepath: Path,
1078
1087
  encoding: BufferEncoding,
1079
- cb: (evenType: WatcherEventType, filename: string) => void
1088
+ cb: (eventType: WatcherEventType, filename: string) => void
1080
1089
  ): Watcher<string>
1081
1090
 
1082
1091
  export function watch(
1083
1092
  filepath: Path,
1084
1093
  encoding: 'buffer',
1085
- cb: (evenType: WatcherEventType, filename: Buffer) => void
1094
+ cb: (eventType: WatcherEventType, filename: Buffer) => void
1086
1095
  ): Watcher<Buffer>
1087
1096
 
1088
1097
  export function watch(
1089
1098
  filepath: Path,
1090
1099
  encoding: BufferEncoding | 'buffer',
1091
- cb: (evenType: WatcherEventType, filename: string | Buffer) => void
1100
+ cb: (eventType: WatcherEventType, filename: string | Buffer) => void
1092
1101
  ): Watcher
1093
1102
 
1094
1103
  export function watch(
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.2",
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
package/promises.d.ts CHANGED
@@ -5,6 +5,8 @@ import {
5
5
  AppendFileOptions,
6
6
  CpOptions,
7
7
  Dir,
8
+ Dirent,
9
+ Flag,
8
10
  MkdirOptions,
9
11
  OpendirOptions,
10
12
  Path,
@@ -15,6 +17,7 @@ import {
15
17
  ReadlinkOptions,
16
18
  RealpathOptions,
17
19
  RmOptions,
20
+ StatFs,
18
21
  Stats,
19
22
  Watcher,
20
23
  WatcherOptions,