bare-fs 4.7.4 → 4.8.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/binding.c CHANGED
@@ -328,7 +328,7 @@ bare_fs_request_result_statfs(js_env_t *env, js_callback_info_t *info) {
328
328
  uv_statfs_t *statfs = req->handle.ptr;
329
329
 
330
330
  js_value_t *result;
331
- err = js_create_array_with_length(env, 7, &result);
331
+ err = js_create_array_with_length(env, 8, &result);
332
332
  assert(err == 0);
333
333
 
334
334
  uint32_t i = 0;
@@ -349,6 +349,7 @@ bare_fs_request_result_statfs(js_env_t *env, js_callback_info_t *info) {
349
349
  V(bavail)
350
350
  V(files)
351
351
  V(ffree)
352
+ V(frsize)
352
353
  #undef V
353
354
 
354
355
  return result;
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
@@ -128,6 +167,7 @@ export interface StatFs {
128
167
  readonly bavail: number
129
168
  readonly files: number
130
169
  readonly ffree: number
170
+ readonly frsize: number
131
171
  }
132
172
 
133
173
  export class StatFs {
@@ -138,12 +178,20 @@ export class StatFs {
138
178
  bfree: number,
139
179
  bavail: number,
140
180
  files: number,
141
- ffree: number
181
+ ffree: number,
182
+ frsize: number
142
183
  )
143
184
  }
144
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
+ */
145
191
  export interface ReadStreamOptions {
192
+ /** The underlying file descriptor. */
146
193
  fd?: number
194
+ /** The flags the file was opened with. */
147
195
  flags?: Flag
148
196
  mode?: number
149
197
  start?: number
@@ -161,8 +209,19 @@ export class ReadStream {
161
209
  private constructor(path: Path | null, opts?: ReadStreamOptions)
162
210
  }
163
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
+ */
164
219
  export function createReadStream(path: Path | null, opts?: ReadStreamOptions): ReadStream
165
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
+ */
166
225
  export interface WriteStreamOptions {
167
226
  fd?: number
168
227
  flags?: Flag
@@ -180,8 +239,19 @@ export class WriteStream {
180
239
  private constructor(path: Path | null, opts?: WriteStreamOptions)
181
240
  }
182
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
+ */
183
248
  export function createWriteStream(path: Path | null, opts?: WriteStreamOptions): WriteStream
184
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
+ */
185
255
  export interface WatcherOptions {
186
256
  persistent?: boolean
187
257
  recursive?: boolean
@@ -193,6 +263,7 @@ export type WatcherEventType = 'rename' | 'change'
193
263
  export interface WatcherEvents<T extends string | Buffer = string | Buffer> extends EventMap {
194
264
  error: [err: Error]
195
265
  change: [eventType: WatcherEventType, filename: T]
266
+ /** Emitted once the watcher has stopped watching. */
196
267
  close: []
197
268
  }
198
269
 
@@ -200,8 +271,11 @@ export interface Watcher<T extends string | Buffer = string | Buffer>
200
271
  extends
201
272
  EventEmitter<WatcherEvents<T>>,
202
273
  AsyncIterable<{ eventType: WatcherEventType; filename: T }> {
274
+ /** Stop watching for further changes. Once closed, a `close` event is emitted. */
203
275
  close(): void
276
+ /** Prevent the event loop from exiting while the watcher is active. */
204
277
  ref(): void
278
+ /** Allow the event loop to exit even if the watcher is still active. */
205
279
  unref(): void
206
280
  }
207
281
 
@@ -209,6 +283,11 @@ export class Watcher {
209
283
  private constructor(path: Path, opts: WatcherOptions)
210
284
  }
211
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
+ */
212
291
  export function access(filepath: Path, mode?: number): Promise<void>
213
292
 
214
293
  export function access(filepath: Path, mode: number, cb: Callback): void
@@ -223,6 +302,10 @@ export interface AppendFileOptions {
223
302
  mode?: number
224
303
  }
225
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
+ */
226
309
  export function appendFile(
227
310
  filepath: Path,
228
311
  data: string | Buffer | ArrayBufferView,
@@ -267,24 +350,42 @@ export function appendFileSync(
267
350
  encoding: BufferEncoding
268
351
  ): void
269
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
+ */
270
357
  export function chmod(filepath: Path, mode: string | number): Promise<void>
271
358
 
272
359
  export function chmod(filepath: Path, mode: string | number, cb: Callback): void
273
360
 
274
361
  export function chmodSync(filepath: Path, mode: string | number): void
275
362
 
363
+ /** Change the owner and group of a file. */
276
364
  export function chown(filepath: Path, uid: number, gid: number): Promise<void>
277
365
 
278
366
  export function chown(filepath: Path, uid: number, gid: number, cb: Callback): void
279
367
 
280
368
  export function chownSync(filepath: Path, uid: number, gid: number): void
281
369
 
370
+ /**
371
+ * Close a file descriptor.
372
+ * @param fd - The file descriptor to close, as returned by `fs.open()`.
373
+ */
282
374
  export function close(fd: number): Promise<void>
283
375
 
284
376
  export function close(fd: number, cb: Callback): void
285
377
 
378
+ /** Close the directory handle opened by `fs.opendirSync()`. */
286
379
  export function closeSync(fd: number): void
287
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
+ */
288
389
  export function copyFile(src: Path, dst: Path, mode?: number): Promise<void>
289
390
 
290
391
  export function copyFile(src: Path, dst: Path, mode: number, cb: Callback): void
@@ -293,10 +394,20 @@ export function copyFile(src: Path, dst: Path, cb: Callback): void
293
394
 
294
395
  export function copyFileSync(src: Path, dst: Path, mode?: number): void
295
396
 
397
+ /**
398
+ * Options for `fs.cp()`. `recursive` must be `true` to copy a directory; without it, copying a
399
+ * directory throws `EISDIR`.
400
+ */
296
401
  export interface CpOptions {
297
402
  recursive?: boolean
298
403
  }
299
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
+ */
300
411
  export function cp(src: Path, dst: Path, opts?: CpOptions): Promise<void>
301
412
 
302
413
  export function cp(src: Path, dst: Path, opts: CpOptions, cb: Callback): void
@@ -305,42 +416,54 @@ export function cp(src: Path, dst: Path, cb: Callback): void
305
416
 
306
417
  export function cpSync(src: Path, dst: Path, opts?: CpOptions): void
307
418
 
419
+ /**
420
+ * Check whether a file exists at `filepath`. Returns `true` if the file is accessible, `false`
421
+ * otherwise.
422
+ */
308
423
  export function exists(filepath: Path): Promise<boolean>
309
424
 
310
425
  export function exists(filepath: Path, cb: (exists: boolean) => void): void
311
426
 
312
427
  export function existsSync(filepath: Path): boolean
313
428
 
429
+ /** Change the permissions of a file by its file descriptor. */
314
430
  export function fchmod(fd: number, mode: string | number): Promise<void>
315
431
 
316
432
  export function fchmod(fd: number, mode: string | number, cb: Callback): void
317
433
 
318
434
  export function fchmodSync(fd: number, mode: string | number): void
319
435
 
436
+ /** Change the owner and group of a file by its file descriptor. */
320
437
  export function fchown(fd: number, uid: number, gid: number): Promise<void>
321
438
 
322
439
  export function fchown(fd: number, uid: number, gid: number, cb: Callback): void
323
440
 
324
441
  export function fchownSync(fd: number, uid: number, gid: number): void
325
442
 
443
+ /** Similar to `fsync`, but does not flush modified metadata unless necessary. */
326
444
  export function fdatasync(fd: number): Promise<void>
327
445
 
328
446
  export function fdatasync(fd: number, cb: Callback): void
329
447
 
330
448
  export function fdatasyncSync(fd: number): void
331
449
 
450
+ /** Get the status of a file by its file descriptor. Returns a `Stats` object. */
332
451
  export function fstat(fd: number): Promise<Stats>
333
452
 
334
453
  export function fstat(fd: number, cb: Callback<[stats: Stats | null]>): void
335
454
 
336
455
  export function fstatSync(fd: number): Stats
337
456
 
457
+ /**
458
+ * Flush all modified in-core data of the file referred by its file descriptor to the disk device.
459
+ */
338
460
  export function fsync(fd: number): Promise<void>
339
461
 
340
462
  export function fsync(fd: number, cb: Callback): void
341
463
 
342
464
  export function fsyncSync(fd: number): void
343
465
 
466
+ /** Truncate a file to `len` bytes. `len` defaults to `0`. */
344
467
  export function ftruncate(fd: number, len?: number): Promise<void>
345
468
 
346
469
  export function ftruncate(fd: number, len: number, cb: Callback): void
@@ -349,18 +472,30 @@ export function ftruncate(fd: number, cb: Callback): void
349
472
 
350
473
  export function ftruncateSync(fd: number, len?: number): void
351
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
+ */
352
479
  export function lchown(filepath: Path, uid: number, gid: number): Promise<void>
353
480
 
354
481
  export function lchown(filepath: Path, uid: number, gid: number, cb: Callback): void
355
482
 
356
483
  export function lchownSync(filepath: Path, uid: number, gid: number): void
357
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
+ */
358
489
  export function lstat(filepath: Path): Promise<Stats>
359
490
 
360
491
  export function lstat(filepath: Path, cb: Callback<[stats: Stats | null]>): void
361
492
 
362
493
  export function lstatSync(filepath: Path): Stats
363
494
 
495
+ /**
496
+ * Change the access and modification times of a file. Times may be numbers (seconds since epoch) or
497
+ * `Date` objects.
498
+ */
364
499
  export function utimes(filepath: Path, atime: number | Date, mtime: number | Date): Promise<void>
365
500
 
366
501
  export function utimes(
@@ -372,6 +507,10 @@ export function utimes(
372
507
 
373
508
  export function utimesSync(filepath: Path, atime: number | Date, mtime: number | Date): void
374
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
+ */
375
514
  export function lutimes(filepath: Path, atime: number | Date, mtime: number | Date): Promise<void>
376
515
 
377
516
  export function lutimes(
@@ -383,23 +522,40 @@ export function lutimes(
383
522
 
384
523
  export function lutimesSync(filepath: Path, atime: number | Date, mtime: number | Date): void
385
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
+ */
386
529
  export function futimes(fd: number, atime: number | Date, mtime: number | Date): Promise<void>
387
530
 
388
531
  export function futimes(fd: number, atime: number | Date, mtime: number | Date, cb: Callback): void
389
532
 
390
533
  export function futimesSync(fd: number, atime: number | Date, mtime: number | Date): void
391
534
 
535
+ /** Creates a new link (also known as a hard link) to an existing file. */
392
536
  export function link(src: Path, dst: Path): Promise<void>
393
537
 
394
538
  export function link(src: Path, dst: Path, cb: Callback): void
395
539
 
396
540
  export function linkSync(src: Path, dst: Path): void
397
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
+ */
398
546
  export interface MkdirOptions {
399
547
  mode?: number
400
548
  recursive?: boolean
401
549
  }
402
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
+ */
403
559
  export function mkdir(filepath: Path, opts?: MkdirOptions): Promise<void>
404
560
 
405
561
  export function mkdir(filepath: Path, mode: number): Promise<void>
@@ -414,12 +570,31 @@ export function mkdirSync(filepath: Path, opts?: MkdirOptions): void
414
570
 
415
571
  export function mkdirSync(filepath: Path, mode: number): void
416
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
+ */
417
579
  export function mkdtemp(prefix: Path): Promise<string>
418
580
 
419
581
  export function mkdtemp(prefix: Path, cb: Callback<[path: string | null]>): void
420
582
 
421
583
  export function mkdtempSync(prefix: Path): string
422
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
+ */
423
598
  export function open(filepath: Path, flags?: Flag | number, mode?: string | number): Promise<number>
424
599
 
425
600
  export function open(
@@ -435,11 +610,16 @@ export function open(filepath: Path, cb: Callback<[fd: number]>): void
435
610
 
436
611
  export function openSync(filepath: Path, flags?: Flag | number, mode?: string | number): number
437
612
 
613
+ /**
614
+ * Options for `fs.opendir()`. `bufferSize` defaults to `32` and sets how many directory entries are
615
+ * buffered internally per read.
616
+ */
438
617
  export interface OpendirOptions {
439
618
  encoding?: BufferEncoding | 'buffer'
440
619
  bufferSize?: number
441
620
  }
442
621
 
622
+ /** Open a directory for iteration. Returns a `Dir` object. */
443
623
  export function opendir(
444
624
  filepath: Path,
445
625
  opts: OpendirOptions & { encoding?: BufferEncoding }
@@ -514,6 +694,17 @@ export function opendirSync(filepath: Path, encoding: BufferEncoding | 'buffer')
514
694
 
515
695
  export function opendirSync(filepath: Path): Dir<string>
516
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
+ */
517
708
  export function read(
518
709
  fd: number,
519
710
  buffer: Buffer | ArrayBufferView,
@@ -552,6 +743,10 @@ export function read(
552
743
  cb: Callback<[len: number]>
553
744
  ): void
554
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
+ */
555
750
  export function readSync(
556
751
  fd: number,
557
752
  buffer: Buffer | ArrayBufferView,
@@ -565,6 +760,12 @@ export interface ReadFileOptions {
565
760
  flag?: Flag
566
761
  }
567
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
+ */
568
769
  export function readFile(
569
770
  filepath: Path,
570
771
  opts: ReadFileOptions & { encoding: BufferEncoding }
@@ -645,6 +846,12 @@ export function readFileSync(filepath: Path): Buffer
645
846
  export interface ReaddirOptions extends OpendirOptions {
646
847
  withFileTypes?: boolean
647
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
+ */
648
855
  export function readdir(
649
856
  filepath: Path,
650
857
  opts: ReaddirOptions & { encoding?: BufferEncoding }
@@ -832,6 +1039,7 @@ export interface ReadlinkOptions {
832
1039
  encoding?: BufferEncoding | 'buffer'
833
1040
  }
834
1041
 
1042
+ /** Read the target of a symbolic link. */
835
1043
  export function readlink(
836
1044
  filepath: Path,
837
1045
  opts: ReadlinkOptions & { encoding?: BufferEncoding }
@@ -910,6 +1118,10 @@ export function readlinkSync(filepath: Path, encoding: BufferEncoding | 'buffer'
910
1118
 
911
1119
  export function readlinkSync(filepath: Path): string
912
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
+ */
913
1125
  export function readv(fd: number, buffers: ArrayBufferView[], position?: number): Promise<number>
914
1126
 
915
1127
  export function readv(
@@ -927,6 +1139,7 @@ export interface RealpathOptions {
927
1139
  encoding?: BufferEncoding | 'buffer'
928
1140
  }
929
1141
 
1142
+ /** Resolve the real path of `filepath`, expanding all symbolic links. */
930
1143
  export function realpath(
931
1144
  filepath: Path,
932
1145
  opts: RealpathOptions & { encoding?: BufferEncoding }
@@ -1005,17 +1218,28 @@ export function realpathSync(filepath: Path, encoding: BufferEncoding | 'buffer'
1005
1218
 
1006
1219
  export function realpathSync(filepath: Path): string
1007
1220
 
1221
+ /** Rename a file from `src` to `dst`. */
1008
1222
  export function rename(src: Path, dst: Path): Promise<void>
1009
1223
 
1010
1224
  export function rename(src: Path, dst: Path, cb: Callback): void
1011
1225
 
1012
1226
  export function renameSync(src: Path, dst: Path): void
1013
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
+ */
1014
1232
  export interface RmOptions {
1015
1233
  force?: boolean
1016
1234
  recursive?: boolean
1017
1235
  }
1018
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
+ */
1019
1243
  export function rm(filepath: Path, opts?: RmOptions): Promise<void>
1020
1244
 
1021
1245
  export function rm(filepath: Path, opts: RmOptions, cb: Callback): void
@@ -1024,24 +1248,35 @@ export function rm(filepath: Path, cb: Callback): void
1024
1248
 
1025
1249
  export function rmSync(filepath: Path, opts?: RmOptions): void
1026
1250
 
1251
+ /**
1252
+ * Remove an empty directory.
1253
+ * @throws {ENOTEMPTY} the directory is not empty.
1254
+ */
1027
1255
  export function rmdir(filepath: Path): Promise<void>
1028
1256
 
1029
1257
  export function rmdir(filepath: Path, cb: Callback): void
1030
1258
 
1031
1259
  export function rmdirSync(filepath: Path): void
1032
1260
 
1261
+ /** Get the status of a file. Returns a `Stats` object. */
1033
1262
  export function stat(filepath: Path): Promise<Stats>
1034
1263
 
1035
1264
  export function stat(filepath: Path, cb: Callback<[stats: Stats | null]>): void
1036
1265
 
1037
1266
  export function statSync(filepath: Path): Stats
1038
1267
 
1268
+ /** Get filesystem statistics. Returns a `StatFs` object. */
1039
1269
  export function statfs(filepath: Path): Promise<StatFs>
1040
1270
 
1041
1271
  export function statfs(filepath: Path, cb: Callback<[stats: StatFs | null]>): void
1042
1272
 
1043
1273
  export function statfsSync(filepath: Path): StatFs
1044
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
+ */
1045
1280
  export function symlink(target: Path, filepath: Path, type?: string | number): Promise<void>
1046
1281
 
1047
1282
  export function symlink(target: Path, filepath: Path, type: string | number, cb: Callback): void
@@ -1050,6 +1285,7 @@ export function symlink(target: Path, filepath: Path, cb: Callback): void
1050
1285
 
1051
1286
  export function symlinkSync(target: Path, filepath: Path, type?: string | number): void
1052
1287
 
1288
+ /** Truncate the file at `filename` to `len` bytes. `len` defaults to `0`. */
1053
1289
  export function truncate(filepath: Path, len?: number): Promise<void>
1054
1290
 
1055
1291
  export function truncate(filepath: Path, len: number, cb: Callback): void
@@ -1058,12 +1294,24 @@ export function truncate(filepath: Path, cb: Callback): void
1058
1294
 
1059
1295
  export function truncateSync(filepath: Path, len?: number): void
1060
1296
 
1297
+ /**
1298
+ * Remove a file.
1299
+ * @param filepath - The path of the file to remove.
1300
+ */
1061
1301
  export function unlink(filepath: Path): Promise<void>
1062
1302
 
1063
1303
  export function unlink(filepath: Path, cb: Callback): void
1064
1304
 
1065
1305
  export function unlinkSync(filepath: Path): void
1066
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.
1310
+ * @param opts - `persistent` defaults to `true`; `recursive` (default `false`) also watches
1311
+ * subdirectories; `encoding` defaults to `'utf8'`.
1312
+ * @param cb - Called with `(eventType, filename)` on each change; equivalent to listening for the
1313
+ * `Watcher`'s `'change'` event.
1314
+ */
1067
1315
  export function watch(
1068
1316
  filepath: Path,
1069
1317
  opts: WatcherOptions & { encoding?: BufferEncoding },
@@ -1105,6 +1353,19 @@ export function watch(
1105
1353
  cb: (eventType: WatcherEventType, filename: string) => void
1106
1354
  ): Watcher<string>
1107
1355
 
1356
+ /**
1357
+ * Write `data` to a file descriptor. When `data` is a string, the signature is
1358
+ * `fs.write(fd, data[, pos[, encoding]])` where `encoding` defaults to `'utf8'`. Returns the number
1359
+ * of bytes written.
1360
+ * @param fd - The file descriptor to write to, as returned by `fs.open()`.
1361
+ * @param data - The bytes to write. May also be a string, in which case the signature becomes
1362
+ * `fs.write(fd, data[, pos[, encoding]])`.
1363
+ * @param offset - The offset within `data` to start writing from. Defaults to `0`.
1364
+ * @param len - The number of bytes to write. Defaults to `data.byteLength - offset`.
1365
+ * @param pos - The position in the file to write to. Defaults to `-1`, which writes at the current
1366
+ * file position and advances it.
1367
+ * @returns The number of bytes actually written, which may be less than `data`'s length.
1368
+ */
1108
1369
  export function write(
1109
1370
  fd: number,
1110
1371
  data: Buffer | ArrayBufferView,
@@ -1174,6 +1435,11 @@ export interface WriteFileOptions {
1174
1435
  mode?: number
1175
1436
  }
1176
1437
 
1438
+ /**
1439
+ * Write `data` to a file, replacing it if it already exists.
1440
+ * @param opts - `flag` defaults to `'w'` (truncating any existing file); `mode` defaults to
1441
+ * `0o666`.
1442
+ */
1177
1443
  export function writeFile(
1178
1444
  filepath: Path,
1179
1445
  data: string | Buffer | ArrayBufferView,
@@ -1218,6 +1484,10 @@ export function writeFileSync(
1218
1484
  encoding: BufferEncoding
1219
1485
  ): void
1220
1486
 
1487
+ /**
1488
+ * Write an array of `buffers` to a file descriptor. `pos` defaults to `-1`.
1489
+ * @returns The number of bytes actually written across all buffers.
1490
+ */
1221
1491
  export function writev(fd: number, buffers: ArrayBufferView[], pos?: number): Promise<number>
1222
1492
 
1223
1493
  export function writev(