bare-fs 4.8.0 → 4.8.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 +1 -957
- package/binding.c +53 -24
- package/index.d.ts +279 -9
- package/index.js +32 -11
- package/lib/constants.d.ts +1 -0
- package/lib/errors.d.ts +2 -0
- package/package.json +2 -1
- package/prebuilds/android-arm/bare-fs.bare +0 -0
- package/prebuilds/android-arm64/bare-fs.bare +0 -0
- package/prebuilds/android-ia32/bare-fs.bare +0 -0
- package/prebuilds/android-x64/bare-fs.bare +0 -0
- package/prebuilds/darwin-arm64/bare-fs.bare +0 -0
- package/prebuilds/darwin-x64/bare-fs.bare +0 -0
- package/prebuilds/ios-arm64/bare-fs.bare +0 -0
- package/prebuilds/ios-arm64-simulator/bare-fs.bare +0 -0
- package/prebuilds/ios-x64-simulator/bare-fs.bare +0 -0
- package/prebuilds/linux-arm64/bare-fs.bare +0 -0
- package/prebuilds/linux-x64/bare-fs.bare +0 -0
- package/prebuilds/win32-arm64/bare-fs.bare +0 -0
- package/prebuilds/win32-x64/bare-fs.bare +0 -0
- package/promises.d.ts +167 -0
package/index.d.ts
CHANGED
|
@@ -39,14 +39,25 @@ interface Callback<A extends unknown[] = []> {
|
|
|
39
39
|
|
|
40
40
|
export interface Dir<T extends string | Buffer = string | Buffer>
|
|
41
41
|
extends Iterable<Dirent>, AsyncIterable<Dirent> {
|
|
42
|
+
/** The path of the directory. */
|
|
42
43
|
readonly path: string
|
|
43
44
|
|
|
45
|
+
/**
|
|
46
|
+
* Read the next entry from the directory.
|
|
47
|
+
* @returns The next `Dirent` for the directory, or `null` once every entry has been read.
|
|
48
|
+
*/
|
|
44
49
|
read(): Promise<Dirent<T> | null>
|
|
45
50
|
read(cb: Callback<[dirent: Dirent<T> | null]>): void
|
|
51
|
+
/**
|
|
52
|
+
* Read the next entry from the directory.
|
|
53
|
+
* @returns The next `Dirent` for the directory, or `null` once every entry has been read.
|
|
54
|
+
*/
|
|
46
55
|
readSync(): Dirent<T> | null
|
|
47
56
|
|
|
57
|
+
/** Close the directory handle opened by `fs.opendir()`. */
|
|
48
58
|
close(): Promise<void>
|
|
49
59
|
close(cb: Callback): void
|
|
60
|
+
/** Close the directory handle opened by `fs.opendirSync()`. */
|
|
50
61
|
closeSync(): void
|
|
51
62
|
}
|
|
52
63
|
|
|
@@ -55,16 +66,26 @@ export class Dir {
|
|
|
55
66
|
}
|
|
56
67
|
|
|
57
68
|
export interface Dirent<T extends string | Buffer = string | Buffer> {
|
|
69
|
+
/** The path of the parent directory. */
|
|
58
70
|
readonly parentPath: string
|
|
71
|
+
/** The name of the directory entry, as a string or `Buffer` depending on the encoding. */
|
|
59
72
|
readonly name: T
|
|
73
|
+
/** The numeric type of the directory entry. */
|
|
60
74
|
readonly type: number
|
|
61
75
|
|
|
76
|
+
/** Returns `true` if the file is a regular file. */
|
|
62
77
|
isFile(): boolean
|
|
78
|
+
/** Returns `true` if the file is a directory. */
|
|
63
79
|
isDirectory(): boolean
|
|
80
|
+
/** Returns `true` if the file is a symbolic link. Only meaningful when using `fs.lstat()`. */
|
|
64
81
|
isSymbolicLink(): boolean
|
|
82
|
+
/** Returns `true` if the file is a FIFO (named pipe). */
|
|
65
83
|
isFIFO(): boolean
|
|
84
|
+
/** Returns `true` if the file is a socket. */
|
|
66
85
|
isSocket(): boolean
|
|
86
|
+
/** Returns `true` if the file is a character device. */
|
|
67
87
|
isCharacterDevice(): boolean
|
|
88
|
+
/** Returns `true` if the file is a block device. */
|
|
68
89
|
isBlockDevice(): boolean
|
|
69
90
|
}
|
|
70
91
|
|
|
@@ -73,23 +94,41 @@ export class Dirent<T extends string | Buffer = string | Buffer> {
|
|
|
73
94
|
}
|
|
74
95
|
|
|
75
96
|
export interface Stats {
|
|
97
|
+
/** The device identifier. */
|
|
76
98
|
readonly dev: number
|
|
99
|
+
/** The file mode (type and permissions). */
|
|
77
100
|
readonly mode: number
|
|
101
|
+
/** The number of hard links. */
|
|
78
102
|
readonly nlink: number
|
|
103
|
+
/** The user identifier of the file owner. */
|
|
79
104
|
readonly uid: number
|
|
105
|
+
/** The group identifier of the file owner. */
|
|
80
106
|
readonly gid: number
|
|
107
|
+
/** The device identifier for special files. */
|
|
81
108
|
readonly rdev: number
|
|
109
|
+
/** The file system block size for I/O operations. */
|
|
82
110
|
readonly blksize: number
|
|
111
|
+
/** The inode number. */
|
|
83
112
|
readonly ino: number
|
|
113
|
+
/** The size of the file in bytes. */
|
|
84
114
|
readonly size: number
|
|
115
|
+
/** The number of 512-byte blocks allocated. */
|
|
85
116
|
readonly blocks: number
|
|
117
|
+
/** The access time in milliseconds since the epoch. */
|
|
86
118
|
readonly atimeMs: number
|
|
119
|
+
/** The modification time in milliseconds since the epoch. */
|
|
87
120
|
readonly mtimeMs: number
|
|
121
|
+
/** The change time in milliseconds since the epoch. */
|
|
88
122
|
readonly ctimeMs: number
|
|
123
|
+
/** The creation time in milliseconds since the epoch. */
|
|
89
124
|
readonly birthtimeMs: number
|
|
125
|
+
/** The access time as a `Date` object. */
|
|
90
126
|
readonly atime: Date
|
|
127
|
+
/** The modification time as a `Date` object. */
|
|
91
128
|
readonly mtime: Date
|
|
129
|
+
/** The change time as a `Date` object. */
|
|
92
130
|
readonly ctime: Date
|
|
131
|
+
/** The creation time as a `Date` object. */
|
|
93
132
|
readonly birthtime: Date
|
|
94
133
|
|
|
95
134
|
isDirectory(): boolean
|
|
@@ -144,8 +183,15 @@ export class StatFs {
|
|
|
144
183
|
)
|
|
145
184
|
}
|
|
146
185
|
|
|
186
|
+
/**
|
|
187
|
+
* Options for `fs.createReadStream()`. `fd`, if given, is used instead of opening `path`. `flags`
|
|
188
|
+
* defaults to `'r'` and `mode` to `0o666`. `start` (default `0`) is the first byte read; `end`, if
|
|
189
|
+
* given, is the last byte read (inclusive).
|
|
190
|
+
*/
|
|
147
191
|
export interface ReadStreamOptions {
|
|
192
|
+
/** The underlying file descriptor. */
|
|
148
193
|
fd?: number
|
|
194
|
+
/** The flags the file was opened with. */
|
|
149
195
|
flags?: Flag
|
|
150
196
|
mode?: number
|
|
151
197
|
start?: number
|
|
@@ -163,8 +209,19 @@ export class ReadStream {
|
|
|
163
209
|
private constructor(path: Path | null, opts?: ReadStreamOptions)
|
|
164
210
|
}
|
|
165
211
|
|
|
212
|
+
/**
|
|
213
|
+
* Create a readable stream for a file. Returns a `ReadStream`.
|
|
214
|
+
* @param path - May be `null` if `opts.fd` specifies an already-open file descriptor to read from
|
|
215
|
+
* instead of opening `path`.
|
|
216
|
+
* @param opts - `flags` defaults to `'r'`, `mode` to `0o666`, `start` (byte offset) to `0`; `end`
|
|
217
|
+
* (inclusive byte offset), if given, stops the stream early.
|
|
218
|
+
*/
|
|
166
219
|
export function createReadStream(path: Path | null, opts?: ReadStreamOptions): ReadStream
|
|
167
220
|
|
|
221
|
+
/**
|
|
222
|
+
* Options for `fs.createWriteStream()`. `fd`, if given, is used instead of opening `path`. `flags`
|
|
223
|
+
* defaults to `'w'` and `mode` to `0o666`.
|
|
224
|
+
*/
|
|
168
225
|
export interface WriteStreamOptions {
|
|
169
226
|
fd?: number
|
|
170
227
|
flags?: Flag
|
|
@@ -182,8 +239,19 @@ export class WriteStream {
|
|
|
182
239
|
private constructor(path: Path | null, opts?: WriteStreamOptions)
|
|
183
240
|
}
|
|
184
241
|
|
|
242
|
+
/**
|
|
243
|
+
* Create a writable stream for a file. Returns a `WriteStream`.
|
|
244
|
+
* @param path - May be `null` if `opts.fd` specifies an already-open file descriptor to write to
|
|
245
|
+
* instead of opening `path`.
|
|
246
|
+
* @param opts - `flags` defaults to `'w'`, `mode` to `0o666`.
|
|
247
|
+
*/
|
|
185
248
|
export function createWriteStream(path: Path | null, opts?: WriteStreamOptions): WriteStream
|
|
186
249
|
|
|
250
|
+
/**
|
|
251
|
+
* Options for `fs.watch()`. `persistent` defaults to `true` (if `false`, the watcher is `unref()`'d
|
|
252
|
+
* immediately so it does not keep the process alive). `recursive` defaults to `false` and also
|
|
253
|
+
* watches subdirectories. `encoding` defaults to `'utf8'`.
|
|
254
|
+
*/
|
|
187
255
|
export interface WatcherOptions {
|
|
188
256
|
persistent?: boolean
|
|
189
257
|
recursive?: boolean
|
|
@@ -194,16 +262,20 @@ export type WatcherEventType = 'rename' | 'change'
|
|
|
194
262
|
|
|
195
263
|
export interface WatcherEvents<T extends string | Buffer = string | Buffer> extends EventMap {
|
|
196
264
|
error: [err: Error]
|
|
197
|
-
change: [eventType: WatcherEventType, filename: T]
|
|
265
|
+
change: [eventType: WatcherEventType, filename: T | null]
|
|
266
|
+
/** Emitted once the watcher has stopped watching. */
|
|
198
267
|
close: []
|
|
199
268
|
}
|
|
200
269
|
|
|
201
270
|
export interface Watcher<T extends string | Buffer = string | Buffer>
|
|
202
271
|
extends
|
|
203
272
|
EventEmitter<WatcherEvents<T>>,
|
|
204
|
-
AsyncIterable<{ eventType: WatcherEventType; filename: T }> {
|
|
273
|
+
AsyncIterable<{ eventType: WatcherEventType; filename: T | null }> {
|
|
274
|
+
/** Stop watching for further changes. Once closed, a `close` event is emitted. */
|
|
205
275
|
close(): void
|
|
276
|
+
/** Prevent the event loop from exiting while the watcher is active. */
|
|
206
277
|
ref(): void
|
|
278
|
+
/** Allow the event loop to exit even if the watcher is still active. */
|
|
207
279
|
unref(): void
|
|
208
280
|
}
|
|
209
281
|
|
|
@@ -211,6 +283,11 @@ export class Watcher {
|
|
|
211
283
|
private constructor(path: Path, opts: WatcherOptions)
|
|
212
284
|
}
|
|
213
285
|
|
|
286
|
+
/**
|
|
287
|
+
* Check whether the file at `filepath` is accessible. `mode` defaults to `fs.constants.F_OK`.
|
|
288
|
+
* @param mode - Defaults to `fs.constants.F_OK` (existence only); may also combine `R_OK`, `W_OK`,
|
|
289
|
+
* and/or `X_OK`.
|
|
290
|
+
*/
|
|
214
291
|
export function access(filepath: Path, mode?: number): Promise<void>
|
|
215
292
|
|
|
216
293
|
export function access(filepath: Path, mode: number, cb: Callback): void
|
|
@@ -225,6 +302,10 @@ export interface AppendFileOptions {
|
|
|
225
302
|
mode?: number
|
|
226
303
|
}
|
|
227
304
|
|
|
305
|
+
/**
|
|
306
|
+
* Append `data` to a file, creating it if it does not exist. Accepts the same options as
|
|
307
|
+
* `fs.writeFile()` but defaults to the `'a'` flag.
|
|
308
|
+
*/
|
|
228
309
|
export function appendFile(
|
|
229
310
|
filepath: Path,
|
|
230
311
|
data: string | Buffer | ArrayBufferView,
|
|
@@ -269,24 +350,42 @@ export function appendFileSync(
|
|
|
269
350
|
encoding: BufferEncoding
|
|
270
351
|
): void
|
|
271
352
|
|
|
353
|
+
/**
|
|
354
|
+
* Change the permissions of a file. `mode` may be a numeric mode or a string that will be parsed as
|
|
355
|
+
* octal.
|
|
356
|
+
*/
|
|
272
357
|
export function chmod(filepath: Path, mode: string | number): Promise<void>
|
|
273
358
|
|
|
274
359
|
export function chmod(filepath: Path, mode: string | number, cb: Callback): void
|
|
275
360
|
|
|
276
361
|
export function chmodSync(filepath: Path, mode: string | number): void
|
|
277
362
|
|
|
363
|
+
/** Change the owner and group of a file. */
|
|
278
364
|
export function chown(filepath: Path, uid: number, gid: number): Promise<void>
|
|
279
365
|
|
|
280
366
|
export function chown(filepath: Path, uid: number, gid: number, cb: Callback): void
|
|
281
367
|
|
|
282
368
|
export function chownSync(filepath: Path, uid: number, gid: number): void
|
|
283
369
|
|
|
370
|
+
/**
|
|
371
|
+
* Close a file descriptor.
|
|
372
|
+
* @param fd - The file descriptor to close, as returned by `fs.open()`.
|
|
373
|
+
*/
|
|
284
374
|
export function close(fd: number): Promise<void>
|
|
285
375
|
|
|
286
376
|
export function close(fd: number, cb: Callback): void
|
|
287
377
|
|
|
378
|
+
/** Close the directory handle opened by `fs.opendirSync()`. */
|
|
288
379
|
export function closeSync(fd: number): void
|
|
289
380
|
|
|
381
|
+
/**
|
|
382
|
+
* Copy a file from `src` to `dst`. `mode` is an optional bitmask created from
|
|
383
|
+
* `fs.constants.COPYFILE_EXCL`, `fs.constants.COPYFILE_FICLONE`, or
|
|
384
|
+
* `fs.constants.COPYFILE_FICLONE_FORCE`.
|
|
385
|
+
* @param mode - Defaults to `0`. A bitmask of `fs.constants.COPYFILE_EXCL` (fail if `dst` exists),
|
|
386
|
+
* `COPYFILE_FICLONE`, or `COPYFILE_FICLONE_FORCE`.
|
|
387
|
+
* @throws {EEXIST} `dst` already exists and `mode` includes `fs.constants.COPYFILE_EXCL`.
|
|
388
|
+
*/
|
|
290
389
|
export function copyFile(src: Path, dst: Path, mode?: number): Promise<void>
|
|
291
390
|
|
|
292
391
|
export function copyFile(src: Path, dst: Path, mode: number, cb: Callback): void
|
|
@@ -295,10 +394,20 @@ export function copyFile(src: Path, dst: Path, cb: Callback): void
|
|
|
295
394
|
|
|
296
395
|
export function copyFileSync(src: Path, dst: Path, mode?: number): void
|
|
297
396
|
|
|
397
|
+
/**
|
|
398
|
+
* Options for `fs.cp()`. `recursive` must be `true` to copy a directory; without it, copying a
|
|
399
|
+
* directory throws `EISDIR`.
|
|
400
|
+
*/
|
|
298
401
|
export interface CpOptions {
|
|
299
402
|
recursive?: boolean
|
|
300
403
|
}
|
|
301
404
|
|
|
405
|
+
/**
|
|
406
|
+
* Copy a file or directory from `src` to `dst`.
|
|
407
|
+
* @param opts - `recursive` must be `true` to copy a directory; copying a directory without it
|
|
408
|
+
* throws `EISDIR`.
|
|
409
|
+
* @throws {EISDIR} `src` is a directory and `opts.recursive` is not set.
|
|
410
|
+
*/
|
|
302
411
|
export function cp(src: Path, dst: Path, opts?: CpOptions): Promise<void>
|
|
303
412
|
|
|
304
413
|
export function cp(src: Path, dst: Path, opts: CpOptions, cb: Callback): void
|
|
@@ -307,42 +416,54 @@ export function cp(src: Path, dst: Path, cb: Callback): void
|
|
|
307
416
|
|
|
308
417
|
export function cpSync(src: Path, dst: Path, opts?: CpOptions): void
|
|
309
418
|
|
|
419
|
+
/**
|
|
420
|
+
* Check whether a file exists at `filepath`. Returns `true` if the file is accessible, `false`
|
|
421
|
+
* otherwise.
|
|
422
|
+
*/
|
|
310
423
|
export function exists(filepath: Path): Promise<boolean>
|
|
311
424
|
|
|
312
425
|
export function exists(filepath: Path, cb: (exists: boolean) => void): void
|
|
313
426
|
|
|
314
427
|
export function existsSync(filepath: Path): boolean
|
|
315
428
|
|
|
429
|
+
/** Change the permissions of a file by its file descriptor. */
|
|
316
430
|
export function fchmod(fd: number, mode: string | number): Promise<void>
|
|
317
431
|
|
|
318
432
|
export function fchmod(fd: number, mode: string | number, cb: Callback): void
|
|
319
433
|
|
|
320
434
|
export function fchmodSync(fd: number, mode: string | number): void
|
|
321
435
|
|
|
436
|
+
/** Change the owner and group of a file by its file descriptor. */
|
|
322
437
|
export function fchown(fd: number, uid: number, gid: number): Promise<void>
|
|
323
438
|
|
|
324
439
|
export function fchown(fd: number, uid: number, gid: number, cb: Callback): void
|
|
325
440
|
|
|
326
441
|
export function fchownSync(fd: number, uid: number, gid: number): void
|
|
327
442
|
|
|
443
|
+
/** Similar to `fsync`, but does not flush modified metadata unless necessary. */
|
|
328
444
|
export function fdatasync(fd: number): Promise<void>
|
|
329
445
|
|
|
330
446
|
export function fdatasync(fd: number, cb: Callback): void
|
|
331
447
|
|
|
332
448
|
export function fdatasyncSync(fd: number): void
|
|
333
449
|
|
|
450
|
+
/** Get the status of a file by its file descriptor. Returns a `Stats` object. */
|
|
334
451
|
export function fstat(fd: number): Promise<Stats>
|
|
335
452
|
|
|
336
453
|
export function fstat(fd: number, cb: Callback<[stats: Stats | null]>): void
|
|
337
454
|
|
|
338
455
|
export function fstatSync(fd: number): Stats
|
|
339
456
|
|
|
457
|
+
/**
|
|
458
|
+
* Flush all modified in-core data of the file referred by its file descriptor to the disk device.
|
|
459
|
+
*/
|
|
340
460
|
export function fsync(fd: number): Promise<void>
|
|
341
461
|
|
|
342
462
|
export function fsync(fd: number, cb: Callback): void
|
|
343
463
|
|
|
344
464
|
export function fsyncSync(fd: number): void
|
|
345
465
|
|
|
466
|
+
/** Truncate a file to `len` bytes. `len` defaults to `0`. */
|
|
346
467
|
export function ftruncate(fd: number, len?: number): Promise<void>
|
|
347
468
|
|
|
348
469
|
export function ftruncate(fd: number, len: number, cb: Callback): void
|
|
@@ -351,18 +472,30 @@ export function ftruncate(fd: number, cb: Callback): void
|
|
|
351
472
|
|
|
352
473
|
export function ftruncateSync(fd: number, len?: number): void
|
|
353
474
|
|
|
475
|
+
/**
|
|
476
|
+
* Change the owner and group of a file, but if `filepath` is a symbolic link, the changes are
|
|
477
|
+
* applied only to the link, not the file it refers to.
|
|
478
|
+
*/
|
|
354
479
|
export function lchown(filepath: Path, uid: number, gid: number): Promise<void>
|
|
355
480
|
|
|
356
481
|
export function lchown(filepath: Path, uid: number, gid: number, cb: Callback): void
|
|
357
482
|
|
|
358
483
|
export function lchownSync(filepath: Path, uid: number, gid: number): void
|
|
359
484
|
|
|
485
|
+
/**
|
|
486
|
+
* Like `fs.stat()`, but if `filepath` is a symbolic link, the link itself is statted, not the file
|
|
487
|
+
* it refers to.
|
|
488
|
+
*/
|
|
360
489
|
export function lstat(filepath: Path): Promise<Stats>
|
|
361
490
|
|
|
362
491
|
export function lstat(filepath: Path, cb: Callback<[stats: Stats | null]>): void
|
|
363
492
|
|
|
364
493
|
export function lstatSync(filepath: Path): Stats
|
|
365
494
|
|
|
495
|
+
/**
|
|
496
|
+
* Change the access and modification times of a file. Times may be numbers (seconds since epoch) or
|
|
497
|
+
* `Date` objects.
|
|
498
|
+
*/
|
|
366
499
|
export function utimes(filepath: Path, atime: number | Date, mtime: number | Date): Promise<void>
|
|
367
500
|
|
|
368
501
|
export function utimes(
|
|
@@ -374,6 +507,10 @@ export function utimes(
|
|
|
374
507
|
|
|
375
508
|
export function utimesSync(filepath: Path, atime: number | Date, mtime: number | Date): void
|
|
376
509
|
|
|
510
|
+
/**
|
|
511
|
+
* Like `fs.utimes()`, but if `filepath` is a symbolic link, the timestamps of the link is changed,
|
|
512
|
+
* not the file it refers to.
|
|
513
|
+
*/
|
|
377
514
|
export function lutimes(filepath: Path, atime: number | Date, mtime: number | Date): Promise<void>
|
|
378
515
|
|
|
379
516
|
export function lutimes(
|
|
@@ -385,23 +522,40 @@ export function lutimes(
|
|
|
385
522
|
|
|
386
523
|
export function lutimesSync(filepath: Path, atime: number | Date, mtime: number | Date): void
|
|
387
524
|
|
|
525
|
+
/**
|
|
526
|
+
* Change the access and modification times of a file by its file descriptor. Times may be numbers
|
|
527
|
+
* (seconds since epoch) or `Date` objects.
|
|
528
|
+
*/
|
|
388
529
|
export function futimes(fd: number, atime: number | Date, mtime: number | Date): Promise<void>
|
|
389
530
|
|
|
390
531
|
export function futimes(fd: number, atime: number | Date, mtime: number | Date, cb: Callback): void
|
|
391
532
|
|
|
392
533
|
export function futimesSync(fd: number, atime: number | Date, mtime: number | Date): void
|
|
393
534
|
|
|
535
|
+
/** Creates a new link (also known as a hard link) to an existing file. */
|
|
394
536
|
export function link(src: Path, dst: Path): Promise<void>
|
|
395
537
|
|
|
396
538
|
export function link(src: Path, dst: Path, cb: Callback): void
|
|
397
539
|
|
|
398
540
|
export function linkSync(src: Path, dst: Path): void
|
|
399
541
|
|
|
542
|
+
/**
|
|
543
|
+
* Options for `fs.mkdir()`. `mode` defaults to `0o777`. `recursive`, if `true`, creates any missing
|
|
544
|
+
* parent directories and does not error if `filepath` already exists as a directory.
|
|
545
|
+
*/
|
|
400
546
|
export interface MkdirOptions {
|
|
401
547
|
mode?: number
|
|
402
548
|
recursive?: boolean
|
|
403
549
|
}
|
|
404
550
|
|
|
551
|
+
/**
|
|
552
|
+
* Create a directory at `filepath`.
|
|
553
|
+
* @param opts - `mode` defaults to `0o777`. `recursive`, if `true`, creates missing parent
|
|
554
|
+
* directories and does not error if `filepath` already exists as a directory.
|
|
555
|
+
* @throws {ENOENT} a parent directory in `filepath` does not exist and `opts.recursive` is not set.
|
|
556
|
+
* @throws {EEXIST} `filepath` already exists; when `opts.recursive` is set this is only thrown if
|
|
557
|
+
* the existing path is not itself a directory.
|
|
558
|
+
*/
|
|
405
559
|
export function mkdir(filepath: Path, opts?: MkdirOptions): Promise<void>
|
|
406
560
|
|
|
407
561
|
export function mkdir(filepath: Path, mode: number): Promise<void>
|
|
@@ -416,12 +570,31 @@ export function mkdirSync(filepath: Path, opts?: MkdirOptions): void
|
|
|
416
570
|
|
|
417
571
|
export function mkdirSync(filepath: Path, mode: number): void
|
|
418
572
|
|
|
573
|
+
/**
|
|
574
|
+
* Create a unique temporary directory.
|
|
575
|
+
* @param prefix - The literal suffix `'XXXXXX'` is appended to `prefix` and replaced with random
|
|
576
|
+
* characters to form the directory name.
|
|
577
|
+
* @returns The path of the newly created directory, including its randomly generated suffix.
|
|
578
|
+
*/
|
|
419
579
|
export function mkdtemp(prefix: Path): Promise<string>
|
|
420
580
|
|
|
421
581
|
export function mkdtemp(prefix: Path, cb: Callback<[path: string | null]>): void
|
|
422
582
|
|
|
423
583
|
export function mkdtempSync(prefix: Path): string
|
|
424
584
|
|
|
585
|
+
/**
|
|
586
|
+
* Open a file, returning a file descriptor. `flags` defaults to `'r'` and `mode` defaults to
|
|
587
|
+
* `0o666`. `flags` may be a string such as `'r'`, `'w'`, `'a'`, `'r+'`, etc., or a numeric
|
|
588
|
+
* combination of `fs.constants` flags.
|
|
589
|
+
* @param flags - Defaults to `'r'`. Selects read/write mode and whether the file is created,
|
|
590
|
+
* truncated, or appended.
|
|
591
|
+
* @param mode - Defaults to `0o666`. Applied only when `flags` creates a new file.
|
|
592
|
+
* @returns The file descriptor for the newly opened file.
|
|
593
|
+
* @throws {ENOENT} `filepath` does not exist and `flags` does not include a creating variant (for
|
|
594
|
+
* example the default `'r'`).
|
|
595
|
+
* @throws {EEXIST} `flags` is an exclusive variant (`'wx'`, `'ax'`, `'xw'`, `'xa'`, etc.) and
|
|
596
|
+
* `filepath` already exists.
|
|
597
|
+
*/
|
|
425
598
|
export function open(filepath: Path, flags?: Flag | number, mode?: string | number): Promise<number>
|
|
426
599
|
|
|
427
600
|
export function open(
|
|
@@ -437,11 +610,16 @@ export function open(filepath: Path, cb: Callback<[fd: number]>): void
|
|
|
437
610
|
|
|
438
611
|
export function openSync(filepath: Path, flags?: Flag | number, mode?: string | number): number
|
|
439
612
|
|
|
613
|
+
/**
|
|
614
|
+
* Options for `fs.opendir()`. `bufferSize` defaults to `32` and sets how many directory entries are
|
|
615
|
+
* buffered internally per read.
|
|
616
|
+
*/
|
|
440
617
|
export interface OpendirOptions {
|
|
441
618
|
encoding?: BufferEncoding | 'buffer'
|
|
442
619
|
bufferSize?: number
|
|
443
620
|
}
|
|
444
621
|
|
|
622
|
+
/** Open a directory for iteration. Returns a `Dir` object. */
|
|
445
623
|
export function opendir(
|
|
446
624
|
filepath: Path,
|
|
447
625
|
opts: OpendirOptions & { encoding?: BufferEncoding }
|
|
@@ -516,6 +694,17 @@ export function opendirSync(filepath: Path, encoding: BufferEncoding | 'buffer')
|
|
|
516
694
|
|
|
517
695
|
export function opendirSync(filepath: Path): Dir<string>
|
|
518
696
|
|
|
697
|
+
/**
|
|
698
|
+
* Read from a file descriptor into `buffer`. `offset` defaults to `0`, `len` defaults to
|
|
699
|
+
* `buffer.byteLength - offset`, and `pos` defaults to `-1` (current position). Returns the number
|
|
700
|
+
* of bytes read.
|
|
701
|
+
* @param fd - The file descriptor to read from, as returned by `fs.open()`.
|
|
702
|
+
* @param offset - The offset within `buffer` to start writing to. Defaults to `0`.
|
|
703
|
+
* @param len - The number of bytes to read. Defaults to `buffer.byteLength - offset`.
|
|
704
|
+
* @param pos - The position in the file to read from. Defaults to `-1`, which reads from the
|
|
705
|
+
* current file position and advances it.
|
|
706
|
+
* @returns The number of bytes actually read, which may be less than `len` (`0` at end of file).
|
|
707
|
+
*/
|
|
519
708
|
export function read(
|
|
520
709
|
fd: number,
|
|
521
710
|
buffer: Buffer | ArrayBufferView,
|
|
@@ -554,6 +743,10 @@ export function read(
|
|
|
554
743
|
cb: Callback<[len: number]>
|
|
555
744
|
): void
|
|
556
745
|
|
|
746
|
+
/**
|
|
747
|
+
* Read the next entry from the directory.
|
|
748
|
+
* @returns The next `Dirent` for the directory, or `null` once every entry has been read.
|
|
749
|
+
*/
|
|
557
750
|
export function readSync(
|
|
558
751
|
fd: number,
|
|
559
752
|
buffer: Buffer | ArrayBufferView,
|
|
@@ -567,6 +760,12 @@ export interface ReadFileOptions {
|
|
|
567
760
|
flag?: Flag
|
|
568
761
|
}
|
|
569
762
|
|
|
763
|
+
/**
|
|
764
|
+
* Read the entire contents of a file. Returns a `Buffer` by default, or a string if an `encoding`
|
|
765
|
+
* is specified.
|
|
766
|
+
* @param opts - `encoding` defaults to `'buffer'` (returning a `Buffer` rather than a string);
|
|
767
|
+
* `flag` defaults to `'r'`.
|
|
768
|
+
*/
|
|
570
769
|
export function readFile(
|
|
571
770
|
filepath: Path,
|
|
572
771
|
opts: ReadFileOptions & { encoding: BufferEncoding }
|
|
@@ -647,6 +846,12 @@ export function readFileSync(filepath: Path): Buffer
|
|
|
647
846
|
export interface ReaddirOptions extends OpendirOptions {
|
|
648
847
|
withFileTypes?: boolean
|
|
649
848
|
}
|
|
849
|
+
/**
|
|
850
|
+
* Read the contents of a directory. Returns an array of filenames or, if `withFileTypes` is `true`,
|
|
851
|
+
* an array of `Dirent` objects.
|
|
852
|
+
* @param opts - `withFileTypes`, if `true`, returns `Dirent` objects instead of plain filename
|
|
853
|
+
* strings.
|
|
854
|
+
*/
|
|
650
855
|
export function readdir(
|
|
651
856
|
filepath: Path,
|
|
652
857
|
opts: ReaddirOptions & { encoding?: BufferEncoding }
|
|
@@ -834,6 +1039,7 @@ export interface ReadlinkOptions {
|
|
|
834
1039
|
encoding?: BufferEncoding | 'buffer'
|
|
835
1040
|
}
|
|
836
1041
|
|
|
1042
|
+
/** Read the target of a symbolic link. */
|
|
837
1043
|
export function readlink(
|
|
838
1044
|
filepath: Path,
|
|
839
1045
|
opts: ReadlinkOptions & { encoding?: BufferEncoding }
|
|
@@ -912,6 +1118,10 @@ export function readlinkSync(filepath: Path, encoding: BufferEncoding | 'buffer'
|
|
|
912
1118
|
|
|
913
1119
|
export function readlinkSync(filepath: Path): string
|
|
914
1120
|
|
|
1121
|
+
/**
|
|
1122
|
+
* Read from a file descriptor into an array of `buffers`. `pos` defaults to `-1`.
|
|
1123
|
+
* @returns The number of bytes actually read across all buffers.
|
|
1124
|
+
*/
|
|
915
1125
|
export function readv(fd: number, buffers: ArrayBufferView[], position?: number): Promise<number>
|
|
916
1126
|
|
|
917
1127
|
export function readv(
|
|
@@ -929,6 +1139,7 @@ export interface RealpathOptions {
|
|
|
929
1139
|
encoding?: BufferEncoding | 'buffer'
|
|
930
1140
|
}
|
|
931
1141
|
|
|
1142
|
+
/** Resolve the real path of `filepath`, expanding all symbolic links. */
|
|
932
1143
|
export function realpath(
|
|
933
1144
|
filepath: Path,
|
|
934
1145
|
opts: RealpathOptions & { encoding?: BufferEncoding }
|
|
@@ -1007,17 +1218,28 @@ export function realpathSync(filepath: Path, encoding: BufferEncoding | 'buffer'
|
|
|
1007
1218
|
|
|
1008
1219
|
export function realpathSync(filepath: Path): string
|
|
1009
1220
|
|
|
1221
|
+
/** Rename a file from `src` to `dst`. */
|
|
1010
1222
|
export function rename(src: Path, dst: Path): Promise<void>
|
|
1011
1223
|
|
|
1012
1224
|
export function rename(src: Path, dst: Path, cb: Callback): void
|
|
1013
1225
|
|
|
1014
1226
|
export function renameSync(src: Path, dst: Path): void
|
|
1015
1227
|
|
|
1228
|
+
/**
|
|
1229
|
+
* Options for `fs.rm()`. `recursive`, if `true`, removes directories and their contents. `force`,
|
|
1230
|
+
* if `true`, suppresses the error when `filepath` does not exist.
|
|
1231
|
+
*/
|
|
1016
1232
|
export interface RmOptions {
|
|
1017
1233
|
force?: boolean
|
|
1018
1234
|
recursive?: boolean
|
|
1019
1235
|
}
|
|
1020
1236
|
|
|
1237
|
+
/**
|
|
1238
|
+
* Remove a file or directory at `filepath`.
|
|
1239
|
+
* @param opts - `recursive`, if `true`, removes directories and their contents; `force`, if `true`,
|
|
1240
|
+
* suppresses the error when `filepath` does not exist.
|
|
1241
|
+
* @throws {EISDIR} `filepath` is a directory and `opts.recursive` is not set.
|
|
1242
|
+
*/
|
|
1021
1243
|
export function rm(filepath: Path, opts?: RmOptions): Promise<void>
|
|
1022
1244
|
|
|
1023
1245
|
export function rm(filepath: Path, opts: RmOptions, cb: Callback): void
|
|
@@ -1026,24 +1248,35 @@ export function rm(filepath: Path, cb: Callback): void
|
|
|
1026
1248
|
|
|
1027
1249
|
export function rmSync(filepath: Path, opts?: RmOptions): void
|
|
1028
1250
|
|
|
1251
|
+
/**
|
|
1252
|
+
* Remove an empty directory.
|
|
1253
|
+
* @throws {ENOTEMPTY} the directory is not empty.
|
|
1254
|
+
*/
|
|
1029
1255
|
export function rmdir(filepath: Path): Promise<void>
|
|
1030
1256
|
|
|
1031
1257
|
export function rmdir(filepath: Path, cb: Callback): void
|
|
1032
1258
|
|
|
1033
1259
|
export function rmdirSync(filepath: Path): void
|
|
1034
1260
|
|
|
1261
|
+
/** Get the status of a file. Returns a `Stats` object. */
|
|
1035
1262
|
export function stat(filepath: Path): Promise<Stats>
|
|
1036
1263
|
|
|
1037
1264
|
export function stat(filepath: Path, cb: Callback<[stats: Stats | null]>): void
|
|
1038
1265
|
|
|
1039
1266
|
export function statSync(filepath: Path): Stats
|
|
1040
1267
|
|
|
1268
|
+
/** Get filesystem statistics. Returns a `StatFs` object. */
|
|
1041
1269
|
export function statfs(filepath: Path): Promise<StatFs>
|
|
1042
1270
|
|
|
1043
1271
|
export function statfs(filepath: Path, cb: Callback<[stats: StatFs | null]>): void
|
|
1044
1272
|
|
|
1045
1273
|
export function statfsSync(filepath: Path): StatFs
|
|
1046
1274
|
|
|
1275
|
+
/**
|
|
1276
|
+
* Create a symbolic link at `filepath` pointing to `target`. `type` may be `'file'`, `'dir'`, or
|
|
1277
|
+
* `'junction'` (Windows only) or a numeric flag. On Windows, if `type` is not provided, it is
|
|
1278
|
+
* inferred from the target.
|
|
1279
|
+
*/
|
|
1047
1280
|
export function symlink(target: Path, filepath: Path, type?: string | number): Promise<void>
|
|
1048
1281
|
|
|
1049
1282
|
export function symlink(target: Path, filepath: Path, type: string | number, cb: Callback): void
|
|
@@ -1052,6 +1285,7 @@ export function symlink(target: Path, filepath: Path, cb: Callback): void
|
|
|
1052
1285
|
|
|
1053
1286
|
export function symlinkSync(target: Path, filepath: Path, type?: string | number): void
|
|
1054
1287
|
|
|
1288
|
+
/** Truncate the file at `filename` to `len` bytes. `len` defaults to `0`. */
|
|
1055
1289
|
export function truncate(filepath: Path, len?: number): Promise<void>
|
|
1056
1290
|
|
|
1057
1291
|
export function truncate(filepath: Path, len: number, cb: Callback): void
|
|
@@ -1060,53 +1294,80 @@ export function truncate(filepath: Path, cb: Callback): void
|
|
|
1060
1294
|
|
|
1061
1295
|
export function truncateSync(filepath: Path, len?: number): void
|
|
1062
1296
|
|
|
1297
|
+
/**
|
|
1298
|
+
* Remove a file.
|
|
1299
|
+
* @param filepath - The path of the file to remove.
|
|
1300
|
+
*/
|
|
1063
1301
|
export function unlink(filepath: Path): Promise<void>
|
|
1064
1302
|
|
|
1065
1303
|
export function unlink(filepath: Path, cb: Callback): void
|
|
1066
1304
|
|
|
1067
1305
|
export function unlinkSync(filepath: Path): void
|
|
1068
1306
|
|
|
1307
|
+
/**
|
|
1308
|
+
* Watch a file or directory for changes. Returns a `Watcher` object. The `callback`, if provided,
|
|
1309
|
+
* is called with `(eventType, filename)` on each change. `filename` is `null` when the platform
|
|
1310
|
+
* could not report which file changed, such as when events were dropped, in which case the watched
|
|
1311
|
+
* path should be rescanned.
|
|
1312
|
+
* @param opts - `persistent` defaults to `true`; `recursive` (default `false`) also watches
|
|
1313
|
+
* subdirectories; `encoding` defaults to `'utf8'`.
|
|
1314
|
+
* @param cb - Called with `(eventType, filename)` on each change; equivalent to listening for the
|
|
1315
|
+
* `Watcher`'s `'change'` event.
|
|
1316
|
+
*/
|
|
1069
1317
|
export function watch(
|
|
1070
1318
|
filepath: Path,
|
|
1071
1319
|
opts: WatcherOptions & { encoding?: BufferEncoding },
|
|
1072
|
-
cb: (eventType: WatcherEventType, filename: string) => void
|
|
1320
|
+
cb: (eventType: WatcherEventType, filename: string | null) => void
|
|
1073
1321
|
): Watcher<string>
|
|
1074
1322
|
|
|
1075
1323
|
export function watch(
|
|
1076
1324
|
filepath: Path,
|
|
1077
1325
|
opts: WatcherOptions & { encoding: 'buffer' },
|
|
1078
|
-
cb: (eventType: WatcherEventType, filename: Buffer) => void
|
|
1326
|
+
cb: (eventType: WatcherEventType, filename: Buffer | null) => void
|
|
1079
1327
|
): Watcher<Buffer>
|
|
1080
1328
|
|
|
1081
1329
|
export function watch(
|
|
1082
1330
|
filepath: Path,
|
|
1083
1331
|
opts: WatcherOptions,
|
|
1084
|
-
cb: (eventType: WatcherEventType, filename: string | Buffer) => void
|
|
1332
|
+
cb: (eventType: WatcherEventType, filename: string | Buffer | null) => void
|
|
1085
1333
|
): Watcher
|
|
1086
1334
|
|
|
1087
1335
|
export function watch(
|
|
1088
1336
|
filepath: Path,
|
|
1089
1337
|
encoding: BufferEncoding,
|
|
1090
|
-
cb: (eventType: WatcherEventType, filename: string) => void
|
|
1338
|
+
cb: (eventType: WatcherEventType, filename: string | null) => void
|
|
1091
1339
|
): Watcher<string>
|
|
1092
1340
|
|
|
1093
1341
|
export function watch(
|
|
1094
1342
|
filepath: Path,
|
|
1095
1343
|
encoding: 'buffer',
|
|
1096
|
-
cb: (eventType: WatcherEventType, filename: Buffer) => void
|
|
1344
|
+
cb: (eventType: WatcherEventType, filename: Buffer | null) => void
|
|
1097
1345
|
): Watcher<Buffer>
|
|
1098
1346
|
|
|
1099
1347
|
export function watch(
|
|
1100
1348
|
filepath: Path,
|
|
1101
1349
|
encoding: BufferEncoding | 'buffer',
|
|
1102
|
-
cb: (eventType: WatcherEventType, filename: string | Buffer) => void
|
|
1350
|
+
cb: (eventType: WatcherEventType, filename: string | Buffer | null) => void
|
|
1103
1351
|
): Watcher
|
|
1104
1352
|
|
|
1105
1353
|
export function watch(
|
|
1106
1354
|
filepath: Path,
|
|
1107
|
-
cb: (eventType: WatcherEventType, filename: string) => void
|
|
1355
|
+
cb: (eventType: WatcherEventType, filename: string | null) => void
|
|
1108
1356
|
): Watcher<string>
|
|
1109
1357
|
|
|
1358
|
+
/**
|
|
1359
|
+
* Write `data` to a file descriptor. When `data` is a string, the signature is
|
|
1360
|
+
* `fs.write(fd, data[, pos[, encoding]])` where `encoding` defaults to `'utf8'`. Returns the number
|
|
1361
|
+
* of bytes written.
|
|
1362
|
+
* @param fd - The file descriptor to write to, as returned by `fs.open()`.
|
|
1363
|
+
* @param data - The bytes to write. May also be a string, in which case the signature becomes
|
|
1364
|
+
* `fs.write(fd, data[, pos[, encoding]])`.
|
|
1365
|
+
* @param offset - The offset within `data` to start writing from. Defaults to `0`.
|
|
1366
|
+
* @param len - The number of bytes to write. Defaults to `data.byteLength - offset`.
|
|
1367
|
+
* @param pos - The position in the file to write to. Defaults to `-1`, which writes at the current
|
|
1368
|
+
* file position and advances it.
|
|
1369
|
+
* @returns The number of bytes actually written, which may be less than `data`'s length.
|
|
1370
|
+
*/
|
|
1110
1371
|
export function write(
|
|
1111
1372
|
fd: number,
|
|
1112
1373
|
data: Buffer | ArrayBufferView,
|
|
@@ -1176,6 +1437,11 @@ export interface WriteFileOptions {
|
|
|
1176
1437
|
mode?: number
|
|
1177
1438
|
}
|
|
1178
1439
|
|
|
1440
|
+
/**
|
|
1441
|
+
* Write `data` to a file, replacing it if it already exists.
|
|
1442
|
+
* @param opts - `flag` defaults to `'w'` (truncating any existing file); `mode` defaults to
|
|
1443
|
+
* `0o666`.
|
|
1444
|
+
*/
|
|
1179
1445
|
export function writeFile(
|
|
1180
1446
|
filepath: Path,
|
|
1181
1447
|
data: string | Buffer | ArrayBufferView,
|
|
@@ -1220,6 +1486,10 @@ export function writeFileSync(
|
|
|
1220
1486
|
encoding: BufferEncoding
|
|
1221
1487
|
): void
|
|
1222
1488
|
|
|
1489
|
+
/**
|
|
1490
|
+
* Write an array of `buffers` to a file descriptor. `pos` defaults to `-1`.
|
|
1491
|
+
* @returns The number of bytes actually written across all buffers.
|
|
1492
|
+
*/
|
|
1223
1493
|
export function writev(fd: number, buffers: ArrayBufferView[], pos?: number): Promise<number>
|
|
1224
1494
|
|
|
1225
1495
|
export function writev(
|