bare-fs 4.4.10 → 4.5.0

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.d.ts CHANGED
@@ -136,10 +136,7 @@ export class ReadStream {
136
136
  private constructor(path: Path | null, opts?: WriteStreamOptions)
137
137
  }
138
138
 
139
- export function createReadStream(
140
- path: Path | null,
141
- opts?: ReadStreamOptions
142
- ): ReadStream
139
+ export function createReadStream(path: Path | null, opts?: ReadStreamOptions): ReadStream
143
140
 
144
141
  export interface WriteStreamOptions {
145
142
  fd?: number
@@ -158,10 +155,7 @@ export class WriteStream {
158
155
  private constructor(path: Path | null, opts?: WriteStreamOptions)
159
156
  }
160
157
 
161
- export function createWriteStream(
162
- path: Path | null,
163
- opts?: WriteStreamOptions
164
- ): WriteStream
158
+ export function createWriteStream(path: Path | null, opts?: WriteStreamOptions): WriteStream
165
159
 
166
160
  export interface WatcherOptions {
167
161
  persistent?: boolean
@@ -171,8 +165,7 @@ export interface WatcherOptions {
171
165
 
172
166
  export type WatcherEventType = 'rename' | 'change'
173
167
 
174
- export interface WatcherEvents<T extends string | Buffer = string | Buffer>
175
- extends EventMap {
168
+ export interface WatcherEvents<T extends string | Buffer = string | Buffer> extends EventMap {
176
169
  error: [err: Error]
177
170
  change: [eventType: WatcherEventType, filename: T]
178
171
  close: []
@@ -268,6 +261,16 @@ export function copyFile(src: Path, dst: Path, cb: Callback): void
268
261
 
269
262
  export function copyFileSync(src: Path, dst: Path, mode?: number): void
270
263
 
264
+ export interface CpOptions {
265
+ recursive?: boolean
266
+ }
267
+
268
+ export function cp(src: Path, dst: Path, opts?: CpOptions): Promise<void>
269
+
270
+ export function cp(src: Path, dst: Path, opts: CpOptions, cb: Callback): void
271
+
272
+ export function cp(src: Path, dst: Path, cb: Callback): void
273
+
271
274
  export function exists(filepath: Path): Promise<boolean>
272
275
 
273
276
  export function exists(filepath: Path, cb: (exists: boolean) => void): void
@@ -319,11 +322,7 @@ export function mkdirSync(filepath: Path, opts?: MkdirOptions): void
319
322
 
320
323
  export function mkdirSync(filepath: Path, mode: number): void
321
324
 
322
- export function open(
323
- filepath: Path,
324
- flags?: Flag | number,
325
- mode?: string | number
326
- ): Promise<number>
325
+ export function open(filepath: Path, flags?: Flag | number, mode?: string | number): Promise<number>
327
326
 
328
327
  export function open(
329
328
  filepath: Path,
@@ -332,19 +331,11 @@ export function open(
332
331
  cb: Callback<[fd: number]>
333
332
  ): void
334
333
 
335
- export function open(
336
- filepath: Path,
337
- flags: Flag | number,
338
- cb: Callback<[fd: number]>
339
- ): void
334
+ export function open(filepath: Path, flags: Flag | number, cb: Callback<[fd: number]>): void
340
335
 
341
336
  export function open(filepath: Path, cb: Callback<[fd: number]>): void
342
337
 
343
- export function openSync(
344
- filepath: Path,
345
- flags?: Flag | number,
346
- mode?: string | number
347
- ): number
338
+ export function openSync(filepath: Path, flags?: Flag | number, mode?: string | number): number
348
339
 
349
340
  export interface OpendirOptions {
350
341
  encoding?: BufferEncoding | 'buffer'
@@ -363,20 +354,11 @@ export function opendir(
363
354
 
364
355
  export function opendir(filepath: Path, opts: OpendirOptions): Promise<Dir>
365
356
 
366
- export function opendir(
367
- filepath: Path,
368
- encoding: BufferEncoding
369
- ): Promise<Dir<string>>
357
+ export function opendir(filepath: Path, encoding: BufferEncoding): Promise<Dir<string>>
370
358
 
371
- export function opendir(
372
- filepath: Path,
373
- encoding: 'buffer'
374
- ): Promise<Dir<Buffer>>
359
+ export function opendir(filepath: Path, encoding: 'buffer'): Promise<Dir<Buffer>>
375
360
 
376
- export function opendir(
377
- filepath: Path,
378
- encoding: BufferEncoding | 'buffer'
379
- ): Promise<Dir>
361
+ export function opendir(filepath: Path, encoding: BufferEncoding | 'buffer'): Promise<Dir>
380
362
 
381
363
  export function opendir(filepath: Path): Promise<Dir<string>>
382
364
 
@@ -392,11 +374,7 @@ export function opendir(
392
374
  cb: Callback<[dir: Dir<Buffer> | null]>
393
375
  ): void
394
376
 
395
- export function opendir(
396
- filepath: Path,
397
- opts: OpendirOptions,
398
- cb: Callback<[dir: Dir | null]>
399
- ): void
377
+ export function opendir(filepath: Path, opts: OpendirOptions, cb: Callback<[dir: Dir | null]>): void
400
378
 
401
379
  export function opendir(
402
380
  filepath: Path,
@@ -416,10 +394,7 @@ export function opendir(
416
394
  cb: Callback<[dir: Dir | null]>
417
395
  ): void
418
396
 
419
- export function opendir(
420
- filepath: Path,
421
- cb: Callback<[dir: Dir<string> | null]>
422
- ): void
397
+ export function opendir(filepath: Path, cb: Callback<[dir: Dir<string> | null]>): void
423
398
 
424
399
  export function opendirSync(
425
400
  filepath: Path,
@@ -433,17 +408,11 @@ export function opendirSync(
433
408
 
434
409
  export function opendirSync(filepath: Path, opts: OpendirOptions): Dir
435
410
 
436
- export function opendirSync(
437
- filepath: Path,
438
- encoding: BufferEncoding
439
- ): Dir<string>
411
+ export function opendirSync(filepath: Path, encoding: BufferEncoding): Dir<string>
440
412
 
441
413
  export function opendirSync(filepath: Path, encoding: 'buffer'): Dir<Buffer>
442
414
 
443
- export function opendirSync(
444
- filepath: Path,
445
- encoding: BufferEncoding | 'buffer'
446
- ): Dir
415
+ export function opendirSync(filepath: Path, encoding: BufferEncoding | 'buffer'): Dir
447
416
 
448
417
  export function opendirSync(filepath: Path): Dir<string>
449
418
 
@@ -508,15 +477,9 @@ export function readFile(
508
477
  opts: ReadFileOptions & { encoding?: 'buffer' }
509
478
  ): Promise<Buffer>
510
479
 
511
- export function readFile(
512
- filepath: Path,
513
- opts: ReadFileOptions
514
- ): Promise<string | Buffer>
480
+ export function readFile(filepath: Path, opts: ReadFileOptions): Promise<string | Buffer>
515
481
 
516
- export function readFile(
517
- filepath: Path,
518
- encoding: BufferEncoding
519
- ): Promise<string>
482
+ export function readFile(filepath: Path, encoding: BufferEncoding): Promise<string>
520
483
 
521
484
  export function readFile(filepath: Path, encoding: 'buffer'): Promise<Buffer>
522
485
 
@@ -551,11 +514,7 @@ export function readFile(
551
514
  cb: Callback<[buffer?: string]>
552
515
  ): void
553
516
 
554
- export function readFile(
555
- filepath: Path,
556
- encoding: 'buffer',
557
- cb: Callback<[buffer?: Buffer]>
558
- ): void
517
+ export function readFile(filepath: Path, encoding: 'buffer', cb: Callback<[buffer?: Buffer]>): void
559
518
 
560
519
  export function readFile(
561
520
  filepath: Path,
@@ -575,19 +534,13 @@ export function readFileSync(
575
534
  opts: ReadFileOptions & { encoding?: 'buffer' }
576
535
  ): Buffer
577
536
 
578
- export function readFileSync(
579
- filepath: Path,
580
- opts: ReadFileOptions
581
- ): string | Buffer
537
+ export function readFileSync(filepath: Path, opts: ReadFileOptions): string | Buffer
582
538
 
583
539
  export function readFileSync(filepath: Path, encoding: BufferEncoding): string
584
540
 
585
541
  export function readFileSync(filepath: Path, encoding: 'buffer'): Buffer
586
542
 
587
- export function readFileSync(
588
- filepath: Path,
589
- encoding?: BufferEncoding | 'buffer'
590
- ): string | Buffer
543
+ export function readFileSync(filepath: Path, encoding?: BufferEncoding | 'buffer'): string | Buffer
591
544
 
592
545
  export function readFileSync(filepath: Path): Buffer
593
546
 
@@ -634,15 +587,9 @@ export function readdir(
634
587
  opts: ReaddirOptions & { withFileTypes?: false }
635
588
  ): Promise<string[] | Buffer[]>
636
589
 
637
- export function readdir(
638
- filepath: Path,
639
- opts: ReaddirOptions
640
- ): Promise<Dir[] | string[] | Buffer[]>
590
+ export function readdir(filepath: Path, opts: ReaddirOptions): Promise<Dir[] | string[] | Buffer[]>
641
591
 
642
- export function readdir(
643
- filepath: Path,
644
- encoding: BufferEncoding
645
- ): Promise<string[]>
592
+ export function readdir(filepath: Path, encoding: BufferEncoding): Promise<string[]>
646
593
 
647
594
  export function readdir(filepath: Path, encoding: 'buffer'): Promise<Buffer[]>
648
595
 
@@ -725,10 +672,7 @@ export function readdir(
725
672
  cb: Callback<[entries: string[] | Buffer[] | null]>
726
673
  ): void
727
674
 
728
- export function readdir(
729
- filepath: Path,
730
- cb: Callback<[entries: string[] | null]>
731
- ): void
675
+ export function readdir(filepath: Path, cb: Callback<[entries: string[] | null]>): void
732
676
 
733
677
  export function readdirSync(
734
678
  filepath: Path,
@@ -770,10 +714,7 @@ export function readdirSync(
770
714
  opts: ReaddirOptions & { withFileTypes?: false }
771
715
  ): string[] | Buffer[]
772
716
 
773
- export function readdirSync(
774
- filepath: Path,
775
- opts: ReaddirOptions
776
- ): Dir[] | string[] | Buffer[]
717
+ export function readdirSync(filepath: Path, opts: ReaddirOptions): Dir[] | string[] | Buffer[]
777
718
 
778
719
  export function readdirSync(filepath: Path, encoding: BufferEncoding): string[]
779
720
 
@@ -800,15 +741,9 @@ export function readlink(
800
741
  opts: ReadlinkOptions & { encoding: 'buffer' }
801
742
  ): Promise<Buffer>
802
743
 
803
- export function readlink(
804
- filepath: Path,
805
- opts: ReadlinkOptions
806
- ): Promise<string | Buffer>
744
+ export function readlink(filepath: Path, opts: ReadlinkOptions): Promise<string | Buffer>
807
745
 
808
- export function readlink(
809
- filepath: Path,
810
- encoding: BufferEncoding
811
- ): Promise<string>
746
+ export function readlink(filepath: Path, encoding: BufferEncoding): Promise<string>
812
747
 
813
748
  export function readlink(filepath: Path, encoding: 'buffer'): Promise<Buffer>
814
749
 
@@ -855,42 +790,26 @@ export function readlink(
855
790
  cb: Callback<[link: string | Buffer | null]>
856
791
  ): void
857
792
 
858
- export function readlink(
859
- filepath: Path,
860
- cb: Callback<[link: string | null]>
861
- ): void
793
+ export function readlink(filepath: Path, cb: Callback<[link: string | null]>): void
862
794
 
863
795
  export function readlinkSync(
864
796
  filepath: Path,
865
797
  opts: ReadlinkOptions & { encoding?: BufferEncoding }
866
798
  ): string
867
799
 
868
- export function readlinkSync(
869
- filepath: Path,
870
- opts: ReadlinkOptions & { encoding: 'buffer' }
871
- ): Buffer
800
+ export function readlinkSync(filepath: Path, opts: ReadlinkOptions & { encoding: 'buffer' }): Buffer
872
801
 
873
- export function readlinkSync(
874
- filepath: Path,
875
- opts: ReadlinkOptions
876
- ): string | Buffer
802
+ export function readlinkSync(filepath: Path, opts: ReadlinkOptions): string | Buffer
877
803
 
878
804
  export function readlinkSync(filepath: Path, encoding: BufferEncoding): string
879
805
 
880
806
  export function readlinkSync(filepath: Path, encoding: 'buffer'): Buffer
881
807
 
882
- export function readlinkSync(
883
- filepath: Path,
884
- encoding: BufferEncoding | 'buffer'
885
- ): string | Buffer
808
+ export function readlinkSync(filepath: Path, encoding: BufferEncoding | 'buffer'): string | Buffer
886
809
 
887
810
  export function readlinkSync(filepath: Path): string
888
811
 
889
- export function readv(
890
- fd: number,
891
- buffers: ArrayBufferView[],
892
- position?: number
893
- ): Promise<number>
812
+ export function readv(fd: number, buffers: ArrayBufferView[], position?: number): Promise<number>
894
813
 
895
814
  export function readv(
896
815
  fd: number,
@@ -899,17 +818,9 @@ export function readv(
899
818
  cb: Callback<[len: number]>
900
819
  ): void
901
820
 
902
- export function readv(
903
- fd: number,
904
- buffers: ArrayBufferView[],
905
- cb: Callback<[len: number]>
906
- ): void
821
+ export function readv(fd: number, buffers: ArrayBufferView[], cb: Callback<[len: number]>): void
907
822
 
908
- export function readvSync(
909
- fd: number,
910
- buffers: ArrayBufferView[],
911
- position?: number
912
- ): number
823
+ export function readvSync(fd: number, buffers: ArrayBufferView[], position?: number): number
913
824
 
914
825
  export interface RealpathOptions {
915
826
  encoding?: BufferEncoding | 'buffer'
@@ -925,15 +836,9 @@ export function realpath(
925
836
  opts: RealpathOptions & { encoding: 'buffer' }
926
837
  ): Promise<Buffer>
927
838
 
928
- export function realpath(
929
- filepath: Path,
930
- opts: RealpathOptions
931
- ): Promise<string | Buffer>
839
+ export function realpath(filepath: Path, opts: RealpathOptions): Promise<string | Buffer>
932
840
 
933
- export function realpath(
934
- filepath: Path,
935
- encoding: BufferEncoding
936
- ): Promise<string>
841
+ export function realpath(filepath: Path, encoding: BufferEncoding): Promise<string>
937
842
 
938
843
  export function realpath(filepath: Path, encoding: 'buffer'): Promise<Buffer>
939
844
 
@@ -980,34 +885,22 @@ export function realpath(
980
885
  cb: Callback<[path: string | Buffer | null]>
981
886
  ): void
982
887
 
983
- export function realpath(
984
- filepath: Path,
985
- cb: Callback<[path: string | null]>
986
- ): void
888
+ export function realpath(filepath: Path, cb: Callback<[path: string | null]>): void
987
889
 
988
890
  export function realpathSync(
989
891
  filepath: Path,
990
892
  opts: RealpathOptions & { encoding?: BufferEncoding }
991
893
  ): string
992
894
 
993
- export function realpathSync(
994
- filepath: Path,
995
- opts: RealpathOptions & { encoding: 'buffer' }
996
- ): Buffer
895
+ export function realpathSync(filepath: Path, opts: RealpathOptions & { encoding: 'buffer' }): Buffer
997
896
 
998
- export function realpathSync(
999
- filepath: Path,
1000
- opts: RealpathOptions
1001
- ): string | Buffer
897
+ export function realpathSync(filepath: Path, opts: RealpathOptions): string | Buffer
1002
898
 
1003
899
  export function realpathSync(filepath: Path, encoding: BufferEncoding): string
1004
900
 
1005
901
  export function realpathSync(filepath: Path, encoding: 'buffer'): Buffer
1006
902
 
1007
- export function realpathSync(
1008
- filepath: Path,
1009
- encoding: BufferEncoding | 'buffer'
1010
- ): string | Buffer
903
+ export function realpathSync(filepath: Path, encoding: BufferEncoding | 'buffer'): string | Buffer
1011
904
 
1012
905
  export function realpathSync(filepath: Path): string
1013
906
 
@@ -1040,26 +933,13 @@ export function stat(filepath: Path, cb: Callback<[stats: Stats | null]>): void
1040
933
 
1041
934
  export function statSync(filepath: Path): Stats
1042
935
 
1043
- export function symlink(
1044
- target: Path,
1045
- filepath: Path,
1046
- type?: string | number
1047
- ): Promise<void>
936
+ export function symlink(target: Path, filepath: Path, type?: string | number): Promise<void>
1048
937
 
1049
- export function symlink(
1050
- target: Path,
1051
- filepath: Path,
1052
- type: string | number,
1053
- cb: Callback
1054
- ): void
938
+ export function symlink(target: Path, filepath: Path, type: string | number, cb: Callback): void
1055
939
 
1056
940
  export function symlink(target: string, filepath: Path, cb: Callback): void
1057
941
 
1058
- export function symlinkSync(
1059
- target: string,
1060
- filepath: Path,
1061
- type?: string | number
1062
- ): void
942
+ export function symlinkSync(target: string, filepath: Path, type?: string | number): void
1063
943
 
1064
944
  export function unlink(filepath: Path): Promise<void>
1065
945
 
@@ -1155,24 +1035,11 @@ export function write(
1155
1035
  cb: Callback<[len: number]>
1156
1036
  ): void
1157
1037
 
1158
- export function write(
1159
- fd: number,
1160
- data: string,
1161
- pos: number,
1162
- cb: Callback<[len: number]>
1163
- ): void
1038
+ export function write(fd: number, data: string, pos: number, cb: Callback<[len: number]>): void
1164
1039
 
1165
- export function write(
1166
- fd: number,
1167
- data: Buffer | ArrayBufferView,
1168
- cb: Callback<[len: number]>
1169
- ): void
1040
+ export function write(fd: number, data: Buffer | ArrayBufferView, cb: Callback<[len: number]>): void
1170
1041
 
1171
- export function write(
1172
- fd: number,
1173
- data: string,
1174
- cb: Callback<[len: number]>
1175
- ): void
1042
+ export function write(fd: number, data: string, cb: Callback<[len: number]>): void
1176
1043
 
1177
1044
  export function writeSync(
1178
1045
  fd: number,
@@ -1182,12 +1049,7 @@ export function writeSync(
1182
1049
  pos?: number
1183
1050
  ): number
1184
1051
 
1185
- export function writeSync(
1186
- fd: number,
1187
- data: string,
1188
- pos?: number,
1189
- encoding?: BufferEncoding
1190
- ): number
1052
+ export function writeSync(fd: number, data: string, pos?: number, encoding?: BufferEncoding): number
1191
1053
 
1192
1054
  export interface WriteFileOptions {
1193
1055
  encoding?: BufferEncoding
@@ -1239,11 +1101,7 @@ export function writeFileSync(
1239
1101
  encoding: BufferEncoding
1240
1102
  ): void
1241
1103
 
1242
- export function writev(
1243
- fd: number,
1244
- buffers: ArrayBufferView[],
1245
- pos?: number
1246
- ): Promise<number>
1104
+ export function writev(fd: number, buffers: ArrayBufferView[], pos?: number): Promise<number>
1247
1105
 
1248
1106
  export function writev(
1249
1107
  fd: number,
@@ -1252,14 +1110,6 @@ export function writev(
1252
1110
  cb: Callback<[len: number]>
1253
1111
  ): void
1254
1112
 
1255
- export function writev(
1256
- fd: number,
1257
- buffers: ArrayBufferView[],
1258
- cb: Callback<[len: number]>
1259
- ): void
1113
+ export function writev(fd: number, buffers: ArrayBufferView[], cb: Callback<[len: number]>): void
1260
1114
 
1261
- export function writevSync(
1262
- fd: number,
1263
- buffers: ArrayBufferView[],
1264
- pos?: number
1265
- ): number
1115
+ export function writevSync(fd: number, buffers: ArrayBufferView[], pos?: number): number
package/index.js CHANGED
@@ -255,14 +255,7 @@ function existsSync(filepath) {
255
255
  return true
256
256
  }
257
257
 
258
- async function read(
259
- fd,
260
- buffer,
261
- offset = 0,
262
- len = buffer.byteLength - offset,
263
- pos = -1,
264
- cb
265
- ) {
258
+ async function read(fd, buffer, offset = 0, len = buffer.byteLength - offset, pos = -1, cb) {
266
259
  if (typeof offset === 'function') {
267
260
  cb = offset
268
261
  offset = 0
@@ -294,13 +287,7 @@ async function read(
294
287
  return done(err, bytes, cb)
295
288
  }
296
289
 
297
- function readSync(
298
- fd,
299
- buffer,
300
- offset = 0,
301
- len = buffer.byteLength - offset,
302
- pos = -1
303
- ) {
290
+ function readSync(fd, buffer, offset = 0, len = buffer.byteLength - offset, pos = -1) {
304
291
  using req = FileRequest.borrow()
305
292
 
306
293
  try {
@@ -1073,6 +1060,55 @@ function copyFileSync(src, dst, mode = 0) {
1073
1060
  }
1074
1061
  }
1075
1062
 
1063
+ async function cp(src, dst, opts, cb) {
1064
+ if (typeof opts === 'function') {
1065
+ cb = opts
1066
+ opts = {}
1067
+ }
1068
+
1069
+ if (!opts) opts = {}
1070
+
1071
+ src = toNamespacedPath(src)
1072
+ dst = toNamespacedPath(dst)
1073
+
1074
+ let err = null
1075
+ try {
1076
+ const st = await lstat(src)
1077
+
1078
+ if (st.isDirectory()) {
1079
+ if (opts.recursive !== true) {
1080
+ throw new FileError('is a directory', {
1081
+ operation: 'cp',
1082
+ code: 'EISDIR',
1083
+ path: src
1084
+ })
1085
+ }
1086
+
1087
+ try {
1088
+ await lstat(dst)
1089
+ } catch (e) {
1090
+ if (e.code === 'ENOENT') {
1091
+ await mkdir(dst, { mode: st.mode, recursive: true })
1092
+ } else {
1093
+ throw e
1094
+ }
1095
+ }
1096
+
1097
+ const dir = await opendir(src)
1098
+ for await (const { name } of dir) {
1099
+ await cp(path.join(src, name), path.join(dst, name), opts)
1100
+ }
1101
+ } else if (st.isFile()) {
1102
+ await copyFile(src, dst)
1103
+ await chmod(dst, st.mode)
1104
+ }
1105
+ } catch (e) {
1106
+ err = e
1107
+ }
1108
+
1109
+ return done(err, cb)
1110
+ }
1111
+
1076
1112
  async function realpath(filepath, opts, cb) {
1077
1113
  if (typeof opts === 'function') {
1078
1114
  cb = opts
@@ -1540,7 +1576,7 @@ async function writeFile(filepath, data, opts, cb) {
1540
1576
  len += await write(fd, len ? data.subarray(len) : data)
1541
1577
  if (len === data.byteLength) break
1542
1578
  }
1543
- } catch (err) {
1579
+ } catch (e) {
1544
1580
  err = e
1545
1581
  } finally {
1546
1582
  if (fd !== -1) await close(fd)
@@ -2031,13 +2067,7 @@ class Watcher extends EventEmitter {
2031
2067
 
2032
2068
  this._closed = false
2033
2069
  this._encoding = encoding
2034
- this._handle = binding.watcherInit(
2035
- path,
2036
- recursive,
2037
- this,
2038
- this._onevent,
2039
- this._onclose
2040
- )
2070
+ this._handle = binding.watcherInit(path, recursive, this, this._onevent, this._onclose)
2041
2071
 
2042
2072
  if (!persistent) this.unref()
2043
2073
 
@@ -2098,8 +2128,7 @@ class Watcher extends EventEmitter {
2098
2128
  new Promise((resolve, reject) => {
2099
2129
  if (error) return reject(error)
2100
2130
 
2101
- if (buffer.length)
2102
- return resolve({ done: false, value: buffer.shift() })
2131
+ if (buffer.length) return resolve({ done: false, value: buffer.shift() })
2103
2132
 
2104
2133
  if (done) return resolve({ done })
2105
2134
 
@@ -2141,6 +2170,7 @@ exports.chmod = chmod
2141
2170
  // exports.chown = chown TODO
2142
2171
  exports.close = close
2143
2172
  exports.copyFile = copyFile
2173
+ exports.cp = cp
2144
2174
  exports.exists = exists
2145
2175
  exports.fchmod = fchmod
2146
2176
  // exports.fchown = fchown TODO
@@ -2265,61 +2295,31 @@ function toFlags(flags) {
2265
2295
  return constants.O_TRUNC | constants.O_CREAT | constants.O_WRONLY
2266
2296
  case 'wx': // Fall through.
2267
2297
  case 'xw':
2268
- return (
2269
- constants.O_TRUNC |
2270
- constants.O_CREAT |
2271
- constants.O_WRONLY |
2272
- constants.O_EXCL
2273
- )
2298
+ return constants.O_TRUNC | constants.O_CREAT | constants.O_WRONLY | constants.O_EXCL
2274
2299
 
2275
2300
  case 'w+':
2276
2301
  return constants.O_TRUNC | constants.O_CREAT | constants.O_RDWR
2277
2302
  case 'wx+': // Fall through.
2278
2303
  case 'xw+':
2279
- return (
2280
- constants.O_TRUNC |
2281
- constants.O_CREAT |
2282
- constants.O_RDWR |
2283
- constants.O_EXCL
2284
- )
2304
+ return constants.O_TRUNC | constants.O_CREAT | constants.O_RDWR | constants.O_EXCL
2285
2305
 
2286
2306
  case 'a':
2287
2307
  return constants.O_APPEND | constants.O_CREAT | constants.O_WRONLY
2288
2308
  case 'ax': // Fall through.
2289
2309
  case 'xa':
2290
- return (
2291
- constants.O_APPEND |
2292
- constants.O_CREAT |
2293
- constants.O_WRONLY |
2294
- constants.O_EXCL
2295
- )
2310
+ return constants.O_APPEND | constants.O_CREAT | constants.O_WRONLY | constants.O_EXCL
2296
2311
  case 'as': // Fall through.
2297
2312
  case 'sa':
2298
- return (
2299
- constants.O_APPEND |
2300
- constants.O_CREAT |
2301
- constants.O_WRONLY |
2302
- constants.O_SYNC
2303
- )
2313
+ return constants.O_APPEND | constants.O_CREAT | constants.O_WRONLY | constants.O_SYNC
2304
2314
 
2305
2315
  case 'a+':
2306
2316
  return constants.O_APPEND | constants.O_CREAT | constants.O_RDWR
2307
2317
  case 'ax+': // Fall through.
2308
2318
  case 'xa+':
2309
- return (
2310
- constants.O_APPEND |
2311
- constants.O_CREAT |
2312
- constants.O_RDWR |
2313
- constants.O_EXCL
2314
- )
2319
+ return constants.O_APPEND | constants.O_CREAT | constants.O_RDWR | constants.O_EXCL
2315
2320
  case 'as+': // Fall through.
2316
2321
  case 'sa+':
2317
- return (
2318
- constants.O_APPEND |
2319
- constants.O_CREAT |
2320
- constants.O_RDWR |
2321
- constants.O_SYNC
2322
- )
2322
+ return constants.O_APPEND | constants.O_CREAT | constants.O_RDWR | constants.O_SYNC
2323
2323
  default:
2324
2324
  return 0
2325
2325
  }
package/lib/errors.js CHANGED
@@ -2,13 +2,7 @@ const os = require('bare-os')
2
2
 
3
3
  module.exports = class FileError extends Error {
4
4
  constructor(msg, opts = {}) {
5
- const {
6
- code,
7
- operation = null,
8
- path = null,
9
- destination = null,
10
- fd = -1
11
- } = opts
5
+ const { code, operation = null, path = null, destination = null, fd = -1 } = opts
12
6
 
13
7
  if (operation !== null) msg += describe(operation, opts)
14
8
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-fs",
3
- "version": "4.4.10",
3
+ "version": "4.5.0",
4
4
  "description": "Native file system operations for Javascript",
5
5
  "exports": {
6
6
  "./package": "./package.json",
@@ -58,7 +58,7 @@
58
58
  "brittle": "^3.1.1",
59
59
  "cmake-bare": "^1.1.7",
60
60
  "prettier": "^3.4.1",
61
- "prettier-config-standard": "^7.0.0"
61
+ "prettier-config-holepunch": "^2.0.0"
62
62
  },
63
63
  "peerDependencies": {
64
64
  "bare-buffer": "*"
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
@@ -3,6 +3,7 @@ import Buffer, { BufferEncoding } from 'bare-buffer'
3
3
  import {
4
4
  constants,
5
5
  AppendFileOptions,
6
+ CpOptions,
6
7
  Dir,
7
8
  MkdirOptions,
8
9
  OpendirOptions,
@@ -86,6 +87,8 @@ export function chmod(filepath: Path, mode: string | number): Promise<void>
86
87
 
87
88
  export function copyFile(src: Path, dst: Path, mode?: number): Promise<void>
88
89
 
90
+ export function cp(src: Path, dst: Path, opts?: CpOptions): Promise<void>
91
+
89
92
  export function lstat(filepath: Path): Promise<Stats>
90
93
 
91
94
  export function mkdir(filepath: Path, opts?: MkdirOptions): Promise<void>
@@ -104,20 +107,11 @@ export function opendir(
104
107
 
105
108
  export function opendir(filepath: Path, opts: OpendirOptions): Promise<Dir>
106
109
 
107
- export function opendir(
108
- filepath: Path,
109
- encoding: BufferEncoding
110
- ): Promise<Dir<string>>
110
+ export function opendir(filepath: Path, encoding: BufferEncoding): Promise<Dir<string>>
111
111
 
112
- export function opendir(
113
- filepath: Path,
114
- encoding: 'buffer'
115
- ): Promise<Dir<Buffer>>
112
+ export function opendir(filepath: Path, encoding: 'buffer'): Promise<Dir<Buffer>>
116
113
 
117
- export function opendir(
118
- filepath: Path,
119
- encoding: BufferEncoding | 'buffer'
120
- ): Promise<Dir>
114
+ export function opendir(filepath: Path, encoding: BufferEncoding | 'buffer'): Promise<Dir>
121
115
 
122
116
  export function opendir(filepath: Path): Promise<Dir<string>>
123
117
 
@@ -131,15 +125,9 @@ export function readFile(
131
125
  opts: ReadFileOptions & { encoding?: 'buffer' }
132
126
  ): Promise<Buffer>
133
127
 
134
- export function readFile(
135
- filepath: Path,
136
- opts: ReadFileOptions
137
- ): Promise<string | Buffer>
128
+ export function readFile(filepath: Path, opts: ReadFileOptions): Promise<string | Buffer>
138
129
 
139
- export function readFile(
140
- filepath: Path,
141
- encoding: BufferEncoding
142
- ): Promise<string>
130
+ export function readFile(filepath: Path, encoding: BufferEncoding): Promise<string>
143
131
 
144
132
  export function readFile(filepath: Path, encoding: 'buffer'): Promise<Buffer>
145
133
 
@@ -190,15 +178,9 @@ export function readdir(
190
178
  opts: ReaddirOptions & { withFileTypes?: false }
191
179
  ): Promise<string[] | Buffer[]>
192
180
 
193
- export function readdir(
194
- filepath: Path,
195
- opts: ReaddirOptions
196
- ): Promise<Dir[] | string[] | Buffer[]>
181
+ export function readdir(filepath: Path, opts: ReaddirOptions): Promise<Dir[] | string[] | Buffer[]>
197
182
 
198
- export function readdir(
199
- filepath: Path,
200
- encoding: BufferEncoding
201
- ): Promise<string[]>
183
+ export function readdir(filepath: Path, encoding: BufferEncoding): Promise<string[]>
202
184
 
203
185
  export function readdir(filepath: Path, encoding: 'buffer'): Promise<Buffer[]>
204
186
 
@@ -219,15 +201,9 @@ export function readlink(
219
201
  opts: ReadlinkOptions & { encoding: 'buffer' }
220
202
  ): Promise<Buffer>
221
203
 
222
- export function readlink(
223
- filepath: Path,
224
- opts: ReadlinkOptions
225
- ): Promise<string | Buffer>
204
+ export function readlink(filepath: Path, opts: ReadlinkOptions): Promise<string | Buffer>
226
205
 
227
- export function readlink(
228
- filepath: Path,
229
- encoding: BufferEncoding
230
- ): Promise<string>
206
+ export function readlink(filepath: Path, encoding: BufferEncoding): Promise<string>
231
207
 
232
208
  export function readlink(filepath: Path, encoding: 'buffer'): Promise<Buffer>
233
209
 
@@ -248,15 +224,9 @@ export function realpath(
248
224
  opts: RealpathOptions & { encoding: 'buffer' }
249
225
  ): Promise<Buffer>
250
226
 
251
- export function realpath(
252
- filepath: Path,
253
- opts: RealpathOptions
254
- ): Promise<string | Buffer>
227
+ export function realpath(filepath: Path, opts: RealpathOptions): Promise<string | Buffer>
255
228
 
256
- export function realpath(
257
- filepath: Path,
258
- encoding: BufferEncoding
259
- ): Promise<string>
229
+ export function realpath(filepath: Path, encoding: BufferEncoding): Promise<string>
260
230
 
261
231
  export function realpath(filepath: Path, encoding: 'buffer'): Promise<Buffer>
262
232
 
@@ -275,11 +245,7 @@ export function rmdir(filepath: Path): Promise<void>
275
245
 
276
246
  export function stat(filepath: Path): Promise<Stats>
277
247
 
278
- export function symlink(
279
- target: Path,
280
- filepath: Path,
281
- type?: string | number
282
- ): Promise<void>
248
+ export function symlink(target: Path, filepath: Path, type?: string | number): Promise<void>
283
249
 
284
250
  export function unlink(filepath: Path): Promise<void>
285
251
 
@@ -299,10 +265,7 @@ export function watch(filepath: Path, encoding: BufferEncoding): Watcher<string>
299
265
 
300
266
  export function watch(filepath: Path, encoding: 'buffer'): Watcher<Buffer>
301
267
 
302
- export function watch(
303
- filepath: Path,
304
- encoding: BufferEncoding | 'buffer'
305
- ): Watcher
268
+ export function watch(filepath: Path, encoding: BufferEncoding | 'buffer'): Watcher
306
269
 
307
270
  export function watch(filepath: Path): Watcher<string>
308
271
 
package/promises.js CHANGED
@@ -71,6 +71,7 @@ exports.appendFile = fs.appendFile
71
71
  exports.chmod = fs.chmod
72
72
  exports.constants = fs.constants
73
73
  exports.copyFile = fs.copyFile
74
+ exports.cp = fs.cp
74
75
  exports.lstat = fs.lstat
75
76
  exports.mkdir = fs.mkdir
76
77
  exports.opendir = fs.opendir