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/README.md
CHANGED
|
@@ -26,963 +26,7 @@ try {
|
|
|
26
26
|
|
|
27
27
|
## API
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
Open a file, returning a file descriptor. `flags` defaults to `'r'` and `mode` defaults to `0o666`. `flags` may be a string such as `'r'`, `'w'`, `'a'`, `'r+'`, etc., or a numeric combination of `fs.constants` flags.
|
|
32
|
-
|
|
33
|
-
#### `fs.open(filepath[, flags[, mode]], callback)`
|
|
34
|
-
|
|
35
|
-
Callback version of `fs.open()`.
|
|
36
|
-
|
|
37
|
-
#### `const fd = fs.openSync(filepath[, flags[, mode]])`
|
|
38
|
-
|
|
39
|
-
Synchronous version of `fs.open()`.
|
|
40
|
-
|
|
41
|
-
#### `await fs.close(fd)`
|
|
42
|
-
|
|
43
|
-
Close a file descriptor.
|
|
44
|
-
|
|
45
|
-
#### `fs.close(fd, callback)`
|
|
46
|
-
|
|
47
|
-
Callback version of `fs.close()`.
|
|
48
|
-
|
|
49
|
-
#### `fs.closeSync(fd)`
|
|
50
|
-
|
|
51
|
-
Synchronous version of `fs.close()`.
|
|
52
|
-
|
|
53
|
-
#### `await fs.access(filepath[, mode])`
|
|
54
|
-
|
|
55
|
-
Check whether the file at `filepath` is accessible. `mode` defaults to `fs.constants.F_OK`.
|
|
56
|
-
|
|
57
|
-
#### `fs.access(filepath[, mode], callback)`
|
|
58
|
-
|
|
59
|
-
Callback version of `fs.access()`.
|
|
60
|
-
|
|
61
|
-
#### `fs.accessSync(filepath[, mode])`
|
|
62
|
-
|
|
63
|
-
Synchronous version of `fs.access()`.
|
|
64
|
-
|
|
65
|
-
#### `const exists = await fs.exists(filepath)`
|
|
66
|
-
|
|
67
|
-
Check whether a file exists at `filepath`. Returns `true` if the file is accessible, `false` otherwise.
|
|
68
|
-
|
|
69
|
-
#### `fs.exists(filepath, callback)`
|
|
70
|
-
|
|
71
|
-
Callback version of `fs.exists()`.
|
|
72
|
-
|
|
73
|
-
#### `const exists = fs.existsSync(filepath)`
|
|
74
|
-
|
|
75
|
-
Synchronous version of `fs.exists()`.
|
|
76
|
-
|
|
77
|
-
#### `const bytesRead = await fs.read(fd, buffer[, offset[, len[, pos]]])`
|
|
78
|
-
|
|
79
|
-
Read from a file descriptor into `buffer`. `offset` defaults to `0`, `len` defaults to `buffer.byteLength - offset`, and `pos` defaults to `-1` (current position). Returns the number of bytes read.
|
|
80
|
-
|
|
81
|
-
#### `fs.read(fd, buffer[, offset[, len[, pos]]], callback)`
|
|
82
|
-
|
|
83
|
-
Callback version of `fs.read()`.
|
|
84
|
-
|
|
85
|
-
#### `const bytesRead = fs.readSync(fd, buffer[, offset[, len[, pos]]])`
|
|
86
|
-
|
|
87
|
-
Synchronous version of `fs.read()`.
|
|
88
|
-
|
|
89
|
-
#### `const bytesRead = await fs.readv(fd, buffers[, pos])`
|
|
90
|
-
|
|
91
|
-
Read from a file descriptor into an array of `buffers`. `pos` defaults to `-1`.
|
|
92
|
-
|
|
93
|
-
#### `fs.readv(fd, buffers[, pos], callback)`
|
|
94
|
-
|
|
95
|
-
Callback version of `fs.readv()`.
|
|
96
|
-
|
|
97
|
-
#### `const bytesRead = fs.readvSync(fd, buffers[, pos])`
|
|
98
|
-
|
|
99
|
-
Synchronous version of `fs.readv()`.
|
|
100
|
-
|
|
101
|
-
#### `const bytesWritten = await fs.write(fd, data[, offset[, len[, pos]]])`
|
|
102
|
-
|
|
103
|
-
Write `data` to a file descriptor. When `data` is a string, the signature is `fs.write(fd, data[, pos[, encoding]])` where `encoding` defaults to `'utf8'`. Returns the number of bytes written.
|
|
104
|
-
|
|
105
|
-
#### `fs.write(fd, data[, offset[, len[, pos]]], callback)`
|
|
106
|
-
|
|
107
|
-
Callback version of `fs.write()`.
|
|
108
|
-
|
|
109
|
-
#### `const bytesWritten = fs.writeSync(fd, data[, offset[, len[, pos]]])`
|
|
110
|
-
|
|
111
|
-
Synchronous version of `fs.write()`.
|
|
112
|
-
|
|
113
|
-
#### `const bytesWritten = await fs.writev(fd, buffers[, pos])`
|
|
114
|
-
|
|
115
|
-
Write an array of `buffers` to a file descriptor. `pos` defaults to `-1`.
|
|
116
|
-
|
|
117
|
-
#### `fs.writev(fd, buffers[, pos], callback)`
|
|
118
|
-
|
|
119
|
-
Callback version of `fs.writev()`.
|
|
120
|
-
|
|
121
|
-
#### `const bytesWritten = fs.writevSync(fd, buffers[, pos])`
|
|
122
|
-
|
|
123
|
-
Synchronous version of `fs.writev()`.
|
|
124
|
-
|
|
125
|
-
#### `const stats = await fs.stat(filepath)`
|
|
126
|
-
|
|
127
|
-
Get the status of a file. Returns a `Stats` object.
|
|
128
|
-
|
|
129
|
-
#### `fs.stat(filepath, callback)`
|
|
130
|
-
|
|
131
|
-
Callback version of `fs.stat()`.
|
|
132
|
-
|
|
133
|
-
#### `const stats = fs.statSync(filepath)`
|
|
134
|
-
|
|
135
|
-
Synchronous version of `fs.stat()`.
|
|
136
|
-
|
|
137
|
-
#### `const stats = await fs.lstat(filepath)`
|
|
138
|
-
|
|
139
|
-
Like `fs.stat()`, but if `filepath` is a symbolic link, the link itself is statted, not the file it refers to.
|
|
140
|
-
|
|
141
|
-
#### `fs.lstat(filepath, callback)`
|
|
142
|
-
|
|
143
|
-
Callback version of `fs.lstat()`.
|
|
144
|
-
|
|
145
|
-
#### `const stats = fs.lstatSync(filepath)`
|
|
146
|
-
|
|
147
|
-
Synchronous version of `fs.lstat()`.
|
|
148
|
-
|
|
149
|
-
#### `const stats = await fs.fstat(fd)`
|
|
150
|
-
|
|
151
|
-
Get the status of a file by its file descriptor. Returns a `Stats` object.
|
|
152
|
-
|
|
153
|
-
#### `fs.fstat(fd, callback)`
|
|
154
|
-
|
|
155
|
-
Callback version of `fs.fstat()`.
|
|
156
|
-
|
|
157
|
-
#### `const stats = fs.fstatSync(fd)`
|
|
158
|
-
|
|
159
|
-
Synchronous version of `fs.fstat()`.
|
|
160
|
-
|
|
161
|
-
#### `const stats = await fs.statfs(filepath)`
|
|
162
|
-
|
|
163
|
-
Get filesystem statistics. Returns a `StatFs` object.
|
|
164
|
-
|
|
165
|
-
#### `fs.statfs(filepath, callback)`
|
|
166
|
-
|
|
167
|
-
Callback version of `fs.statfs()`.
|
|
168
|
-
|
|
169
|
-
#### `const stats = fs.statfsSync(filepath)`
|
|
170
|
-
|
|
171
|
-
Synchronous version of `fs.statfs()`.
|
|
172
|
-
|
|
173
|
-
#### `await fs.ftruncate(fd[, len])`
|
|
174
|
-
|
|
175
|
-
Truncate a file to `len` bytes. `len` defaults to `0`.
|
|
176
|
-
|
|
177
|
-
#### `fs.ftruncate(fd[, len], callback)`
|
|
178
|
-
|
|
179
|
-
Callback version of `fs.ftruncate()`.
|
|
180
|
-
|
|
181
|
-
#### `fs.ftruncateSync(fd[, len])`
|
|
182
|
-
|
|
183
|
-
Synchronous version of `fs.ftruncate()`.
|
|
184
|
-
|
|
185
|
-
#### `await fs.chmod(filepath, mode)`
|
|
186
|
-
|
|
187
|
-
Change the permissions of a file. `mode` may be a numeric mode or a string that will be parsed as octal.
|
|
188
|
-
|
|
189
|
-
#### `fs.chmod(filepath, mode, callback)`
|
|
190
|
-
|
|
191
|
-
Callback version of `fs.chmod()`.
|
|
192
|
-
|
|
193
|
-
#### `fs.chmodSync(filepath, mode)`
|
|
194
|
-
|
|
195
|
-
Synchronous version of `fs.chmod()`.
|
|
196
|
-
|
|
197
|
-
#### `await fs.fchmod(fd, mode)`
|
|
198
|
-
|
|
199
|
-
Change the permissions of a file by its file descriptor.
|
|
200
|
-
|
|
201
|
-
#### `fs.fchmod(fd, mode, callback)`
|
|
202
|
-
|
|
203
|
-
Callback version of `fs.fchmod()`.
|
|
204
|
-
|
|
205
|
-
#### `fs.fchmodSync(fd, mode)`
|
|
206
|
-
|
|
207
|
-
Synchronous version of `fs.fchmod()`.
|
|
208
|
-
|
|
209
|
-
#### `await fs.chown(filepath, uid, gid)`
|
|
210
|
-
|
|
211
|
-
Change the owner and group of a file.
|
|
212
|
-
|
|
213
|
-
**NOTE**: The `chown` functions are not implemented on Windows.
|
|
214
|
-
|
|
215
|
-
#### `fs.chown(filepath, uid, gid, callback)`
|
|
216
|
-
|
|
217
|
-
Callback version of `fs.chown()`.
|
|
218
|
-
|
|
219
|
-
#### `await fs.chownSync(filepath, uid, gid)`
|
|
220
|
-
|
|
221
|
-
Synchronous version of `fs.chown()`.
|
|
222
|
-
|
|
223
|
-
#### `await fs.lchown(filepath, uid, gid)`
|
|
224
|
-
|
|
225
|
-
Change the owner and group of a file, but if `filepath` is a symbolic link, the changes are applied only to the link, not the file it refers to.
|
|
226
|
-
|
|
227
|
-
#### `fs.lchown(filepath, uid, gid, callback)`
|
|
228
|
-
|
|
229
|
-
Callback version of `fs.lchown()`.
|
|
230
|
-
|
|
231
|
-
#### `fs.lchownSync(filepath, uid, gid)`
|
|
232
|
-
|
|
233
|
-
Synchronous version of `fs.lchown()`.
|
|
234
|
-
|
|
235
|
-
#### `await fs.fchown(filepath, uid, gid)`
|
|
236
|
-
|
|
237
|
-
Change the owner and group of a file by its file descriptor.
|
|
238
|
-
|
|
239
|
-
#### `fs.fchown(filepath, uid, gid, callback)`
|
|
240
|
-
|
|
241
|
-
Callback version of `fs.fchown()`.
|
|
242
|
-
|
|
243
|
-
#### `fs.fchownSync(filepath, uid, gid)`
|
|
244
|
-
|
|
245
|
-
Synchronous version of `fs.fchown()`.
|
|
246
|
-
|
|
247
|
-
#### `await fs.utimes(filepath, atime, mtime)`
|
|
248
|
-
|
|
249
|
-
Change the access and modification times of a file. Times may be numbers (seconds since epoch) or `Date` objects.
|
|
250
|
-
|
|
251
|
-
#### `fs.utimes(filepath, atime, mtime, callback)`
|
|
252
|
-
|
|
253
|
-
Callback version of `fs.utimes()`.
|
|
254
|
-
|
|
255
|
-
#### `fs.utimesSync(filepath, atime, mtime)`
|
|
256
|
-
|
|
257
|
-
Synchronous version of `fs.utimes()`.
|
|
258
|
-
|
|
259
|
-
#### `await fs.lutimes(filepath, atime, mtime)`
|
|
260
|
-
|
|
261
|
-
Like `fs.utimes()`, but if `filepath` is a symbolic link, the timestamps of the link is changed, not the file it refers to.
|
|
262
|
-
|
|
263
|
-
#### `fs.lutimes(filepath, atime, mtime, callback)`
|
|
264
|
-
|
|
265
|
-
Callback version of `fs.lutimes()`.
|
|
266
|
-
|
|
267
|
-
#### `fs.lutimesSync(filepath, atime, mtime)`
|
|
268
|
-
|
|
269
|
-
Synchronous version of `fs.lutimes()`.
|
|
270
|
-
|
|
271
|
-
#### `await fs.futimes(fd, atime, mtime)`
|
|
272
|
-
|
|
273
|
-
Change the access and modification times of a file by its file descriptor. Times may be numbers (seconds since epoch) or `Date` objects.
|
|
274
|
-
|
|
275
|
-
#### `fs.futimes(fd, atime, mtime, callback)`
|
|
276
|
-
|
|
277
|
-
Callback version of `fs.futimes()`.
|
|
278
|
-
|
|
279
|
-
#### `fs.futimesSync(fd, atime, mtime)`
|
|
280
|
-
|
|
281
|
-
Synchronous version of `fs.futimes()`.
|
|
282
|
-
|
|
283
|
-
#### `await fs.link(src, dst)`
|
|
284
|
-
|
|
285
|
-
Creates a new link (also known as a hard link) to an existing file.
|
|
286
|
-
|
|
287
|
-
#### `fs.link(src, dst, callback)`
|
|
288
|
-
|
|
289
|
-
Callback version of `fs.link()`.
|
|
290
|
-
|
|
291
|
-
#### `fs.linkSync(src, dst)`
|
|
292
|
-
|
|
293
|
-
Synchronous version of `fs.link()`.
|
|
294
|
-
|
|
295
|
-
#### `await fs.mkdir(filepath[, opts])`
|
|
296
|
-
|
|
297
|
-
Create a directory at `filepath`.
|
|
298
|
-
|
|
299
|
-
Options include:
|
|
300
|
-
|
|
301
|
-
```js
|
|
302
|
-
options = {
|
|
303
|
-
mode: 0o777,
|
|
304
|
-
recursive: false
|
|
305
|
-
}
|
|
306
|
-
```
|
|
307
|
-
|
|
308
|
-
If `opts` is a number, it is treated as the `mode`. When `recursive` is `true`, parent directories are created as needed.
|
|
309
|
-
|
|
310
|
-
#### `fs.mkdir(filepath[, opts], callback)`
|
|
311
|
-
|
|
312
|
-
Callback version of `fs.mkdir()`.
|
|
313
|
-
|
|
314
|
-
#### `fs.mkdirSync(filepath[, opts])`
|
|
315
|
-
|
|
316
|
-
Synchronous version of `fs.mkdir()`.
|
|
317
|
-
|
|
318
|
-
#### `const path = await fs.mkdtemp(prefix)`
|
|
319
|
-
|
|
320
|
-
Create a unique temporary directory.
|
|
321
|
-
|
|
322
|
-
#### `fs.mkdtemp(prefix, callback)`
|
|
323
|
-
|
|
324
|
-
Callback version of `fs.mkdtemp()`.
|
|
325
|
-
|
|
326
|
-
#### `const path = fs.mkdtempSync(prefix)`
|
|
327
|
-
|
|
328
|
-
Synchronous version of `fs.mkdtemp()`.
|
|
329
|
-
|
|
330
|
-
#### `await fs.rmdir(filepath)`
|
|
331
|
-
|
|
332
|
-
Remove an empty directory.
|
|
333
|
-
|
|
334
|
-
#### `fs.rmdir(filepath, callback)`
|
|
335
|
-
|
|
336
|
-
Callback version of `fs.rmdir()`.
|
|
337
|
-
|
|
338
|
-
#### `fs.rmdirSync(filepath)`
|
|
339
|
-
|
|
340
|
-
Synchronous version of `fs.rmdir()`.
|
|
341
|
-
|
|
342
|
-
#### `await fs.rm(filepath[, opts])`
|
|
343
|
-
|
|
344
|
-
Remove a file or directory at `filepath`.
|
|
345
|
-
|
|
346
|
-
Options include:
|
|
347
|
-
|
|
348
|
-
```js
|
|
349
|
-
options = {
|
|
350
|
-
force: false,
|
|
351
|
-
recursive: false
|
|
352
|
-
}
|
|
353
|
-
```
|
|
354
|
-
|
|
355
|
-
When `recursive` is `true`, directories are removed along with their contents. When `force` is `true`, no error is thrown if `filepath` does not exist.
|
|
356
|
-
|
|
357
|
-
#### `fs.rm(filepath[, opts], callback)`
|
|
358
|
-
|
|
359
|
-
Callback version of `fs.rm()`.
|
|
360
|
-
|
|
361
|
-
#### `fs.rmSync(filepath[, opts])`
|
|
362
|
-
|
|
363
|
-
Synchronous version of `fs.rm()`.
|
|
364
|
-
|
|
365
|
-
#### `await fs.unlink(filepath)`
|
|
366
|
-
|
|
367
|
-
Remove a file.
|
|
368
|
-
|
|
369
|
-
#### `fs.unlink(filepath, callback)`
|
|
370
|
-
|
|
371
|
-
Callback version of `fs.unlink()`.
|
|
372
|
-
|
|
373
|
-
#### `fs.unlinkSync(filepath)`
|
|
374
|
-
|
|
375
|
-
Synchronous version of `fs.unlink()`.
|
|
376
|
-
|
|
377
|
-
#### `await fs.rename(src, dst)`
|
|
378
|
-
|
|
379
|
-
Rename a file from `src` to `dst`.
|
|
380
|
-
|
|
381
|
-
#### `fs.rename(src, dst, callback)`
|
|
382
|
-
|
|
383
|
-
Callback version of `fs.rename()`.
|
|
384
|
-
|
|
385
|
-
#### `fs.renameSync(src, dst)`
|
|
386
|
-
|
|
387
|
-
Synchronous version of `fs.rename()`.
|
|
388
|
-
|
|
389
|
-
#### `await fs.copyFile(src, dst[, mode])`
|
|
390
|
-
|
|
391
|
-
Copy a file from `src` to `dst`. `mode` is an optional bitmask created from `fs.constants.COPYFILE_EXCL`, `fs.constants.COPYFILE_FICLONE`, or `fs.constants.COPYFILE_FICLONE_FORCE`.
|
|
392
|
-
|
|
393
|
-
#### `fs.copyFile(src, dst[, mode], callback)`
|
|
394
|
-
|
|
395
|
-
Callback version of `fs.copyFile()`.
|
|
396
|
-
|
|
397
|
-
#### `fs.copyFileSync(src, dst[, mode])`
|
|
398
|
-
|
|
399
|
-
Synchronous version of `fs.copyFile()`.
|
|
400
|
-
|
|
401
|
-
#### `await fs.cp(src, dst[, opts])`
|
|
402
|
-
|
|
403
|
-
Copy a file or directory from `src` to `dst`.
|
|
404
|
-
|
|
405
|
-
Options include:
|
|
406
|
-
|
|
407
|
-
```js
|
|
408
|
-
options = {
|
|
409
|
-
recursive: false
|
|
410
|
-
}
|
|
411
|
-
```
|
|
412
|
-
|
|
413
|
-
Set `recursive` to `true` to copy directories and their contents. Files are copied preserving their permissions.
|
|
414
|
-
|
|
415
|
-
#### `fs.cp(src, dst[, opts], callback)`
|
|
416
|
-
|
|
417
|
-
Callback version of `fs.cp()`.
|
|
418
|
-
|
|
419
|
-
#### `fs.cpSync(src, dst[, opts])`
|
|
420
|
-
|
|
421
|
-
Synchronous version of `fs.cp()`.
|
|
422
|
-
|
|
423
|
-
#### `const resolved = await fs.realpath(filepath[, opts])`
|
|
424
|
-
|
|
425
|
-
Resolve the real path of `filepath`, expanding all symbolic links.
|
|
426
|
-
|
|
427
|
-
Options include:
|
|
428
|
-
|
|
429
|
-
```js
|
|
430
|
-
options = {
|
|
431
|
-
encoding: 'utf8'
|
|
432
|
-
}
|
|
433
|
-
```
|
|
434
|
-
|
|
435
|
-
Set `encoding` to `'buffer'` to receive the result as a `Buffer`.
|
|
436
|
-
|
|
437
|
-
#### `fs.realpath(filepath[, opts], callback)`
|
|
438
|
-
|
|
439
|
-
Callback version of `fs.realpath()`.
|
|
440
|
-
|
|
441
|
-
#### `const resolved = fs.realpathSync(filepath[, opts])`
|
|
442
|
-
|
|
443
|
-
Synchronous version of `fs.realpath()`.
|
|
444
|
-
|
|
445
|
-
#### `const target = await fs.readlink(filepath[, opts])`
|
|
446
|
-
|
|
447
|
-
Read the target of a symbolic link.
|
|
448
|
-
|
|
449
|
-
Options include:
|
|
450
|
-
|
|
451
|
-
```js
|
|
452
|
-
options = {
|
|
453
|
-
encoding: 'utf8'
|
|
454
|
-
}
|
|
455
|
-
```
|
|
456
|
-
|
|
457
|
-
#### `fs.readlink(filepath[, opts], callback)`
|
|
458
|
-
|
|
459
|
-
Callback version of `fs.readlink()`.
|
|
460
|
-
|
|
461
|
-
#### `const target = fs.readlinkSync(filepath[, opts])`
|
|
462
|
-
|
|
463
|
-
Synchronous version of `fs.readlink()`.
|
|
464
|
-
|
|
465
|
-
#### `await fs.truncate(filename[, len])`
|
|
466
|
-
|
|
467
|
-
Truncate the file at `filename` to `len` bytes. `len` defaults to `0`.
|
|
468
|
-
|
|
469
|
-
#### `fs.truncate(filename[, len], callback)`
|
|
470
|
-
|
|
471
|
-
Callback version of `fs.truncate()`.
|
|
472
|
-
|
|
473
|
-
#### `fs.truncateSync(filename[, len])`
|
|
474
|
-
|
|
475
|
-
Synchronous version of `fs.truncate()`.
|
|
476
|
-
|
|
477
|
-
#### `await fs.symlink(target, filepath[, type])`
|
|
478
|
-
|
|
479
|
-
Create a symbolic link at `filepath` pointing to `target`. `type` may be `'file'`, `'dir'`, or `'junction'` (Windows only) or a numeric flag. On Windows, if `type` is not provided, it is inferred from the target.
|
|
480
|
-
|
|
481
|
-
#### `fs.symlink(target, filepath[, type], callback)`
|
|
482
|
-
|
|
483
|
-
Callback version of `fs.symlink()`.
|
|
484
|
-
|
|
485
|
-
#### `fs.symlinkSync(target, filepath[, type])`
|
|
486
|
-
|
|
487
|
-
Synchronous version of `fs.symlink()`.
|
|
488
|
-
|
|
489
|
-
#### `await fs.fsync(fd)`
|
|
490
|
-
|
|
491
|
-
Flush all modified in-core data of the file referred by its file descriptor to the disk device.
|
|
492
|
-
|
|
493
|
-
#### `fs.fsync(fs, callback)`
|
|
494
|
-
|
|
495
|
-
Callback version of `fs.fsync()`.
|
|
496
|
-
|
|
497
|
-
#### `fs.fsyncSync(fd)`
|
|
498
|
-
|
|
499
|
-
Synchronous version of `fs.fsync()`.
|
|
500
|
-
|
|
501
|
-
#### `await fs.fdatasync(fd)`
|
|
502
|
-
|
|
503
|
-
Similar to `fsync`, but does not flush modified metadata unless necessary.
|
|
504
|
-
|
|
505
|
-
#### `fs.fdatasync(fs, callback)`
|
|
506
|
-
|
|
507
|
-
Callback version of `fs.fdatasync()`.
|
|
508
|
-
|
|
509
|
-
#### `fs.fdatasyncSync(fd)`
|
|
510
|
-
|
|
511
|
-
Synchronous version of `fs.fdatasync()`.
|
|
512
|
-
|
|
513
|
-
#### `const dir = await fs.opendir(filepath[, opts])`
|
|
514
|
-
|
|
515
|
-
Open a directory for iteration. Returns a `Dir` object.
|
|
516
|
-
|
|
517
|
-
Options include:
|
|
518
|
-
|
|
519
|
-
```js
|
|
520
|
-
options = {
|
|
521
|
-
encoding: 'utf8',
|
|
522
|
-
bufferSize: 32
|
|
523
|
-
}
|
|
524
|
-
```
|
|
525
|
-
|
|
526
|
-
#### `fs.opendir(filepath[, opts], callback)`
|
|
527
|
-
|
|
528
|
-
Callback version of `fs.opendir()`.
|
|
529
|
-
|
|
530
|
-
#### `const dir = fs.opendirSync(filepath[, opts])`
|
|
531
|
-
|
|
532
|
-
Synchronous version of `fs.opendir()`.
|
|
533
|
-
|
|
534
|
-
#### `const entries = await fs.readdir(filepath[, opts])`
|
|
535
|
-
|
|
536
|
-
Read the contents of a directory. Returns an array of filenames or, if `withFileTypes` is `true`, an array of `Dirent` objects.
|
|
537
|
-
|
|
538
|
-
Options include:
|
|
539
|
-
|
|
540
|
-
```js
|
|
541
|
-
options = {
|
|
542
|
-
encoding: 'utf8',
|
|
543
|
-
withFileTypes: false,
|
|
544
|
-
recursive: false
|
|
545
|
-
}
|
|
546
|
-
```
|
|
547
|
-
|
|
548
|
-
#### `fs.readdir(filepath[, opts], callback)`
|
|
549
|
-
|
|
550
|
-
Callback version of `fs.readdir()`.
|
|
551
|
-
|
|
552
|
-
#### `const entries = fs.readdirSync(filepath[, opts])`
|
|
553
|
-
|
|
554
|
-
Synchronous version of `fs.readdir()`.
|
|
555
|
-
|
|
556
|
-
#### `const data = await fs.readFile(filepath[, opts])`
|
|
557
|
-
|
|
558
|
-
Read the entire contents of a file. Returns a `Buffer` by default, or a string if an `encoding` is specified.
|
|
559
|
-
|
|
560
|
-
Options include:
|
|
561
|
-
|
|
562
|
-
```js
|
|
563
|
-
options = {
|
|
564
|
-
encoding: 'buffer',
|
|
565
|
-
flag: 'r'
|
|
566
|
-
}
|
|
567
|
-
```
|
|
568
|
-
|
|
569
|
-
#### `fs.readFile(filepath[, opts], callback)`
|
|
570
|
-
|
|
571
|
-
Callback version of `fs.readFile()`.
|
|
572
|
-
|
|
573
|
-
#### `const data = fs.readFileSync(filepath[, opts])`
|
|
574
|
-
|
|
575
|
-
Synchronous version of `fs.readFile()`.
|
|
576
|
-
|
|
577
|
-
#### `await fs.writeFile(filepath, data[, opts])`
|
|
578
|
-
|
|
579
|
-
Write `data` to a file, replacing it if it already exists.
|
|
580
|
-
|
|
581
|
-
Options include:
|
|
582
|
-
|
|
583
|
-
```js
|
|
584
|
-
options = {
|
|
585
|
-
encoding: 'utf8',
|
|
586
|
-
flag: 'w',
|
|
587
|
-
mode: 0o666
|
|
588
|
-
}
|
|
589
|
-
```
|
|
590
|
-
|
|
591
|
-
#### `fs.writeFile(filepath, data[, opts], callback)`
|
|
592
|
-
|
|
593
|
-
Callback version of `fs.writeFile()`.
|
|
594
|
-
|
|
595
|
-
#### `fs.writeFileSync(filepath, data[, opts])`
|
|
596
|
-
|
|
597
|
-
Synchronous version of `fs.writeFile()`.
|
|
598
|
-
|
|
599
|
-
#### `await fs.appendFile(filepath, data[, opts])`
|
|
600
|
-
|
|
601
|
-
Append `data` to a file, creating it if it does not exist. Accepts the same options as `fs.writeFile()` but defaults to the `'a'` flag.
|
|
602
|
-
|
|
603
|
-
#### `fs.appendFile(filepath, data[, opts], callback)`
|
|
604
|
-
|
|
605
|
-
Callback version of `fs.appendFile()`.
|
|
606
|
-
|
|
607
|
-
#### `fs.appendFileSync(filepath, data[, opts])`
|
|
608
|
-
|
|
609
|
-
Synchronous version of `fs.appendFile()`.
|
|
610
|
-
|
|
611
|
-
#### `const watcher = fs.watch(filepath[, opts], callback)`
|
|
612
|
-
|
|
613
|
-
Watch a file or directory for changes. Returns a `Watcher` object. The `callback`, if provided, is called with `(eventType, filename)` on each change.
|
|
614
|
-
|
|
615
|
-
Options include:
|
|
616
|
-
|
|
617
|
-
```js
|
|
618
|
-
options = {
|
|
619
|
-
persistent: true,
|
|
620
|
-
recursive: false,
|
|
621
|
-
encoding: 'utf8'
|
|
622
|
-
}
|
|
623
|
-
```
|
|
624
|
-
|
|
625
|
-
#### `const stream = fs.createReadStream(path[, opts])`
|
|
626
|
-
|
|
627
|
-
Create a readable stream for a file. Returns a `ReadStream`.
|
|
628
|
-
|
|
629
|
-
Options include:
|
|
630
|
-
|
|
631
|
-
```js
|
|
632
|
-
options = {
|
|
633
|
-
fd: -1,
|
|
634
|
-
flags: 'r',
|
|
635
|
-
mode: 0o666,
|
|
636
|
-
start: 0,
|
|
637
|
-
end: Infinity
|
|
638
|
-
}
|
|
639
|
-
```
|
|
640
|
-
|
|
641
|
-
If `fd` is provided, `path` may be `null` and the stream reads from the given file descriptor.
|
|
642
|
-
|
|
643
|
-
#### `const stream = fs.createWriteStream(path[, opts])`
|
|
644
|
-
|
|
645
|
-
Create a writable stream for a file. Returns a `WriteStream`.
|
|
646
|
-
|
|
647
|
-
Options include:
|
|
648
|
-
|
|
649
|
-
```js
|
|
650
|
-
options = {
|
|
651
|
-
fd: -1,
|
|
652
|
-
flags: 'w',
|
|
653
|
-
mode: 0o666
|
|
654
|
-
}
|
|
655
|
-
```
|
|
656
|
-
|
|
657
|
-
If `fd` is provided, `path` may be `null` and the stream writes to the given file descriptor.
|
|
658
|
-
|
|
659
|
-
#### `fs.constants`
|
|
660
|
-
|
|
661
|
-
An object containing file system constants. See `fs/constants` for the full list. Commonly used constants include:
|
|
662
|
-
|
|
663
|
-
- `fs.constants.O_RDONLY`, `fs.constants.O_WRONLY`, `fs.constants.O_RDWR` — file access flags
|
|
664
|
-
- `fs.constants.O_CREAT`, `fs.constants.O_TRUNC`, `fs.constants.O_APPEND` — file creation flags
|
|
665
|
-
- `fs.constants.F_OK`, `fs.constants.R_OK`, `fs.constants.W_OK`, `fs.constants.X_OK` — file accessibility flags
|
|
666
|
-
- `fs.constants.S_IFMT`, `fs.constants.S_IFREG`, `fs.constants.S_IFDIR`, `fs.constants.S_IFLNK` — file type flags
|
|
667
|
-
- `fs.constants.COPYFILE_EXCL`, `fs.constants.COPYFILE_FICLONE`, `fs.constants.COPYFILE_FICLONE_FORCE` — copy flags
|
|
668
|
-
|
|
669
|
-
### `Stats`
|
|
670
|
-
|
|
671
|
-
Returned by `fs.stat()`, `fs.lstat()`, and `fs.fstat()`.
|
|
672
|
-
|
|
673
|
-
#### `stats.dev`
|
|
674
|
-
|
|
675
|
-
The device identifier.
|
|
676
|
-
|
|
677
|
-
#### `stats.mode`
|
|
678
|
-
|
|
679
|
-
The file mode (type and permissions).
|
|
680
|
-
|
|
681
|
-
#### `stats.nlink`
|
|
682
|
-
|
|
683
|
-
The number of hard links.
|
|
684
|
-
|
|
685
|
-
#### `stats.uid`
|
|
686
|
-
|
|
687
|
-
The user identifier of the file owner.
|
|
688
|
-
|
|
689
|
-
#### `stats.gid`
|
|
690
|
-
|
|
691
|
-
The group identifier of the file owner.
|
|
692
|
-
|
|
693
|
-
#### `stats.rdev`
|
|
694
|
-
|
|
695
|
-
The device identifier for special files.
|
|
696
|
-
|
|
697
|
-
#### `stats.blksize`
|
|
698
|
-
|
|
699
|
-
The file system block size for I/O operations.
|
|
700
|
-
|
|
701
|
-
#### `stats.ino`
|
|
702
|
-
|
|
703
|
-
The inode number.
|
|
704
|
-
|
|
705
|
-
#### `stats.size`
|
|
706
|
-
|
|
707
|
-
The size of the file in bytes.
|
|
708
|
-
|
|
709
|
-
#### `stats.blocks`
|
|
710
|
-
|
|
711
|
-
The number of 512-byte blocks allocated.
|
|
712
|
-
|
|
713
|
-
#### `stats.atimeMs`
|
|
714
|
-
|
|
715
|
-
The access time in milliseconds since the epoch.
|
|
716
|
-
|
|
717
|
-
#### `stats.mtimeMs`
|
|
718
|
-
|
|
719
|
-
The modification time in milliseconds since the epoch.
|
|
720
|
-
|
|
721
|
-
#### `stats.ctimeMs`
|
|
722
|
-
|
|
723
|
-
The change time in milliseconds since the epoch.
|
|
724
|
-
|
|
725
|
-
#### `stats.birthtimeMs`
|
|
726
|
-
|
|
727
|
-
The creation time in milliseconds since the epoch.
|
|
728
|
-
|
|
729
|
-
#### `stats.atime`
|
|
730
|
-
|
|
731
|
-
The access time as a `Date` object.
|
|
732
|
-
|
|
733
|
-
#### `stats.mtime`
|
|
734
|
-
|
|
735
|
-
The modification time as a `Date` object.
|
|
736
|
-
|
|
737
|
-
#### `stats.ctime`
|
|
738
|
-
|
|
739
|
-
The change time as a `Date` object.
|
|
740
|
-
|
|
741
|
-
#### `stats.birthtime`
|
|
742
|
-
|
|
743
|
-
The creation time as a `Date` object.
|
|
744
|
-
|
|
745
|
-
#### `stats.isDirectory()`
|
|
746
|
-
|
|
747
|
-
Returns `true` if the file is a directory.
|
|
748
|
-
|
|
749
|
-
#### `stats.isFile()`
|
|
750
|
-
|
|
751
|
-
Returns `true` if the file is a regular file.
|
|
752
|
-
|
|
753
|
-
#### `stats.isBlockDevice()`
|
|
754
|
-
|
|
755
|
-
Returns `true` if the file is a block device.
|
|
756
|
-
|
|
757
|
-
#### `stats.isCharacterDevice()`
|
|
758
|
-
|
|
759
|
-
Returns `true` if the file is a character device.
|
|
760
|
-
|
|
761
|
-
#### `stats.isFIFO()`
|
|
762
|
-
|
|
763
|
-
Returns `true` if the file is a FIFO (named pipe).
|
|
764
|
-
|
|
765
|
-
#### `stats.isSymbolicLink()`
|
|
766
|
-
|
|
767
|
-
Returns `true` if the file is a symbolic link. Only meaningful when using `fs.lstat()`.
|
|
768
|
-
|
|
769
|
-
#### `stats.isSocket()`
|
|
770
|
-
|
|
771
|
-
Returns `true` if the file is a socket.
|
|
772
|
-
|
|
773
|
-
### `Dir`
|
|
774
|
-
|
|
775
|
-
Returned by `fs.opendir()`. Supports both synchronous and asynchronous iteration.
|
|
776
|
-
|
|
777
|
-
#### `dir.path`
|
|
778
|
-
|
|
779
|
-
The path of the directory.
|
|
780
|
-
|
|
781
|
-
#### `const dirent = await dir.read()`
|
|
782
|
-
|
|
783
|
-
Read the next directory entry. Returns a `Dirent` or `null` when all entries have been read.
|
|
784
|
-
|
|
785
|
-
#### `dir.read(callback)`
|
|
786
|
-
|
|
787
|
-
Callback version of `dir.read()`.
|
|
788
|
-
|
|
789
|
-
#### `const dirent = dir.readSync()`
|
|
790
|
-
|
|
791
|
-
Synchronous version of `dir.read()`.
|
|
792
|
-
|
|
793
|
-
#### `await dir.close()`
|
|
794
|
-
|
|
795
|
-
Close the directory handle.
|
|
796
|
-
|
|
797
|
-
#### `dir.close(callback)`
|
|
798
|
-
|
|
799
|
-
Callback version of `dir.close()`.
|
|
800
|
-
|
|
801
|
-
#### `dir.closeSync()`
|
|
802
|
-
|
|
803
|
-
Synchronous version of `dir.close()`.
|
|
804
|
-
|
|
805
|
-
### `Dirent`
|
|
806
|
-
|
|
807
|
-
Represents a directory entry, returned when iterating a `Dir` or using `fs.readdir()` with `withFileTypes: true`.
|
|
808
|
-
|
|
809
|
-
#### `dirent.parentPath`
|
|
810
|
-
|
|
811
|
-
The path of the parent directory.
|
|
812
|
-
|
|
813
|
-
#### `dirent.name`
|
|
814
|
-
|
|
815
|
-
The name of the directory entry, as a string or `Buffer` depending on the encoding.
|
|
816
|
-
|
|
817
|
-
#### `dirent.type`
|
|
818
|
-
|
|
819
|
-
The numeric type of the directory entry.
|
|
820
|
-
|
|
821
|
-
#### `dirent.isFile()`
|
|
822
|
-
|
|
823
|
-
Returns `true` if the entry is a regular file.
|
|
824
|
-
|
|
825
|
-
#### `dirent.isDirectory()`
|
|
826
|
-
|
|
827
|
-
Returns `true` if the entry is a directory.
|
|
828
|
-
|
|
829
|
-
#### `dirent.isSymbolicLink()`
|
|
830
|
-
|
|
831
|
-
Returns `true` if the entry is a symbolic link.
|
|
832
|
-
|
|
833
|
-
#### `dirent.isFIFO()`
|
|
834
|
-
|
|
835
|
-
Returns `true` if the entry is a FIFO.
|
|
836
|
-
|
|
837
|
-
#### `dirent.isSocket()`
|
|
838
|
-
|
|
839
|
-
Returns `true` if the entry is a socket.
|
|
840
|
-
|
|
841
|
-
#### `dirent.isCharacterDevice()`
|
|
842
|
-
|
|
843
|
-
Returns `true` if the entry is a character device.
|
|
844
|
-
|
|
845
|
-
#### `dirent.isBlockDevice()`
|
|
846
|
-
|
|
847
|
-
Returns `true` if the entry is a block device.
|
|
848
|
-
|
|
849
|
-
### `ReadStream`
|
|
850
|
-
|
|
851
|
-
A readable stream for file data, created by `fs.createReadStream()`. Extends `Readable` from <https://github.com/holepunchto/bare-stream>.
|
|
852
|
-
|
|
853
|
-
#### `stream.path`
|
|
854
|
-
|
|
855
|
-
The file path, or `null` if opened by file descriptor.
|
|
856
|
-
|
|
857
|
-
#### `stream.fd`
|
|
858
|
-
|
|
859
|
-
The underlying file descriptor.
|
|
860
|
-
|
|
861
|
-
#### `stream.flags`
|
|
862
|
-
|
|
863
|
-
The flags the file was opened with.
|
|
864
|
-
|
|
865
|
-
#### `stream.mode`
|
|
866
|
-
|
|
867
|
-
The mode the file was opened with.
|
|
868
|
-
|
|
869
|
-
### `WriteStream`
|
|
870
|
-
|
|
871
|
-
A writable stream for file data, created by `fs.createWriteStream()`. Extends `Writable` from <https://github.com/holepunchto/bare-stream>.
|
|
872
|
-
|
|
873
|
-
#### `stream.path`
|
|
874
|
-
|
|
875
|
-
The file path, or `null` if opened by file descriptor.
|
|
876
|
-
|
|
877
|
-
#### `stream.fd`
|
|
878
|
-
|
|
879
|
-
The underlying file descriptor.
|
|
880
|
-
|
|
881
|
-
#### `stream.flags`
|
|
882
|
-
|
|
883
|
-
The flags the file was opened with.
|
|
884
|
-
|
|
885
|
-
#### `stream.mode`
|
|
886
|
-
|
|
887
|
-
The mode the file was opened with.
|
|
888
|
-
|
|
889
|
-
### `Watcher`
|
|
890
|
-
|
|
891
|
-
Watches for file system changes, created by `fs.watch()`. Extends `EventEmitter` from <https://github.com/holepunchto/bare-events>.
|
|
892
|
-
|
|
893
|
-
#### `watcher.close()`
|
|
894
|
-
|
|
895
|
-
Stop watching for changes.
|
|
896
|
-
|
|
897
|
-
#### `watcher.ref()`
|
|
898
|
-
|
|
899
|
-
Prevent the event loop from exiting while the watcher is active.
|
|
900
|
-
|
|
901
|
-
#### `watcher.unref()`
|
|
902
|
-
|
|
903
|
-
Allow the event loop to exit even if the watcher is still active.
|
|
904
|
-
|
|
905
|
-
#### `event: 'change'`
|
|
906
|
-
|
|
907
|
-
Emitted with `(eventType, filename)` when a change is detected. `eventType` is either `'rename'` or `'change'`.
|
|
908
|
-
|
|
909
|
-
#### `event: 'error'`
|
|
910
|
-
|
|
911
|
-
Emitted with `(err)` when an error occurs.
|
|
912
|
-
|
|
913
|
-
#### `event: 'close'`
|
|
914
|
-
|
|
915
|
-
Emitted when the watcher is closed.
|
|
916
|
-
|
|
917
|
-
### `FileHandle`
|
|
918
|
-
|
|
919
|
-
Returned by `require('bare-fs/promises').open()`. Provides an object-oriented API for working with file descriptors.
|
|
920
|
-
|
|
921
|
-
#### `await handle.close()`
|
|
922
|
-
|
|
923
|
-
Close the file handle.
|
|
924
|
-
|
|
925
|
-
#### `const { bytesRead, buffer } = await handle.read(buffer[, offset[, len[, pos]]])`
|
|
926
|
-
|
|
927
|
-
Read from the file into `buffer`.
|
|
928
|
-
|
|
929
|
-
#### `const { bytesRead, buffers } = await handle.readv(buffers[, pos])`
|
|
930
|
-
|
|
931
|
-
Read from the file into an array of `buffers`.
|
|
932
|
-
|
|
933
|
-
#### `const { bytesWritten, buffer } = await handle.write(data[, offset[, len[, pos]]])`
|
|
934
|
-
|
|
935
|
-
Write `data` to the file.
|
|
936
|
-
|
|
937
|
-
#### `const { bytesWritten, buffers } = await handle.writev(buffers[, pos])`
|
|
938
|
-
|
|
939
|
-
Write an array of `buffers` to the file.
|
|
940
|
-
|
|
941
|
-
#### `const stats = await handle.stat()`
|
|
942
|
-
|
|
943
|
-
Get the status of the file.
|
|
944
|
-
|
|
945
|
-
#### `await handle.chmod(mode)`
|
|
946
|
-
|
|
947
|
-
Change the permissions of the file.
|
|
948
|
-
|
|
949
|
-
#### `await handle.chown(uid, gid)`
|
|
950
|
-
|
|
951
|
-
Change the owner and group of the file.
|
|
952
|
-
|
|
953
|
-
**NOTE**: This function is not implemented on Windows.
|
|
954
|
-
|
|
955
|
-
#### `await handle.datasync()`
|
|
956
|
-
|
|
957
|
-
Similar to `fsync`, but does not flush modified metadata unless necessary.
|
|
958
|
-
|
|
959
|
-
#### `await handle.sync()`
|
|
960
|
-
|
|
961
|
-
Flush all modified in-core data of the file.
|
|
962
|
-
|
|
963
|
-
#### `await handle.truncate(len)`
|
|
964
|
-
|
|
965
|
-
Truncate the file.
|
|
966
|
-
|
|
967
|
-
#### `await handle.utimes(mode)`
|
|
968
|
-
|
|
969
|
-
Change the access and modification times of the file.
|
|
970
|
-
|
|
971
|
-
#### `const stream = handle.createReadStream([opts])`
|
|
972
|
-
|
|
973
|
-
Create a readable stream for the file.
|
|
974
|
-
|
|
975
|
-
#### `const stream = handle.createWriteStream([opts])`
|
|
976
|
-
|
|
977
|
-
Create a writable stream for the file.
|
|
978
|
-
|
|
979
|
-
#### `handle.fd`
|
|
980
|
-
|
|
981
|
-
The file descriptor number.
|
|
982
|
-
|
|
983
|
-
#### `event: 'close'`
|
|
984
|
-
|
|
985
|
-
Emitted when the file handle is closed.
|
|
29
|
+
See the [`bare-fs` reference](https://docs.pears.com/reference/bare/modules/bare-fs).
|
|
986
30
|
|
|
987
31
|
## License
|
|
988
32
|
|