@types/node 16.4.2 → 16.4.6
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.
- node/README.md +2 -2
- node/assert/strict.d.ts +0 -1
- node/assert.d.ts +1352 -40
- node/async_hooks.d.ts +359 -90
- node/buffer.d.ts +1503 -78
- node/child_process.d.ts +1054 -233
- node/cluster.d.ts +320 -100
- node/console.d.ts +305 -32
- node/crypto.d.ts +3115 -739
- node/dgram.d.ts +446 -55
- node/diagnostics_channel.d.ts +85 -12
- node/dns/promises.d.ts +292 -36
- node/dns.d.ts +410 -97
- node/domain.d.ts +154 -10
- node/events.d.ts +377 -31
- node/fs/promises.d.ts +697 -273
- node/fs.d.ts +2257 -858
- node/http.d.ts +888 -80
- node/http2.d.ts +1525 -459
- node/https.d.ts +261 -11
- node/index.d.ts +25 -0
- node/inspector.d.ts +354 -661
- node/module.d.ts +49 -11
- node/net.d.ts +548 -140
- node/os.d.ts +236 -26
- node/package.json +7 -2
- node/path.d.ts +9 -5
- node/perf_hooks.d.ts +288 -90
- node/process.d.ts +1092 -153
- node/punycode.d.ts +65 -26
- node/querystring.d.ts +107 -8
- node/readline.d.ts +425 -79
- node/repl.d.ts +135 -110
- node/stream/promises.d.ts +15 -44
- node/stream.d.ts +927 -225
- node/string_decoder.d.ts +57 -1
- node/timers/promises.d.ts +97 -9
- node/timers.d.ts +29 -10
- node/tls.d.ts +444 -221
- node/trace_events.d.ts +107 -11
- node/tty.d.ts +163 -23
- node/url.d.ts +739 -29
- node/util.d.ts +1361 -73
- node/v8.d.ts +254 -78
- node/vm.d.ts +381 -33
- node/wasi.d.ts +107 -24
- node/worker_threads.d.ts +494 -131
- node/zlib.d.ts +215 -63
node/fs.d.ts
CHANGED
|
@@ -1,33 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `fs` module enables interacting with the file system in a
|
|
3
|
+
* way modeled on standard POSIX functions.
|
|
4
|
+
*
|
|
5
|
+
* To use the promise-based APIs:
|
|
6
|
+
*
|
|
7
|
+
* ```js
|
|
8
|
+
* // Using ESM Module syntax:
|
|
9
|
+
* import * as fs from 'fs/promises';
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* ```js
|
|
13
|
+
* // Using CommonJS syntax:
|
|
14
|
+
* const fs = require('fs/promises');
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* To use the callback and sync APIs:
|
|
18
|
+
*
|
|
19
|
+
* ```js
|
|
20
|
+
* // Using ESM Module syntax:
|
|
21
|
+
* import * as fs from 'fs';
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* ```js
|
|
25
|
+
* // Using CommonJS syntax:
|
|
26
|
+
* const fs = require('fs');
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* All file system operations have synchronous, callback, and promise-based
|
|
30
|
+
* forms, and are accessible using both CommonJS syntax and ES6 Modules (ESM).
|
|
31
|
+
* @see [source](https://github.com/nodejs/node/blob/v16.4.2/lib/fs.js)
|
|
32
|
+
*/
|
|
1
33
|
declare module 'fs' {
|
|
2
34
|
import * as stream from 'node:stream';
|
|
3
35
|
import { Abortable, EventEmitter } from 'node:events';
|
|
4
36
|
import { URL } from 'node:url';
|
|
5
37
|
import * as promises from 'node:fs/promises';
|
|
6
|
-
|
|
7
38
|
export { promises };
|
|
8
39
|
/**
|
|
9
40
|
* Valid types for path values in "fs".
|
|
10
41
|
*/
|
|
11
42
|
export type PathLike = string | Buffer | URL;
|
|
12
|
-
|
|
13
43
|
export type PathOrFileDescriptor = PathLike | number;
|
|
14
|
-
|
|
15
44
|
export type TimeLike = string | number | Date;
|
|
16
|
-
|
|
17
45
|
export type NoParamCallback = (err: NodeJS.ErrnoException | null) => void;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
46
|
+
export type BufferEncodingOption =
|
|
47
|
+
| 'buffer'
|
|
48
|
+
| {
|
|
49
|
+
encoding: 'buffer';
|
|
50
|
+
};
|
|
21
51
|
export interface ObjectEncodingOptions {
|
|
22
52
|
encoding?: BufferEncoding | null | undefined;
|
|
23
53
|
}
|
|
24
|
-
|
|
25
54
|
export type EncodingOption = ObjectEncodingOptions | BufferEncoding | undefined | null;
|
|
26
|
-
|
|
27
55
|
export type OpenMode = number | string;
|
|
28
|
-
|
|
29
56
|
export type Mode = number | string;
|
|
30
|
-
|
|
31
57
|
export interface StatsBase<T> {
|
|
32
58
|
isFile(): boolean;
|
|
33
59
|
isDirectory(): boolean;
|
|
@@ -36,7 +62,6 @@ declare module 'fs' {
|
|
|
36
62
|
isSymbolicLink(): boolean;
|
|
37
63
|
isFIFO(): boolean;
|
|
38
64
|
isSocket(): boolean;
|
|
39
|
-
|
|
40
65
|
dev: T;
|
|
41
66
|
ino: T;
|
|
42
67
|
mode: T;
|
|
@@ -56,237 +81,416 @@ declare module 'fs' {
|
|
|
56
81
|
ctime: Date;
|
|
57
82
|
birthtime: Date;
|
|
58
83
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
84
|
+
export interface Stats extends StatsBase<number> {}
|
|
85
|
+
/**
|
|
86
|
+
* A `<fs.Stats>` object provides information about a file.
|
|
87
|
+
*
|
|
88
|
+
* Objects returned from {@link stat}, {@link lstat} and {@link fstat} and
|
|
89
|
+
* their synchronous counterparts are of this type.
|
|
90
|
+
* If `bigint` in the `options` passed to those methods is true, the numeric values
|
|
91
|
+
* will be `bigint` instead of `number`, and the object will contain additional
|
|
92
|
+
* nanosecond-precision properties suffixed with `Ns`.
|
|
93
|
+
*
|
|
94
|
+
* ```console
|
|
95
|
+
* Stats {
|
|
96
|
+
* dev: 2114,
|
|
97
|
+
* ino: 48064969,
|
|
98
|
+
* mode: 33188,
|
|
99
|
+
* nlink: 1,
|
|
100
|
+
* uid: 85,
|
|
101
|
+
* gid: 100,
|
|
102
|
+
* rdev: 0,
|
|
103
|
+
* size: 527,
|
|
104
|
+
* blksize: 4096,
|
|
105
|
+
* blocks: 8,
|
|
106
|
+
* atimeMs: 1318289051000.1,
|
|
107
|
+
* mtimeMs: 1318289051000.1,
|
|
108
|
+
* ctimeMs: 1318289051000.1,
|
|
109
|
+
* birthtimeMs: 1318289051000.1,
|
|
110
|
+
* atime: Mon, 10 Oct 2011 23:24:11 GMT,
|
|
111
|
+
* mtime: Mon, 10 Oct 2011 23:24:11 GMT,
|
|
112
|
+
* ctime: Mon, 10 Oct 2011 23:24:11 GMT,
|
|
113
|
+
* birthtime: Mon, 10 Oct 2011 23:24:11 GMT }
|
|
114
|
+
* ```
|
|
115
|
+
*
|
|
116
|
+
* `bigint` version:
|
|
117
|
+
*
|
|
118
|
+
* ```console
|
|
119
|
+
* BigIntStats {
|
|
120
|
+
* dev: 2114n,
|
|
121
|
+
* ino: 48064969n,
|
|
122
|
+
* mode: 33188n,
|
|
123
|
+
* nlink: 1n,
|
|
124
|
+
* uid: 85n,
|
|
125
|
+
* gid: 100n,
|
|
126
|
+
* rdev: 0n,
|
|
127
|
+
* size: 527n,
|
|
128
|
+
* blksize: 4096n,
|
|
129
|
+
* blocks: 8n,
|
|
130
|
+
* atimeMs: 1318289051000n,
|
|
131
|
+
* mtimeMs: 1318289051000n,
|
|
132
|
+
* ctimeMs: 1318289051000n,
|
|
133
|
+
* birthtimeMs: 1318289051000n,
|
|
134
|
+
* atimeNs: 1318289051000000000n,
|
|
135
|
+
* mtimeNs: 1318289051000000000n,
|
|
136
|
+
* ctimeNs: 1318289051000000000n,
|
|
137
|
+
* birthtimeNs: 1318289051000000000n,
|
|
138
|
+
* atime: Mon, 10 Oct 2011 23:24:11 GMT,
|
|
139
|
+
* mtime: Mon, 10 Oct 2011 23:24:11 GMT,
|
|
140
|
+
* ctime: Mon, 10 Oct 2011 23:24:11 GMT,
|
|
141
|
+
* birthtime: Mon, 10 Oct 2011 23:24:11 GMT }
|
|
142
|
+
* ```
|
|
143
|
+
* @since v0.1.21
|
|
144
|
+
*/
|
|
145
|
+
export class Stats {}
|
|
146
|
+
/**
|
|
147
|
+
* A representation of a directory entry, which can be a file or a subdirectory
|
|
148
|
+
* within the directory, as returned by reading from an `<fs.Dir>`. The
|
|
149
|
+
* directory entry is a combination of the file name and file type pairs.
|
|
150
|
+
*
|
|
151
|
+
* Additionally, when {@link readdir} or {@link readdirSync} is called with
|
|
152
|
+
* the `withFileTypes` option set to `true`, the resulting array is filled with `<fs.Dirent>` objects, rather than strings or `<Buffer>` s.
|
|
153
|
+
* @since v10.10.0
|
|
154
|
+
*/
|
|
66
155
|
export class Dirent {
|
|
156
|
+
/**
|
|
157
|
+
* Returns `true` if the `<fs.Dirent>` object describes a regular file.
|
|
158
|
+
* @since v10.10.0
|
|
159
|
+
*/
|
|
67
160
|
isFile(): boolean;
|
|
161
|
+
/**
|
|
162
|
+
* Returns `true` if the `<fs.Dirent>` object describes a file system
|
|
163
|
+
* directory.
|
|
164
|
+
* @since v10.10.0
|
|
165
|
+
*/
|
|
68
166
|
isDirectory(): boolean;
|
|
167
|
+
/**
|
|
168
|
+
* Returns `true` if the `<fs.Dirent>` object describes a block device.
|
|
169
|
+
* @since v10.10.0
|
|
170
|
+
*/
|
|
69
171
|
isBlockDevice(): boolean;
|
|
172
|
+
/**
|
|
173
|
+
* Returns `true` if the `<fs.Dirent>` object describes a character device.
|
|
174
|
+
* @since v10.10.0
|
|
175
|
+
*/
|
|
70
176
|
isCharacterDevice(): boolean;
|
|
177
|
+
/**
|
|
178
|
+
* Returns `true` if the `<fs.Dirent>` object describes a symbolic link.
|
|
179
|
+
* @since v10.10.0
|
|
180
|
+
*/
|
|
71
181
|
isSymbolicLink(): boolean;
|
|
182
|
+
/**
|
|
183
|
+
* Returns `true` if the `<fs.Dirent>` object describes a first-in-first-out
|
|
184
|
+
* (FIFO) pipe.
|
|
185
|
+
* @since v10.10.0
|
|
186
|
+
*/
|
|
72
187
|
isFIFO(): boolean;
|
|
188
|
+
/**
|
|
189
|
+
* Returns `true` if the `<fs.Dirent>` object describes a socket.
|
|
190
|
+
* @since v10.10.0
|
|
191
|
+
*/
|
|
73
192
|
isSocket(): boolean;
|
|
193
|
+
/**
|
|
194
|
+
* The file name that this `<fs.Dirent>` object refers to. The type of this
|
|
195
|
+
* value is determined by the `options.encoding` passed to {@link readdir} or {@link readdirSync}.
|
|
196
|
+
* @since v10.10.0
|
|
197
|
+
*/
|
|
74
198
|
name: string;
|
|
75
199
|
}
|
|
76
|
-
|
|
77
200
|
/**
|
|
78
201
|
* A class representing a directory stream.
|
|
202
|
+
*
|
|
203
|
+
* Created by {@link opendir}, {@link opendirSync}, or {@link romises.opendir}.
|
|
204
|
+
*
|
|
205
|
+
* ```js
|
|
206
|
+
* import { opendir } from 'fs/promises';
|
|
207
|
+
*
|
|
208
|
+
* try {
|
|
209
|
+
* const dir = await opendir('./');
|
|
210
|
+
* for await (const dirent of dir)
|
|
211
|
+
* console.log(dirent.name);
|
|
212
|
+
* } catch (err) {
|
|
213
|
+
* console.error(err);
|
|
214
|
+
* }
|
|
215
|
+
* ```
|
|
216
|
+
*
|
|
217
|
+
* When using the async iterator, the `<fs.Dir>` object will be automatically
|
|
218
|
+
* closed after the iterator exits.
|
|
219
|
+
* @since v12.12.0
|
|
79
220
|
*/
|
|
80
221
|
export class Dir implements AsyncIterable<Dirent> {
|
|
222
|
+
/**
|
|
223
|
+
* The read-only path of this directory as was provided to {@link opendir},{@link opendirSync}, or {@link romises.opendir}.
|
|
224
|
+
* @since v12.12.0
|
|
225
|
+
*/
|
|
81
226
|
readonly path: string;
|
|
82
|
-
|
|
83
227
|
/**
|
|
84
228
|
* Asynchronously iterates over the directory via `readdir(3)` until all entries have been read.
|
|
85
229
|
*/
|
|
86
230
|
[Symbol.asyncIterator](): AsyncIterableIterator<Dirent>;
|
|
87
|
-
|
|
88
231
|
/**
|
|
89
232
|
* Asynchronously close the directory's underlying resource handle.
|
|
90
233
|
* Subsequent reads will result in errors.
|
|
234
|
+
*
|
|
235
|
+
* A promise is returned that will be resolved after the resource has been
|
|
236
|
+
* closed.
|
|
237
|
+
* @since v12.12.0
|
|
91
238
|
*/
|
|
92
239
|
close(): Promise<void>;
|
|
93
240
|
close(cb: NoParamCallback): void;
|
|
94
|
-
|
|
95
241
|
/**
|
|
96
242
|
* Synchronously close the directory's underlying resource handle.
|
|
97
243
|
* Subsequent reads will result in errors.
|
|
244
|
+
* @since v12.12.0
|
|
98
245
|
*/
|
|
99
246
|
closeSync(): void;
|
|
100
|
-
|
|
101
247
|
/**
|
|
102
|
-
* Asynchronously read the next directory entry via `readdir(3)` as an
|
|
103
|
-
*
|
|
104
|
-
*
|
|
248
|
+
* Asynchronously read the next directory entry via [`readdir(3)`](http://man7.org/linux/man-pages/man3/readdir.3.html) as an `<fs.Dirent>`.
|
|
249
|
+
*
|
|
250
|
+
* A promise is returned that will be resolved with an `<fs.Dirent>`, or `null`if there are no more directory entries to read.
|
|
251
|
+
*
|
|
252
|
+
* Directory entries returned by this function are in no particular order as
|
|
253
|
+
* provided by the operating system's underlying directory mechanisms.
|
|
254
|
+
* Entries added or removed while iterating over the directory might not be
|
|
255
|
+
* included in the iteration results.
|
|
256
|
+
* @since v12.12.0
|
|
257
|
+
* @return containing {fs.Dirent|null}
|
|
105
258
|
*/
|
|
106
259
|
read(): Promise<Dirent | null>;
|
|
107
260
|
read(cb: (err: NodeJS.ErrnoException | null, dirEnt: Dirent | null) => void): void;
|
|
108
|
-
|
|
109
261
|
/**
|
|
110
|
-
* Synchronously read the next directory entry
|
|
111
|
-
*
|
|
112
|
-
*
|
|
262
|
+
* Synchronously read the next directory entry as an `<fs.Dirent>`. See the
|
|
263
|
+
* POSIX [`readdir(3)`](http://man7.org/linux/man-pages/man3/readdir.3.html) documentation for more detail.
|
|
264
|
+
*
|
|
265
|
+
* If there are no more directory entries to read, `null` will be returned.
|
|
266
|
+
*
|
|
267
|
+
* Directory entries returned by this function are in no particular order as
|
|
268
|
+
* provided by the operating system's underlying directory mechanisms.
|
|
269
|
+
* Entries added or removed while iterating over the directory might not be
|
|
270
|
+
* included in the iteration results.
|
|
271
|
+
* @since v12.12.0
|
|
113
272
|
*/
|
|
114
273
|
readSync(): Dirent | null;
|
|
115
274
|
}
|
|
116
|
-
|
|
117
275
|
export interface FSWatcher extends EventEmitter {
|
|
276
|
+
/**
|
|
277
|
+
* Stop watching for changes on the given `<fs.FSWatcher>`. Once stopped, the `<fs.FSWatcher>` object is no longer usable.
|
|
278
|
+
* @since v0.5.8
|
|
279
|
+
*/
|
|
118
280
|
close(): void;
|
|
119
|
-
|
|
120
281
|
/**
|
|
121
282
|
* events.EventEmitter
|
|
122
283
|
* 1. change
|
|
123
284
|
* 2. error
|
|
124
285
|
*/
|
|
125
286
|
addListener(event: string, listener: (...args: any[]) => void): this;
|
|
126
|
-
addListener(event:
|
|
127
|
-
addListener(event:
|
|
128
|
-
addListener(event:
|
|
129
|
-
|
|
287
|
+
addListener(event: 'change', listener: (eventType: string, filename: string | Buffer) => void): this;
|
|
288
|
+
addListener(event: 'error', listener: (error: Error) => void): this;
|
|
289
|
+
addListener(event: 'close', listener: () => void): this;
|
|
130
290
|
on(event: string, listener: (...args: any[]) => void): this;
|
|
131
|
-
on(event:
|
|
132
|
-
on(event:
|
|
133
|
-
on(event:
|
|
134
|
-
|
|
291
|
+
on(event: 'change', listener: (eventType: string, filename: string | Buffer) => void): this;
|
|
292
|
+
on(event: 'error', listener: (error: Error) => void): this;
|
|
293
|
+
on(event: 'close', listener: () => void): this;
|
|
135
294
|
once(event: string, listener: (...args: any[]) => void): this;
|
|
136
|
-
once(event:
|
|
137
|
-
once(event:
|
|
138
|
-
once(event:
|
|
139
|
-
|
|
295
|
+
once(event: 'change', listener: (eventType: string, filename: string | Buffer) => void): this;
|
|
296
|
+
once(event: 'error', listener: (error: Error) => void): this;
|
|
297
|
+
once(event: 'close', listener: () => void): this;
|
|
140
298
|
prependListener(event: string, listener: (...args: any[]) => void): this;
|
|
141
|
-
prependListener(event:
|
|
142
|
-
prependListener(event:
|
|
143
|
-
prependListener(event:
|
|
144
|
-
|
|
299
|
+
prependListener(event: 'change', listener: (eventType: string, filename: string | Buffer) => void): this;
|
|
300
|
+
prependListener(event: 'error', listener: (error: Error) => void): this;
|
|
301
|
+
prependListener(event: 'close', listener: () => void): this;
|
|
145
302
|
prependOnceListener(event: string, listener: (...args: any[]) => void): this;
|
|
146
|
-
prependOnceListener(event:
|
|
147
|
-
prependOnceListener(event:
|
|
148
|
-
prependOnceListener(event:
|
|
303
|
+
prependOnceListener(event: 'change', listener: (eventType: string, filename: string | Buffer) => void): this;
|
|
304
|
+
prependOnceListener(event: 'error', listener: (error: Error) => void): this;
|
|
305
|
+
prependOnceListener(event: 'close', listener: () => void): this;
|
|
149
306
|
}
|
|
150
|
-
|
|
307
|
+
/**
|
|
308
|
+
* * Extends: `<stream.Readable>`
|
|
309
|
+
*
|
|
310
|
+
* Instances of `<fs.ReadStream>` are created and returned using the {@link createReadStream} function.
|
|
311
|
+
* @since v0.1.93
|
|
312
|
+
*/
|
|
151
313
|
export class ReadStream extends stream.Readable {
|
|
152
314
|
close(): void;
|
|
315
|
+
/**
|
|
316
|
+
* The number of bytes that have been read so far.
|
|
317
|
+
* @since v6.4.0
|
|
318
|
+
*/
|
|
153
319
|
bytesRead: number;
|
|
320
|
+
/**
|
|
321
|
+
* The path to the file the stream is reading from as specified in the first
|
|
322
|
+
* argument to `fs.createReadStream()`. If `path` is passed as a string, then`readStream.path` will be a string. If `path` is passed as a `<Buffer>`, then`readStream.path` will be a
|
|
323
|
+
* `<Buffer>`.
|
|
324
|
+
* @since v0.1.93
|
|
325
|
+
*/
|
|
154
326
|
path: string | Buffer;
|
|
327
|
+
/**
|
|
328
|
+
* This property is `true` if the underlying file has not been opened yet,
|
|
329
|
+
* i.e. before the `'ready'` event is emitted.
|
|
330
|
+
* @since v11.2.0, v10.16.0
|
|
331
|
+
*/
|
|
155
332
|
pending: boolean;
|
|
156
|
-
|
|
157
333
|
/**
|
|
158
334
|
* events.EventEmitter
|
|
159
335
|
* 1. open
|
|
160
336
|
* 2. close
|
|
161
337
|
* 3. ready
|
|
162
338
|
*/
|
|
163
|
-
addListener(event:
|
|
164
|
-
addListener(event:
|
|
165
|
-
addListener(event:
|
|
166
|
-
addListener(event:
|
|
167
|
-
addListener(event:
|
|
168
|
-
addListener(event:
|
|
169
|
-
addListener(event:
|
|
170
|
-
addListener(event:
|
|
171
|
-
addListener(event:
|
|
339
|
+
addListener(event: 'close', listener: () => void): this;
|
|
340
|
+
addListener(event: 'data', listener: (chunk: Buffer | string) => void): this;
|
|
341
|
+
addListener(event: 'end', listener: () => void): this;
|
|
342
|
+
addListener(event: 'error', listener: (err: Error) => void): this;
|
|
343
|
+
addListener(event: 'open', listener: (fd: number) => void): this;
|
|
344
|
+
addListener(event: 'pause', listener: () => void): this;
|
|
345
|
+
addListener(event: 'readable', listener: () => void): this;
|
|
346
|
+
addListener(event: 'ready', listener: () => void): this;
|
|
347
|
+
addListener(event: 'resume', listener: () => void): this;
|
|
172
348
|
addListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
173
|
-
|
|
174
|
-
on(event:
|
|
175
|
-
on(event:
|
|
176
|
-
on(event:
|
|
177
|
-
on(event:
|
|
178
|
-
on(event:
|
|
179
|
-
on(event:
|
|
180
|
-
on(event:
|
|
181
|
-
on(event:
|
|
182
|
-
on(event: "resume", listener: () => void): this;
|
|
349
|
+
on(event: 'close', listener: () => void): this;
|
|
350
|
+
on(event: 'data', listener: (chunk: Buffer | string) => void): this;
|
|
351
|
+
on(event: 'end', listener: () => void): this;
|
|
352
|
+
on(event: 'error', listener: (err: Error) => void): this;
|
|
353
|
+
on(event: 'open', listener: (fd: number) => void): this;
|
|
354
|
+
on(event: 'pause', listener: () => void): this;
|
|
355
|
+
on(event: 'readable', listener: () => void): this;
|
|
356
|
+
on(event: 'ready', listener: () => void): this;
|
|
357
|
+
on(event: 'resume', listener: () => void): this;
|
|
183
358
|
on(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
184
|
-
|
|
185
|
-
once(event:
|
|
186
|
-
once(event:
|
|
187
|
-
once(event:
|
|
188
|
-
once(event:
|
|
189
|
-
once(event:
|
|
190
|
-
once(event:
|
|
191
|
-
once(event:
|
|
192
|
-
once(event:
|
|
193
|
-
once(event: "resume", listener: () => void): this;
|
|
359
|
+
once(event: 'close', listener: () => void): this;
|
|
360
|
+
once(event: 'data', listener: (chunk: Buffer | string) => void): this;
|
|
361
|
+
once(event: 'end', listener: () => void): this;
|
|
362
|
+
once(event: 'error', listener: (err: Error) => void): this;
|
|
363
|
+
once(event: 'open', listener: (fd: number) => void): this;
|
|
364
|
+
once(event: 'pause', listener: () => void): this;
|
|
365
|
+
once(event: 'readable', listener: () => void): this;
|
|
366
|
+
once(event: 'ready', listener: () => void): this;
|
|
367
|
+
once(event: 'resume', listener: () => void): this;
|
|
194
368
|
once(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
195
|
-
|
|
196
|
-
prependListener(event:
|
|
197
|
-
prependListener(event:
|
|
198
|
-
prependListener(event:
|
|
199
|
-
prependListener(event:
|
|
200
|
-
prependListener(event:
|
|
201
|
-
prependListener(event:
|
|
202
|
-
prependListener(event:
|
|
203
|
-
prependListener(event:
|
|
204
|
-
prependListener(event: "resume", listener: () => void): this;
|
|
369
|
+
prependListener(event: 'close', listener: () => void): this;
|
|
370
|
+
prependListener(event: 'data', listener: (chunk: Buffer | string) => void): this;
|
|
371
|
+
prependListener(event: 'end', listener: () => void): this;
|
|
372
|
+
prependListener(event: 'error', listener: (err: Error) => void): this;
|
|
373
|
+
prependListener(event: 'open', listener: (fd: number) => void): this;
|
|
374
|
+
prependListener(event: 'pause', listener: () => void): this;
|
|
375
|
+
prependListener(event: 'readable', listener: () => void): this;
|
|
376
|
+
prependListener(event: 'ready', listener: () => void): this;
|
|
377
|
+
prependListener(event: 'resume', listener: () => void): this;
|
|
205
378
|
prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
206
|
-
|
|
207
|
-
prependOnceListener(event:
|
|
208
|
-
prependOnceListener(event:
|
|
209
|
-
prependOnceListener(event:
|
|
210
|
-
prependOnceListener(event:
|
|
211
|
-
prependOnceListener(event:
|
|
212
|
-
prependOnceListener(event:
|
|
213
|
-
prependOnceListener(event:
|
|
214
|
-
prependOnceListener(event:
|
|
215
|
-
prependOnceListener(event: "resume", listener: () => void): this;
|
|
379
|
+
prependOnceListener(event: 'close', listener: () => void): this;
|
|
380
|
+
prependOnceListener(event: 'data', listener: (chunk: Buffer | string) => void): this;
|
|
381
|
+
prependOnceListener(event: 'end', listener: () => void): this;
|
|
382
|
+
prependOnceListener(event: 'error', listener: (err: Error) => void): this;
|
|
383
|
+
prependOnceListener(event: 'open', listener: (fd: number) => void): this;
|
|
384
|
+
prependOnceListener(event: 'pause', listener: () => void): this;
|
|
385
|
+
prependOnceListener(event: 'readable', listener: () => void): this;
|
|
386
|
+
prependOnceListener(event: 'ready', listener: () => void): this;
|
|
387
|
+
prependOnceListener(event: 'resume', listener: () => void): this;
|
|
216
388
|
prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
217
389
|
}
|
|
218
|
-
|
|
390
|
+
/**
|
|
391
|
+
* * Extends `<stream.Writable>`
|
|
392
|
+
*
|
|
393
|
+
* Instances of `<fs.WriteStream>` are created and returned using the {@link createWriteStream} function.
|
|
394
|
+
* @since v0.1.93
|
|
395
|
+
*/
|
|
219
396
|
export class WriteStream extends stream.Writable {
|
|
397
|
+
/**
|
|
398
|
+
* Closes `writeStream`. Optionally accepts a
|
|
399
|
+
* callback that will be executed once the `writeStream`is closed.
|
|
400
|
+
* @since v0.9.4
|
|
401
|
+
*/
|
|
220
402
|
close(): void;
|
|
403
|
+
/**
|
|
404
|
+
* The number of bytes written so far. Does not include data that is still queued
|
|
405
|
+
* for writing.
|
|
406
|
+
* @since v0.4.7
|
|
407
|
+
*/
|
|
221
408
|
bytesWritten: number;
|
|
409
|
+
/**
|
|
410
|
+
* The path to the file the stream is writing to as specified in the first
|
|
411
|
+
* argument to {@link createWriteStream}. If `path` is passed as a string, then`writeStream.path` will be a string. If `path` is passed as a `<Buffer>`, then`writeStream.path` will be a
|
|
412
|
+
* `<Buffer>`.
|
|
413
|
+
* @since v0.1.93
|
|
414
|
+
*/
|
|
222
415
|
path: string | Buffer;
|
|
416
|
+
/**
|
|
417
|
+
* This property is `true` if the underlying file has not been opened yet,
|
|
418
|
+
* i.e. before the `'ready'` event is emitted.
|
|
419
|
+
* @since v11.2.0
|
|
420
|
+
*/
|
|
223
421
|
pending: boolean;
|
|
224
|
-
|
|
225
422
|
/**
|
|
226
423
|
* events.EventEmitter
|
|
227
424
|
* 1. open
|
|
228
425
|
* 2. close
|
|
229
426
|
* 3. ready
|
|
230
427
|
*/
|
|
231
|
-
addListener(event:
|
|
232
|
-
addListener(event:
|
|
233
|
-
addListener(event:
|
|
234
|
-
addListener(event:
|
|
235
|
-
addListener(event:
|
|
236
|
-
addListener(event:
|
|
237
|
-
addListener(event:
|
|
238
|
-
addListener(event:
|
|
428
|
+
addListener(event: 'close', listener: () => void): this;
|
|
429
|
+
addListener(event: 'drain', listener: () => void): this;
|
|
430
|
+
addListener(event: 'error', listener: (err: Error) => void): this;
|
|
431
|
+
addListener(event: 'finish', listener: () => void): this;
|
|
432
|
+
addListener(event: 'open', listener: (fd: number) => void): this;
|
|
433
|
+
addListener(event: 'pipe', listener: (src: stream.Readable) => void): this;
|
|
434
|
+
addListener(event: 'ready', listener: () => void): this;
|
|
435
|
+
addListener(event: 'unpipe', listener: (src: stream.Readable) => void): this;
|
|
239
436
|
addListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
240
|
-
|
|
241
|
-
on(event:
|
|
242
|
-
on(event:
|
|
243
|
-
on(event:
|
|
244
|
-
on(event:
|
|
245
|
-
on(event:
|
|
246
|
-
on(event:
|
|
247
|
-
on(event:
|
|
248
|
-
on(event: "unpipe", listener: (src: stream.Readable) => void): this;
|
|
437
|
+
on(event: 'close', listener: () => void): this;
|
|
438
|
+
on(event: 'drain', listener: () => void): this;
|
|
439
|
+
on(event: 'error', listener: (err: Error) => void): this;
|
|
440
|
+
on(event: 'finish', listener: () => void): this;
|
|
441
|
+
on(event: 'open', listener: (fd: number) => void): this;
|
|
442
|
+
on(event: 'pipe', listener: (src: stream.Readable) => void): this;
|
|
443
|
+
on(event: 'ready', listener: () => void): this;
|
|
444
|
+
on(event: 'unpipe', listener: (src: stream.Readable) => void): this;
|
|
249
445
|
on(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
250
|
-
|
|
251
|
-
once(event:
|
|
252
|
-
once(event:
|
|
253
|
-
once(event:
|
|
254
|
-
once(event:
|
|
255
|
-
once(event:
|
|
256
|
-
once(event:
|
|
257
|
-
once(event:
|
|
258
|
-
once(event: "unpipe", listener: (src: stream.Readable) => void): this;
|
|
446
|
+
once(event: 'close', listener: () => void): this;
|
|
447
|
+
once(event: 'drain', listener: () => void): this;
|
|
448
|
+
once(event: 'error', listener: (err: Error) => void): this;
|
|
449
|
+
once(event: 'finish', listener: () => void): this;
|
|
450
|
+
once(event: 'open', listener: (fd: number) => void): this;
|
|
451
|
+
once(event: 'pipe', listener: (src: stream.Readable) => void): this;
|
|
452
|
+
once(event: 'ready', listener: () => void): this;
|
|
453
|
+
once(event: 'unpipe', listener: (src: stream.Readable) => void): this;
|
|
259
454
|
once(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
260
|
-
|
|
261
|
-
prependListener(event:
|
|
262
|
-
prependListener(event:
|
|
263
|
-
prependListener(event:
|
|
264
|
-
prependListener(event:
|
|
265
|
-
prependListener(event:
|
|
266
|
-
prependListener(event:
|
|
267
|
-
prependListener(event:
|
|
268
|
-
prependListener(event: "unpipe", listener: (src: stream.Readable) => void): this;
|
|
455
|
+
prependListener(event: 'close', listener: () => void): this;
|
|
456
|
+
prependListener(event: 'drain', listener: () => void): this;
|
|
457
|
+
prependListener(event: 'error', listener: (err: Error) => void): this;
|
|
458
|
+
prependListener(event: 'finish', listener: () => void): this;
|
|
459
|
+
prependListener(event: 'open', listener: (fd: number) => void): this;
|
|
460
|
+
prependListener(event: 'pipe', listener: (src: stream.Readable) => void): this;
|
|
461
|
+
prependListener(event: 'ready', listener: () => void): this;
|
|
462
|
+
prependListener(event: 'unpipe', listener: (src: stream.Readable) => void): this;
|
|
269
463
|
prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
270
|
-
|
|
271
|
-
prependOnceListener(event:
|
|
272
|
-
prependOnceListener(event:
|
|
273
|
-
prependOnceListener(event:
|
|
274
|
-
prependOnceListener(event:
|
|
275
|
-
prependOnceListener(event:
|
|
276
|
-
prependOnceListener(event:
|
|
277
|
-
prependOnceListener(event:
|
|
278
|
-
prependOnceListener(event: "unpipe", listener: (src: stream.Readable) => void): this;
|
|
464
|
+
prependOnceListener(event: 'close', listener: () => void): this;
|
|
465
|
+
prependOnceListener(event: 'drain', listener: () => void): this;
|
|
466
|
+
prependOnceListener(event: 'error', listener: (err: Error) => void): this;
|
|
467
|
+
prependOnceListener(event: 'finish', listener: () => void): this;
|
|
468
|
+
prependOnceListener(event: 'open', listener: (fd: number) => void): this;
|
|
469
|
+
prependOnceListener(event: 'pipe', listener: (src: stream.Readable) => void): this;
|
|
470
|
+
prependOnceListener(event: 'ready', listener: () => void): this;
|
|
471
|
+
prependOnceListener(event: 'unpipe', listener: (src: stream.Readable) => void): this;
|
|
279
472
|
prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
280
473
|
}
|
|
281
|
-
|
|
282
474
|
/**
|
|
283
|
-
*
|
|
284
|
-
*
|
|
285
|
-
*
|
|
475
|
+
* Asynchronously rename file at `oldPath` to the pathname provided
|
|
476
|
+
* as `newPath`. In the case that `newPath` already exists, it will
|
|
477
|
+
* be overwritten. If there is a directory at `newPath`, an error will
|
|
478
|
+
* be raised instead. No arguments other than a possible exception are
|
|
479
|
+
* given to the completion callback.
|
|
480
|
+
*
|
|
481
|
+
* See also: [`rename(2)`](http://man7.org/linux/man-pages/man2/rename.2.html).
|
|
482
|
+
*
|
|
483
|
+
* ```js
|
|
484
|
+
* import { rename } from 'fs';
|
|
485
|
+
*
|
|
486
|
+
* rename('oldFile.txt', 'newFile.txt', (err) => {
|
|
487
|
+
* if (err) throw err;
|
|
488
|
+
* console.log('Rename complete!');
|
|
489
|
+
* });
|
|
490
|
+
* ```
|
|
491
|
+
* @since v0.0.2
|
|
286
492
|
*/
|
|
287
493
|
export function rename(oldPath: PathLike, newPath: PathLike, callback: NoParamCallback): void;
|
|
288
|
-
|
|
289
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
290
494
|
export namespace rename {
|
|
291
495
|
/**
|
|
292
496
|
* Asynchronous rename(2) - Change the name or location of a file or directory.
|
|
@@ -297,28 +501,30 @@ declare module 'fs' {
|
|
|
297
501
|
*/
|
|
298
502
|
function __promisify__(oldPath: PathLike, newPath: PathLike): Promise<void>;
|
|
299
503
|
}
|
|
300
|
-
|
|
301
504
|
/**
|
|
302
|
-
*
|
|
303
|
-
*
|
|
304
|
-
*
|
|
505
|
+
* Renames the file from `oldPath` to `newPath`. Returns `undefined`.
|
|
506
|
+
*
|
|
507
|
+
* See the POSIX [`rename(2)`](http://man7.org/linux/man-pages/man2/rename.2.html) documentation for more details.
|
|
508
|
+
* @since v0.1.21
|
|
305
509
|
*/
|
|
306
510
|
export function renameSync(oldPath: PathLike, newPath: PathLike): void;
|
|
307
|
-
|
|
308
511
|
/**
|
|
309
|
-
*
|
|
310
|
-
*
|
|
311
|
-
*
|
|
512
|
+
* Truncates the file. No arguments other than a possible exception are
|
|
513
|
+
* given to the completion callback. A file descriptor can also be passed as the
|
|
514
|
+
* first argument. In this case, `fs.ftruncate()` is called.
|
|
515
|
+
*
|
|
516
|
+
* Passing a file descriptor is deprecated and may result in an error being thrown
|
|
517
|
+
* in the future.
|
|
518
|
+
*
|
|
519
|
+
* See the POSIX [`truncate(2)`](http://man7.org/linux/man-pages/man2/truncate.2.html) documentation for more details.
|
|
520
|
+
* @since v0.8.6
|
|
312
521
|
*/
|
|
313
522
|
export function truncate(path: PathLike, len: number | undefined | null, callback: NoParamCallback): void;
|
|
314
|
-
|
|
315
523
|
/**
|
|
316
524
|
* Asynchronous truncate(2) - Truncate a file to a specified length.
|
|
317
525
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
318
526
|
*/
|
|
319
527
|
export function truncate(path: PathLike, callback: NoParamCallback): void;
|
|
320
|
-
|
|
321
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
322
528
|
export namespace truncate {
|
|
323
529
|
/**
|
|
324
530
|
* Asynchronous truncate(2) - Truncate a file to a specified length.
|
|
@@ -327,28 +533,63 @@ declare module 'fs' {
|
|
|
327
533
|
*/
|
|
328
534
|
function __promisify__(path: PathLike, len?: number | null): Promise<void>;
|
|
329
535
|
}
|
|
330
|
-
|
|
331
536
|
/**
|
|
332
|
-
*
|
|
333
|
-
*
|
|
334
|
-
*
|
|
537
|
+
* Truncates the file. Returns `undefined`. A file descriptor can also be
|
|
538
|
+
* passed as the first argument. In this case, `fs.ftruncateSync()` is called.
|
|
539
|
+
*
|
|
540
|
+
* Passing a file descriptor is deprecated and may result in an error being thrown
|
|
541
|
+
* in the future.
|
|
542
|
+
* @since v0.8.6
|
|
335
543
|
*/
|
|
336
544
|
export function truncateSync(path: PathLike, len?: number | null): void;
|
|
337
|
-
|
|
338
545
|
/**
|
|
339
|
-
*
|
|
340
|
-
*
|
|
341
|
-
*
|
|
546
|
+
* Truncates the file descriptor. No arguments other than a possible exception are
|
|
547
|
+
* given to the completion callback.
|
|
548
|
+
*
|
|
549
|
+
* See the POSIX [`ftruncate(2)`](http://man7.org/linux/man-pages/man2/ftruncate.2.html) documentation for more detail.
|
|
550
|
+
*
|
|
551
|
+
* If the file referred to by the file descriptor was larger than `len` bytes, only
|
|
552
|
+
* the first `len` bytes will be retained in the file.
|
|
553
|
+
*
|
|
554
|
+
* For example, the following program retains only the first four bytes of the
|
|
555
|
+
* file:
|
|
556
|
+
*
|
|
557
|
+
* ```js
|
|
558
|
+
* import { open, close, ftruncate } from 'fs';
|
|
559
|
+
*
|
|
560
|
+
* function closeFd(fd) {
|
|
561
|
+
* close(fd, (err) => {
|
|
562
|
+
* if (err) throw err;
|
|
563
|
+
* });
|
|
564
|
+
* }
|
|
565
|
+
*
|
|
566
|
+
* open('temp.txt', 'r+', (err, fd) => {
|
|
567
|
+
* if (err) throw err;
|
|
568
|
+
*
|
|
569
|
+
* try {
|
|
570
|
+
* ftruncate(fd, 4, (err) => {
|
|
571
|
+
* closeFd(fd);
|
|
572
|
+
* if (err) throw err;
|
|
573
|
+
* });
|
|
574
|
+
* } catch (err) {
|
|
575
|
+
* closeFd(fd);
|
|
576
|
+
* if (err) throw err;
|
|
577
|
+
* }
|
|
578
|
+
* });
|
|
579
|
+
* ```
|
|
580
|
+
*
|
|
581
|
+
* If the file previously was shorter than `len` bytes, it is extended, and the
|
|
582
|
+
* extended part is filled with null bytes (`'\0'`):
|
|
583
|
+
*
|
|
584
|
+
* If `len` is negative then `0` will be used.
|
|
585
|
+
* @since v0.8.6
|
|
342
586
|
*/
|
|
343
587
|
export function ftruncate(fd: number, len: number | undefined | null, callback: NoParamCallback): void;
|
|
344
|
-
|
|
345
588
|
/**
|
|
346
589
|
* Asynchronous ftruncate(2) - Truncate a file to a specified length.
|
|
347
590
|
* @param fd A file descriptor.
|
|
348
591
|
*/
|
|
349
592
|
export function ftruncate(fd: number, callback: NoParamCallback): void;
|
|
350
|
-
|
|
351
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
352
593
|
export namespace ftruncate {
|
|
353
594
|
/**
|
|
354
595
|
* Asynchronous ftruncate(2) - Truncate a file to a specified length.
|
|
@@ -357,21 +598,22 @@ declare module 'fs' {
|
|
|
357
598
|
*/
|
|
358
599
|
function __promisify__(fd: number, len?: number | null): Promise<void>;
|
|
359
600
|
}
|
|
360
|
-
|
|
361
601
|
/**
|
|
362
|
-
*
|
|
363
|
-
*
|
|
364
|
-
*
|
|
602
|
+
* Truncates the file descriptor. Returns `undefined`.
|
|
603
|
+
*
|
|
604
|
+
* For detailed information, see the documentation of the asynchronous version of
|
|
605
|
+
* this API: {@link ftruncate}.
|
|
606
|
+
* @since v0.8.6
|
|
365
607
|
*/
|
|
366
608
|
export function ftruncateSync(fd: number, len?: number | null): void;
|
|
367
|
-
|
|
368
609
|
/**
|
|
369
|
-
*
|
|
370
|
-
*
|
|
610
|
+
* Asynchronously changes owner and group of a file. No arguments other than a
|
|
611
|
+
* possible exception are given to the completion callback.
|
|
612
|
+
*
|
|
613
|
+
* See the POSIX [`chown(2)`](http://man7.org/linux/man-pages/man2/chown.2.html) documentation for more detail.
|
|
614
|
+
* @since v0.1.97
|
|
371
615
|
*/
|
|
372
616
|
export function chown(path: PathLike, uid: number, gid: number, callback: NoParamCallback): void;
|
|
373
|
-
|
|
374
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
375
617
|
export namespace chown {
|
|
376
618
|
/**
|
|
377
619
|
* Asynchronous chown(2) - Change ownership of a file.
|
|
@@ -379,20 +621,22 @@ declare module 'fs' {
|
|
|
379
621
|
*/
|
|
380
622
|
function __promisify__(path: PathLike, uid: number, gid: number): Promise<void>;
|
|
381
623
|
}
|
|
382
|
-
|
|
383
624
|
/**
|
|
384
|
-
*
|
|
385
|
-
*
|
|
625
|
+
* Synchronously changes owner and group of a file. Returns `undefined`.
|
|
626
|
+
* This is the synchronous version of {@link chown}.
|
|
627
|
+
*
|
|
628
|
+
* See the POSIX [`chown(2)`](http://man7.org/linux/man-pages/man2/chown.2.html) documentation for more detail.
|
|
629
|
+
* @since v0.1.97
|
|
386
630
|
*/
|
|
387
631
|
export function chownSync(path: PathLike, uid: number, gid: number): void;
|
|
388
|
-
|
|
389
632
|
/**
|
|
390
|
-
*
|
|
391
|
-
*
|
|
633
|
+
* Sets the owner of the file. No arguments other than a possible exception are
|
|
634
|
+
* given to the completion callback.
|
|
635
|
+
*
|
|
636
|
+
* See the POSIX [`fchown(2)`](http://man7.org/linux/man-pages/man2/fchown.2.html) documentation for more detail.
|
|
637
|
+
* @since v0.4.7
|
|
392
638
|
*/
|
|
393
639
|
export function fchown(fd: number, uid: number, gid: number, callback: NoParamCallback): void;
|
|
394
|
-
|
|
395
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
396
640
|
export namespace fchown {
|
|
397
641
|
/**
|
|
398
642
|
* Asynchronous fchown(2) - Change ownership of a file.
|
|
@@ -400,20 +644,22 @@ declare module 'fs' {
|
|
|
400
644
|
*/
|
|
401
645
|
function __promisify__(fd: number, uid: number, gid: number): Promise<void>;
|
|
402
646
|
}
|
|
403
|
-
|
|
404
647
|
/**
|
|
405
|
-
*
|
|
406
|
-
*
|
|
648
|
+
* Sets the owner of the file. Returns `undefined`.
|
|
649
|
+
*
|
|
650
|
+
* See the POSIX [`fchown(2)`](http://man7.org/linux/man-pages/man2/fchown.2.html) documentation for more detail.
|
|
651
|
+
* @since v0.4.7
|
|
652
|
+
* @param uid The file's new owner's user id.
|
|
653
|
+
* @param gid The file's new group's group id.
|
|
407
654
|
*/
|
|
408
655
|
export function fchownSync(fd: number, uid: number, gid: number): void;
|
|
409
|
-
|
|
410
656
|
/**
|
|
411
|
-
*
|
|
412
|
-
*
|
|
657
|
+
* Set the owner of the symbolic link. No arguments other than a possible
|
|
658
|
+
* exception are given to the completion callback.
|
|
659
|
+
*
|
|
660
|
+
* See the POSIX [`lchown(2)`](http://man7.org/linux/man-pages/man2/lchown.2.html) documentation for more detail.
|
|
413
661
|
*/
|
|
414
662
|
export function lchown(path: PathLike, uid: number, gid: number, callback: NoParamCallback): void;
|
|
415
|
-
|
|
416
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
417
663
|
export namespace lchown {
|
|
418
664
|
/**
|
|
419
665
|
* Asynchronous lchown(2) - Change ownership of a file. Does not dereference symbolic links.
|
|
@@ -421,24 +667,24 @@ declare module 'fs' {
|
|
|
421
667
|
*/
|
|
422
668
|
function __promisify__(path: PathLike, uid: number, gid: number): Promise<void>;
|
|
423
669
|
}
|
|
424
|
-
|
|
425
670
|
/**
|
|
426
|
-
*
|
|
427
|
-
*
|
|
671
|
+
* Set the owner for the path. Returns `undefined`.
|
|
672
|
+
*
|
|
673
|
+
* See the POSIX [`lchown(2)`](http://man7.org/linux/man-pages/man2/lchown.2.html) documentation for more details.
|
|
674
|
+
* @param uid The file's new owner's user id.
|
|
675
|
+
* @param gid The file's new group's group id.
|
|
428
676
|
*/
|
|
429
677
|
export function lchownSync(path: PathLike, uid: number, gid: number): void;
|
|
430
|
-
|
|
431
678
|
/**
|
|
432
|
-
* Changes the access and modification times of a file in the same way as
|
|
433
|
-
*
|
|
434
|
-
*
|
|
435
|
-
*
|
|
436
|
-
*
|
|
437
|
-
*
|
|
679
|
+
* Changes the access and modification times of a file in the same way as {@link utimes}, with the difference that if the path refers to a symbolic
|
|
680
|
+
* link, then the link is not dereferenced: instead, the timestamps of the
|
|
681
|
+
* symbolic link itself are changed.
|
|
682
|
+
*
|
|
683
|
+
* No arguments other than a possible exception are given to the completion
|
|
684
|
+
* callback.
|
|
685
|
+
* @since v14.5.0, v12.19.0
|
|
438
686
|
*/
|
|
439
687
|
export function lutimes(path: PathLike, atime: TimeLike, mtime: TimeLike, callback: NoParamCallback): void;
|
|
440
|
-
|
|
441
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
442
688
|
export namespace lutimes {
|
|
443
689
|
/**
|
|
444
690
|
* Changes the access and modification times of a file in the same way as `fsPromises.utimes()`,
|
|
@@ -450,25 +696,30 @@ declare module 'fs' {
|
|
|
450
696
|
*/
|
|
451
697
|
function __promisify__(path: PathLike, atime: TimeLike, mtime: TimeLike): Promise<void>;
|
|
452
698
|
}
|
|
453
|
-
|
|
454
699
|
/**
|
|
455
|
-
* Change the file system timestamps of the symbolic link referenced by `path`.
|
|
456
|
-
* or throws an exception when parameters are incorrect or
|
|
457
|
-
* This is the synchronous version of
|
|
458
|
-
* @
|
|
459
|
-
* @param atime The last access time. If a string is provided, it will be coerced to number.
|
|
460
|
-
* @param mtime The last modified time. If a string is provided, it will be coerced to number.
|
|
700
|
+
* Change the file system timestamps of the symbolic link referenced by `path`.
|
|
701
|
+
* Returns `undefined`, or throws an exception when parameters are incorrect or
|
|
702
|
+
* the operation fails. This is the synchronous version of {@link lutimes}.
|
|
703
|
+
* @since v14.5.0, v12.19.0
|
|
461
704
|
*/
|
|
462
705
|
export function lutimesSync(path: PathLike, atime: TimeLike, mtime: TimeLike): void;
|
|
463
|
-
|
|
464
706
|
/**
|
|
465
|
-
*
|
|
466
|
-
*
|
|
467
|
-
*
|
|
707
|
+
* Asynchronously changes the permissions of a file. No arguments other than a
|
|
708
|
+
* possible exception are given to the completion callback.
|
|
709
|
+
*
|
|
710
|
+
* See the POSIX [`chmod(2)`](http://man7.org/linux/man-pages/man2/chmod.2.html) documentation for more detail.
|
|
711
|
+
*
|
|
712
|
+
* ```js
|
|
713
|
+
* import { chmod } from 'fs';
|
|
714
|
+
*
|
|
715
|
+
* chmod('my_file.txt', 0o775, (err) => {
|
|
716
|
+
* if (err) throw err;
|
|
717
|
+
* console.log('The permissions for file "my_file.txt" have been changed!');
|
|
718
|
+
* });
|
|
719
|
+
* ```
|
|
720
|
+
* @since v0.1.30
|
|
468
721
|
*/
|
|
469
722
|
export function chmod(path: PathLike, mode: Mode, callback: NoParamCallback): void;
|
|
470
|
-
|
|
471
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
472
723
|
export namespace chmod {
|
|
473
724
|
/**
|
|
474
725
|
* Asynchronous chmod(2) - Change permissions of a file.
|
|
@@ -477,22 +728,22 @@ declare module 'fs' {
|
|
|
477
728
|
*/
|
|
478
729
|
function __promisify__(path: PathLike, mode: Mode): Promise<void>;
|
|
479
730
|
}
|
|
480
|
-
|
|
481
731
|
/**
|
|
482
|
-
*
|
|
483
|
-
*
|
|
484
|
-
*
|
|
732
|
+
* For detailed information, see the documentation of the asynchronous version of
|
|
733
|
+
* this API: {@link chmod}.
|
|
734
|
+
*
|
|
735
|
+
* See the POSIX [`chmod(2)`](http://man7.org/linux/man-pages/man2/chmod.2.html) documentation for more detail.
|
|
736
|
+
* @since v0.6.7
|
|
485
737
|
*/
|
|
486
738
|
export function chmodSync(path: PathLike, mode: Mode): void;
|
|
487
|
-
|
|
488
739
|
/**
|
|
489
|
-
*
|
|
490
|
-
*
|
|
491
|
-
*
|
|
740
|
+
* Sets the permissions on the file. No arguments other than a possible exception
|
|
741
|
+
* are given to the completion callback.
|
|
742
|
+
*
|
|
743
|
+
* See the POSIX [`fchmod(2)`](http://man7.org/linux/man-pages/man2/fchmod.2.html) documentation for more detail.
|
|
744
|
+
* @since v0.4.7
|
|
492
745
|
*/
|
|
493
746
|
export function fchmod(fd: number, mode: Mode, callback: NoParamCallback): void;
|
|
494
|
-
|
|
495
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
496
747
|
export namespace fchmod {
|
|
497
748
|
/**
|
|
498
749
|
* Asynchronous fchmod(2) - Change permissions of a file.
|
|
@@ -501,22 +752,23 @@ declare module 'fs' {
|
|
|
501
752
|
*/
|
|
502
753
|
function __promisify__(fd: number, mode: Mode): Promise<void>;
|
|
503
754
|
}
|
|
504
|
-
|
|
505
755
|
/**
|
|
506
|
-
*
|
|
507
|
-
*
|
|
508
|
-
*
|
|
756
|
+
* Sets the permissions on the file. Returns `undefined`.
|
|
757
|
+
*
|
|
758
|
+
* See the POSIX [`fchmod(2)`](http://man7.org/linux/man-pages/man2/fchmod.2.html) documentation for more detail.
|
|
759
|
+
* @since v0.4.7
|
|
509
760
|
*/
|
|
510
761
|
export function fchmodSync(fd: number, mode: Mode): void;
|
|
511
|
-
|
|
512
762
|
/**
|
|
513
|
-
*
|
|
514
|
-
*
|
|
515
|
-
*
|
|
763
|
+
* Changes the permissions on a symbolic link. No arguments other than a possible
|
|
764
|
+
* exception are given to the completion callback.
|
|
765
|
+
*
|
|
766
|
+
* This method is only implemented on macOS.
|
|
767
|
+
*
|
|
768
|
+
* See the POSIX [`lchmod(2)`](https://www.freebsd.org/cgi/man.cgi?query=lchmod&sektion=2) documentation for more detail.
|
|
769
|
+
* @deprecated Since v0.4.7
|
|
516
770
|
*/
|
|
517
771
|
export function lchmod(path: PathLike, mode: Mode, callback: NoParamCallback): void;
|
|
518
|
-
|
|
519
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
520
772
|
export namespace lchmod {
|
|
521
773
|
/**
|
|
522
774
|
* Asynchronous lchmod(2) - Change permissions of a file. Does not dereference symbolic links.
|
|
@@ -525,109 +777,281 @@ declare module 'fs' {
|
|
|
525
777
|
*/
|
|
526
778
|
function __promisify__(path: PathLike, mode: Mode): Promise<void>;
|
|
527
779
|
}
|
|
528
|
-
|
|
529
780
|
/**
|
|
530
|
-
*
|
|
531
|
-
*
|
|
532
|
-
*
|
|
781
|
+
* Changes the permissions on a symbolic link. Returns `undefined`.
|
|
782
|
+
*
|
|
783
|
+
* This method is only implemented on macOS.
|
|
784
|
+
*
|
|
785
|
+
* See the POSIX [`lchmod(2)`](https://www.freebsd.org/cgi/man.cgi?query=lchmod&sektion=2) documentation for more detail.
|
|
786
|
+
* @deprecated Since v0.4.7
|
|
533
787
|
*/
|
|
534
788
|
export function lchmodSync(path: PathLike, mode: Mode): void;
|
|
535
|
-
|
|
536
789
|
/**
|
|
537
|
-
* Asynchronous stat(2)
|
|
538
|
-
*
|
|
790
|
+
* Asynchronous [`stat(2)`](http://man7.org/linux/man-pages/man2/stat.2.html). The callback gets two arguments `(err, stats)` where`stats` is an `<fs.Stats>` object.
|
|
791
|
+
*
|
|
792
|
+
* In case of an error, the `err.code` will be one of `Common System Errors`.
|
|
793
|
+
*
|
|
794
|
+
* Using `fs.stat()` to check for the existence of a file before calling`fs.open()`, `fs.readFile()` or `fs.writeFile()` is not recommended.
|
|
795
|
+
* Instead, user code should open/read/write the file directly and handle the
|
|
796
|
+
* error raised if the file is not available.
|
|
797
|
+
*
|
|
798
|
+
* To check if a file exists without manipulating it afterwards, {@link access} is recommended.
|
|
799
|
+
*
|
|
800
|
+
* For example, given the following directory structure:
|
|
801
|
+
*
|
|
802
|
+
* ```text
|
|
803
|
+
* - txtDir
|
|
804
|
+
* -- file.txt
|
|
805
|
+
* - app.js
|
|
806
|
+
* ```
|
|
807
|
+
*
|
|
808
|
+
* The next program will check for the stats of the given paths:
|
|
809
|
+
*
|
|
810
|
+
* ```js
|
|
811
|
+
* import { stat } from 'fs';
|
|
812
|
+
*
|
|
813
|
+
* const pathsToCheck = ['./txtDir', './txtDir/file.txt'];
|
|
814
|
+
*
|
|
815
|
+
* for (let i = 0; i < pathsToCheck.length; i++) {
|
|
816
|
+
* stat(pathsToCheck[i], (err, stats) => {
|
|
817
|
+
* console.log(stats.isDirectory());
|
|
818
|
+
* console.log(stats);
|
|
819
|
+
* });
|
|
820
|
+
* }
|
|
821
|
+
* ```
|
|
822
|
+
*
|
|
823
|
+
* The resulting output will resemble:
|
|
824
|
+
*
|
|
825
|
+
* ```console
|
|
826
|
+
* true
|
|
827
|
+
* Stats {
|
|
828
|
+
* dev: 16777220,
|
|
829
|
+
* mode: 16877,
|
|
830
|
+
* nlink: 3,
|
|
831
|
+
* uid: 501,
|
|
832
|
+
* gid: 20,
|
|
833
|
+
* rdev: 0,
|
|
834
|
+
* blksize: 4096,
|
|
835
|
+
* ino: 14214262,
|
|
836
|
+
* size: 96,
|
|
837
|
+
* blocks: 0,
|
|
838
|
+
* atimeMs: 1561174653071.963,
|
|
839
|
+
* mtimeMs: 1561174614583.3518,
|
|
840
|
+
* ctimeMs: 1561174626623.5366,
|
|
841
|
+
* birthtimeMs: 1561174126937.2893,
|
|
842
|
+
* atime: 2019-06-22T03:37:33.072Z,
|
|
843
|
+
* mtime: 2019-06-22T03:36:54.583Z,
|
|
844
|
+
* ctime: 2019-06-22T03:37:06.624Z,
|
|
845
|
+
* birthtime: 2019-06-22T03:28:46.937Z
|
|
846
|
+
* }
|
|
847
|
+
* false
|
|
848
|
+
* Stats {
|
|
849
|
+
* dev: 16777220,
|
|
850
|
+
* mode: 33188,
|
|
851
|
+
* nlink: 1,
|
|
852
|
+
* uid: 501,
|
|
853
|
+
* gid: 20,
|
|
854
|
+
* rdev: 0,
|
|
855
|
+
* blksize: 4096,
|
|
856
|
+
* ino: 14214074,
|
|
857
|
+
* size: 8,
|
|
858
|
+
* blocks: 8,
|
|
859
|
+
* atimeMs: 1561174616618.8555,
|
|
860
|
+
* mtimeMs: 1561174614584,
|
|
861
|
+
* ctimeMs: 1561174614583.8145,
|
|
862
|
+
* birthtimeMs: 1561174007710.7478,
|
|
863
|
+
* atime: 2019-06-22T03:36:56.619Z,
|
|
864
|
+
* mtime: 2019-06-22T03:36:54.584Z,
|
|
865
|
+
* ctime: 2019-06-22T03:36:54.584Z,
|
|
866
|
+
* birthtime: 2019-06-22T03:26:47.711Z
|
|
867
|
+
* }
|
|
868
|
+
* ```
|
|
869
|
+
* @since v0.0.2
|
|
539
870
|
*/
|
|
540
871
|
export function stat(path: PathLike, callback: (err: NodeJS.ErrnoException | null, stats: Stats) => void): void;
|
|
541
|
-
export function stat(
|
|
542
|
-
|
|
872
|
+
export function stat(
|
|
873
|
+
path: PathLike,
|
|
874
|
+
options:
|
|
875
|
+
| (StatOptions & {
|
|
876
|
+
bigint?: false | undefined;
|
|
877
|
+
})
|
|
878
|
+
| undefined,
|
|
879
|
+
callback: (err: NodeJS.ErrnoException | null, stats: Stats) => void
|
|
880
|
+
): void;
|
|
881
|
+
export function stat(
|
|
882
|
+
path: PathLike,
|
|
883
|
+
options: StatOptions & {
|
|
884
|
+
bigint: true;
|
|
885
|
+
},
|
|
886
|
+
callback: (err: NodeJS.ErrnoException | null, stats: BigIntStats) => void
|
|
887
|
+
): void;
|
|
543
888
|
export function stat(path: PathLike, options: StatOptions | undefined, callback: (err: NodeJS.ErrnoException | null, stats: Stats | BigIntStats) => void): void;
|
|
544
|
-
|
|
545
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
546
889
|
export namespace stat {
|
|
547
890
|
/**
|
|
548
891
|
* Asynchronous stat(2) - Get file status.
|
|
549
892
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
550
893
|
*/
|
|
551
|
-
function __promisify__(
|
|
552
|
-
|
|
894
|
+
function __promisify__(
|
|
895
|
+
path: PathLike,
|
|
896
|
+
options?: StatOptions & {
|
|
897
|
+
bigint?: false | undefined;
|
|
898
|
+
}
|
|
899
|
+
): Promise<Stats>;
|
|
900
|
+
function __promisify__(
|
|
901
|
+
path: PathLike,
|
|
902
|
+
options: StatOptions & {
|
|
903
|
+
bigint: true;
|
|
904
|
+
}
|
|
905
|
+
): Promise<BigIntStats>;
|
|
553
906
|
function __promisify__(path: PathLike, options?: StatOptions): Promise<Stats | BigIntStats>;
|
|
554
907
|
}
|
|
555
|
-
|
|
556
908
|
export interface StatSyncFn<TDescriptor = PathLike> extends Function {
|
|
557
909
|
(path: TDescriptor, options?: undefined): Stats;
|
|
558
|
-
(
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
910
|
+
(
|
|
911
|
+
path: TDescriptor,
|
|
912
|
+
options?: StatOptions & {
|
|
913
|
+
bigint?: false | undefined;
|
|
914
|
+
throwIfNoEntry: false;
|
|
915
|
+
}
|
|
916
|
+
): Stats | undefined;
|
|
917
|
+
(
|
|
918
|
+
path: TDescriptor,
|
|
919
|
+
options: StatOptions & {
|
|
920
|
+
bigint: true;
|
|
921
|
+
throwIfNoEntry: false;
|
|
922
|
+
}
|
|
923
|
+
): BigIntStats | undefined;
|
|
924
|
+
(
|
|
925
|
+
path: TDescriptor,
|
|
926
|
+
options?: StatOptions & {
|
|
927
|
+
bigint?: false | undefined;
|
|
928
|
+
}
|
|
929
|
+
): Stats;
|
|
930
|
+
(
|
|
931
|
+
path: TDescriptor,
|
|
932
|
+
options: StatOptions & {
|
|
933
|
+
bigint: true;
|
|
934
|
+
}
|
|
935
|
+
): BigIntStats;
|
|
936
|
+
(
|
|
937
|
+
path: TDescriptor,
|
|
938
|
+
options: StatOptions & {
|
|
939
|
+
bigint: boolean;
|
|
940
|
+
throwIfNoEntry?: false | undefined;
|
|
941
|
+
}
|
|
942
|
+
): Stats | BigIntStats;
|
|
563
943
|
(path: TDescriptor, options?: StatOptions): Stats | BigIntStats | undefined;
|
|
564
944
|
}
|
|
565
|
-
|
|
566
945
|
/**
|
|
567
946
|
* Synchronous stat(2) - Get file status.
|
|
568
947
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
569
948
|
*/
|
|
570
949
|
export const statSync: StatSyncFn;
|
|
571
|
-
|
|
572
950
|
/**
|
|
573
|
-
*
|
|
574
|
-
*
|
|
951
|
+
* Invokes the callback with the `<fs.Stats>` for the file descriptor.
|
|
952
|
+
*
|
|
953
|
+
* See the POSIX [`fstat(2)`](http://man7.org/linux/man-pages/man2/fstat.2.html) documentation for more detail.
|
|
954
|
+
* @since v0.1.95
|
|
575
955
|
*/
|
|
576
956
|
export function fstat(fd: number, callback: (err: NodeJS.ErrnoException | null, stats: Stats) => void): void;
|
|
577
|
-
export function fstat(
|
|
578
|
-
|
|
957
|
+
export function fstat(
|
|
958
|
+
fd: number,
|
|
959
|
+
options:
|
|
960
|
+
| (StatOptions & {
|
|
961
|
+
bigint?: false | undefined;
|
|
962
|
+
})
|
|
963
|
+
| undefined,
|
|
964
|
+
callback: (err: NodeJS.ErrnoException | null, stats: Stats) => void
|
|
965
|
+
): void;
|
|
966
|
+
export function fstat(
|
|
967
|
+
fd: number,
|
|
968
|
+
options: StatOptions & {
|
|
969
|
+
bigint: true;
|
|
970
|
+
},
|
|
971
|
+
callback: (err: NodeJS.ErrnoException | null, stats: BigIntStats) => void
|
|
972
|
+
): void;
|
|
579
973
|
export function fstat(fd: number, options: StatOptions | undefined, callback: (err: NodeJS.ErrnoException | null, stats: Stats | BigIntStats) => void): void;
|
|
580
|
-
|
|
581
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
582
974
|
export namespace fstat {
|
|
583
975
|
/**
|
|
584
976
|
* Asynchronous fstat(2) - Get file status.
|
|
585
977
|
* @param fd A file descriptor.
|
|
586
978
|
*/
|
|
587
|
-
function __promisify__(
|
|
588
|
-
|
|
979
|
+
function __promisify__(
|
|
980
|
+
fd: number,
|
|
981
|
+
options?: StatOptions & {
|
|
982
|
+
bigint?: false | undefined;
|
|
983
|
+
}
|
|
984
|
+
): Promise<Stats>;
|
|
985
|
+
function __promisify__(
|
|
986
|
+
fd: number,
|
|
987
|
+
options: StatOptions & {
|
|
988
|
+
bigint: true;
|
|
989
|
+
}
|
|
990
|
+
): Promise<BigIntStats>;
|
|
589
991
|
function __promisify__(fd: number, options?: StatOptions): Promise<Stats | BigIntStats>;
|
|
590
992
|
}
|
|
591
|
-
|
|
592
993
|
/**
|
|
593
994
|
* Synchronous fstat(2) - Get file status.
|
|
594
995
|
* @param fd A file descriptor.
|
|
595
996
|
*/
|
|
596
997
|
export const fstatSync: StatSyncFn<number>;
|
|
597
|
-
|
|
598
998
|
/**
|
|
599
|
-
*
|
|
600
|
-
*
|
|
999
|
+
* Retrieves the `<fs.Stats>` for the symbolic link referred to by the path.
|
|
1000
|
+
* The callback gets two arguments `(err, stats)` where `stats` is a `<fs.Stats>` object. `lstat()` is identical to `stat()`, except that if `path` is a symbolic
|
|
1001
|
+
* link, then the link itself is stat-ed, not the file that it refers to.
|
|
1002
|
+
*
|
|
1003
|
+
* See the POSIX [`lstat(2)`](http://man7.org/linux/man-pages/man2/lstat.2.html) documentation for more details.
|
|
1004
|
+
* @since v0.1.30
|
|
601
1005
|
*/
|
|
602
1006
|
export function lstat(path: PathLike, callback: (err: NodeJS.ErrnoException | null, stats: Stats) => void): void;
|
|
603
|
-
export function lstat(
|
|
604
|
-
|
|
1007
|
+
export function lstat(
|
|
1008
|
+
path: PathLike,
|
|
1009
|
+
options:
|
|
1010
|
+
| (StatOptions & {
|
|
1011
|
+
bigint?: false | undefined;
|
|
1012
|
+
})
|
|
1013
|
+
| undefined,
|
|
1014
|
+
callback: (err: NodeJS.ErrnoException | null, stats: Stats) => void
|
|
1015
|
+
): void;
|
|
1016
|
+
export function lstat(
|
|
1017
|
+
path: PathLike,
|
|
1018
|
+
options: StatOptions & {
|
|
1019
|
+
bigint: true;
|
|
1020
|
+
},
|
|
1021
|
+
callback: (err: NodeJS.ErrnoException | null, stats: BigIntStats) => void
|
|
1022
|
+
): void;
|
|
605
1023
|
export function lstat(path: PathLike, options: StatOptions | undefined, callback: (err: NodeJS.ErrnoException | null, stats: Stats | BigIntStats) => void): void;
|
|
606
|
-
|
|
607
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
608
1024
|
export namespace lstat {
|
|
609
1025
|
/**
|
|
610
1026
|
* Asynchronous lstat(2) - Get file status. Does not dereference symbolic links.
|
|
611
1027
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
612
1028
|
*/
|
|
613
|
-
function __promisify__(
|
|
614
|
-
|
|
1029
|
+
function __promisify__(
|
|
1030
|
+
path: PathLike,
|
|
1031
|
+
options?: StatOptions & {
|
|
1032
|
+
bigint?: false | undefined;
|
|
1033
|
+
}
|
|
1034
|
+
): Promise<Stats>;
|
|
1035
|
+
function __promisify__(
|
|
1036
|
+
path: PathLike,
|
|
1037
|
+
options: StatOptions & {
|
|
1038
|
+
bigint: true;
|
|
1039
|
+
}
|
|
1040
|
+
): Promise<BigIntStats>;
|
|
615
1041
|
function __promisify__(path: PathLike, options?: StatOptions): Promise<Stats | BigIntStats>;
|
|
616
1042
|
}
|
|
617
|
-
|
|
618
1043
|
/**
|
|
619
1044
|
* Synchronous lstat(2) - Get file status. Does not dereference symbolic links.
|
|
620
1045
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
621
1046
|
*/
|
|
622
1047
|
export const lstatSync: StatSyncFn;
|
|
623
1048
|
/**
|
|
624
|
-
*
|
|
625
|
-
*
|
|
626
|
-
*
|
|
1049
|
+
* Creates a new link from the `existingPath` to the `newPath`. See the POSIX[`link(2)`](http://man7.org/linux/man-pages/man2/link.2.html) documentation for more detail. No arguments other than a
|
|
1050
|
+
* possible
|
|
1051
|
+
* exception are given to the completion callback.
|
|
1052
|
+
* @since v0.1.31
|
|
627
1053
|
*/
|
|
628
1054
|
export function link(existingPath: PathLike, newPath: PathLike, callback: NoParamCallback): void;
|
|
629
|
-
|
|
630
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
631
1055
|
export namespace link {
|
|
632
1056
|
/**
|
|
633
1057
|
* Asynchronous link(2) - Create a new link (also known as a hard link) to an existing file.
|
|
@@ -636,31 +1060,49 @@ declare module 'fs' {
|
|
|
636
1060
|
*/
|
|
637
1061
|
function __promisify__(existingPath: PathLike, newPath: PathLike): Promise<void>;
|
|
638
1062
|
}
|
|
639
|
-
|
|
640
1063
|
/**
|
|
641
|
-
*
|
|
642
|
-
* @
|
|
643
|
-
* @param newPath A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
1064
|
+
* Creates a new link from the `existingPath` to the `newPath`. See the POSIX[`link(2)`](http://man7.org/linux/man-pages/man2/link.2.html) documentation for more detail. Returns `undefined`.
|
|
1065
|
+
* @since v0.1.31
|
|
644
1066
|
*/
|
|
645
1067
|
export function linkSync(existingPath: PathLike, newPath: PathLike): void;
|
|
646
|
-
|
|
647
1068
|
/**
|
|
648
|
-
*
|
|
649
|
-
*
|
|
650
|
-
*
|
|
651
|
-
*
|
|
652
|
-
*
|
|
1069
|
+
* Creates the link called `path` pointing to `target`. No arguments other than a
|
|
1070
|
+
* possible exception are given to the completion callback.
|
|
1071
|
+
*
|
|
1072
|
+
* See the POSIX [`symlink(2)`](http://man7.org/linux/man-pages/man2/symlink.2.html) documentation for more details.
|
|
1073
|
+
*
|
|
1074
|
+
* The `type` argument is only available on Windows and ignored on other platforms.
|
|
1075
|
+
* It can be set to `'dir'`, `'file'`, or `'junction'`. If the `type` argument is
|
|
1076
|
+
* not set, Node.js will autodetect `target` type and use `'file'` or `'dir'`. If
|
|
1077
|
+
* the `target` does not exist, `'file'` will be used. Windows junction points
|
|
1078
|
+
* require the destination path to be absolute. When using `'junction'`, the`target` argument will automatically be normalized to absolute path.
|
|
1079
|
+
*
|
|
1080
|
+
* Relative targets are relative to the link’s parent directory.
|
|
1081
|
+
*
|
|
1082
|
+
* ```js
|
|
1083
|
+
* import { symlink } from 'fs';
|
|
1084
|
+
*
|
|
1085
|
+
* symlink('./mew', './example/mewtwo', callback);
|
|
1086
|
+
* ```
|
|
1087
|
+
*
|
|
1088
|
+
* The above example creates a symbolic link `mewtwo` in the `example` which points
|
|
1089
|
+
* to `mew` in the same directory:
|
|
1090
|
+
*
|
|
1091
|
+
* ```bash
|
|
1092
|
+
* $ tree example/
|
|
1093
|
+
* example/
|
|
1094
|
+
* ├── mew
|
|
1095
|
+
* └── mewtwo -> ./mew
|
|
1096
|
+
* ```
|
|
1097
|
+
* @since v0.1.31
|
|
653
1098
|
*/
|
|
654
1099
|
export function symlink(target: PathLike, path: PathLike, type: symlink.Type | undefined | null, callback: NoParamCallback): void;
|
|
655
|
-
|
|
656
1100
|
/**
|
|
657
1101
|
* Asynchronous symlink(2) - Create a new symbolic link to an existing file.
|
|
658
1102
|
* @param target A path to an existing file. If a URL is provided, it must use the `file:` protocol.
|
|
659
1103
|
* @param path A path to the new symlink. If a URL is provided, it must use the `file:` protocol.
|
|
660
1104
|
*/
|
|
661
1105
|
export function symlink(target: PathLike, path: PathLike, callback: NoParamCallback): void;
|
|
662
|
-
|
|
663
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
664
1106
|
export namespace symlink {
|
|
665
1107
|
/**
|
|
666
1108
|
* Asynchronous symlink(2) - Create a new symbolic link to an existing file.
|
|
@@ -670,51 +1112,46 @@ declare module 'fs' {
|
|
|
670
1112
|
* When using `'junction'`, the `target` argument will automatically be normalized to an absolute path.
|
|
671
1113
|
*/
|
|
672
1114
|
function __promisify__(target: PathLike, path: PathLike, type?: string | null): Promise<void>;
|
|
673
|
-
|
|
674
|
-
type Type = "dir" | "file" | "junction";
|
|
1115
|
+
type Type = 'dir' | 'file' | 'junction';
|
|
675
1116
|
}
|
|
676
|
-
|
|
677
1117
|
/**
|
|
678
|
-
*
|
|
679
|
-
*
|
|
680
|
-
*
|
|
681
|
-
*
|
|
682
|
-
*
|
|
1118
|
+
* Returns `undefined`.
|
|
1119
|
+
*
|
|
1120
|
+
* For detailed information, see the documentation of the asynchronous version of
|
|
1121
|
+
* this API: {@link symlink}.
|
|
1122
|
+
* @since v0.1.31
|
|
683
1123
|
*/
|
|
684
1124
|
export function symlinkSync(target: PathLike, path: PathLike, type?: symlink.Type | null): void;
|
|
685
|
-
|
|
686
1125
|
/**
|
|
687
|
-
*
|
|
688
|
-
*
|
|
689
|
-
*
|
|
1126
|
+
* Reads the contents of the symbolic link referred to by `path`. The callback gets
|
|
1127
|
+
* two arguments `(err, linkString)`.
|
|
1128
|
+
*
|
|
1129
|
+
* See the POSIX [`readlink(2)`](http://man7.org/linux/man-pages/man2/readlink.2.html) documentation for more details.
|
|
1130
|
+
*
|
|
1131
|
+
* The optional `options` argument can be a string specifying an encoding, or an
|
|
1132
|
+
* object with an `encoding` property specifying the character encoding to use for
|
|
1133
|
+
* the link path passed to the callback. If the `encoding` is set to `'buffer'`,
|
|
1134
|
+
* the link path returned will be passed as a `<Buffer>` object.
|
|
1135
|
+
* @since v0.1.31
|
|
690
1136
|
*/
|
|
691
|
-
export function readlink(
|
|
692
|
-
path: PathLike,
|
|
693
|
-
options: EncodingOption,
|
|
694
|
-
callback: (err: NodeJS.ErrnoException | null, linkString: string) => void
|
|
695
|
-
): void;
|
|
696
|
-
|
|
1137
|
+
export function readlink(path: PathLike, options: EncodingOption, callback: (err: NodeJS.ErrnoException | null, linkString: string) => void): void;
|
|
697
1138
|
/**
|
|
698
1139
|
* Asynchronous readlink(2) - read value of a symbolic link.
|
|
699
1140
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
700
1141
|
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
|
701
1142
|
*/
|
|
702
1143
|
export function readlink(path: PathLike, options: BufferEncodingOption, callback: (err: NodeJS.ErrnoException | null, linkString: Buffer) => void): void;
|
|
703
|
-
|
|
704
1144
|
/**
|
|
705
1145
|
* Asynchronous readlink(2) - read value of a symbolic link.
|
|
706
1146
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
707
1147
|
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
|
708
1148
|
*/
|
|
709
1149
|
export function readlink(path: PathLike, options: EncodingOption, callback: (err: NodeJS.ErrnoException | null, linkString: string | Buffer) => void): void;
|
|
710
|
-
|
|
711
1150
|
/**
|
|
712
1151
|
* Asynchronous readlink(2) - read value of a symbolic link.
|
|
713
1152
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
714
1153
|
*/
|
|
715
1154
|
export function readlink(path: PathLike, callback: (err: NodeJS.ErrnoException | null, linkString: string) => void): void;
|
|
716
|
-
|
|
717
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
718
1155
|
export namespace readlink {
|
|
719
1156
|
/**
|
|
720
1157
|
* Asynchronous readlink(2) - read value of a symbolic link.
|
|
@@ -722,14 +1159,12 @@ declare module 'fs' {
|
|
|
722
1159
|
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
|
723
1160
|
*/
|
|
724
1161
|
function __promisify__(path: PathLike, options?: EncodingOption): Promise<string>;
|
|
725
|
-
|
|
726
1162
|
/**
|
|
727
1163
|
* Asynchronous readlink(2) - read value of a symbolic link.
|
|
728
1164
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
729
1165
|
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
|
730
1166
|
*/
|
|
731
1167
|
function __promisify__(path: PathLike, options: BufferEncodingOption): Promise<Buffer>;
|
|
732
|
-
|
|
733
1168
|
/**
|
|
734
1169
|
* Asynchronous readlink(2) - read value of a symbolic link.
|
|
735
1170
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
@@ -737,60 +1172,74 @@ declare module 'fs' {
|
|
|
737
1172
|
*/
|
|
738
1173
|
function __promisify__(path: PathLike, options?: EncodingOption): Promise<string | Buffer>;
|
|
739
1174
|
}
|
|
740
|
-
|
|
741
1175
|
/**
|
|
742
|
-
*
|
|
743
|
-
*
|
|
744
|
-
*
|
|
1176
|
+
* Returns the symbolic link's string value.
|
|
1177
|
+
*
|
|
1178
|
+
* See the POSIX [`readlink(2)`](http://man7.org/linux/man-pages/man2/readlink.2.html) documentation for more details.
|
|
1179
|
+
*
|
|
1180
|
+
* The optional `options` argument can be a string specifying an encoding, or an
|
|
1181
|
+
* object with an `encoding` property specifying the character encoding to use for
|
|
1182
|
+
* the link path returned. If the `encoding` is set to `'buffer'`,
|
|
1183
|
+
* the link path returned will be passed as a `<Buffer>` object.
|
|
1184
|
+
* @since v0.1.31
|
|
745
1185
|
*/
|
|
746
1186
|
export function readlinkSync(path: PathLike, options?: EncodingOption): string;
|
|
747
|
-
|
|
748
1187
|
/**
|
|
749
1188
|
* Synchronous readlink(2) - read value of a symbolic link.
|
|
750
1189
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
751
1190
|
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
|
752
1191
|
*/
|
|
753
1192
|
export function readlinkSync(path: PathLike, options: BufferEncodingOption): Buffer;
|
|
754
|
-
|
|
755
1193
|
/**
|
|
756
1194
|
* Synchronous readlink(2) - read value of a symbolic link.
|
|
757
1195
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
758
1196
|
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
|
759
1197
|
*/
|
|
760
1198
|
export function readlinkSync(path: PathLike, options?: EncodingOption): string | Buffer;
|
|
761
|
-
|
|
762
1199
|
/**
|
|
763
|
-
*
|
|
764
|
-
*
|
|
765
|
-
*
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
1200
|
+
* Asynchronously computes the canonical pathname by resolving `.`, `..` and
|
|
1201
|
+
* symbolic links.
|
|
1202
|
+
*
|
|
1203
|
+
* A canonical pathname is not necessarily unique. Hard links and bind mounts can
|
|
1204
|
+
* expose a file system entity through many pathnames.
|
|
1205
|
+
*
|
|
1206
|
+
* This function behaves like [`realpath(3)`](http://man7.org/linux/man-pages/man3/realpath.3.html), with some exceptions:
|
|
1207
|
+
*
|
|
1208
|
+
* 1. No case conversion is performed on case-insensitive file systems.
|
|
1209
|
+
* 2. The maximum number of symbolic links is platform-independent and generally
|
|
1210
|
+
* (much) higher than what the native [`realpath(3)`](http://man7.org/linux/man-pages/man3/realpath.3.html) implementation supports.
|
|
1211
|
+
*
|
|
1212
|
+
* The `callback` gets two arguments `(err, resolvedPath)`. May use `process.cwd`to resolve relative paths.
|
|
1213
|
+
*
|
|
1214
|
+
* Only paths that can be converted to UTF8 strings are supported.
|
|
1215
|
+
*
|
|
1216
|
+
* The optional `options` argument can be a string specifying an encoding, or an
|
|
1217
|
+
* object with an `encoding` property specifying the character encoding to use for
|
|
1218
|
+
* the path passed to the callback. If the `encoding` is set to `'buffer'`,
|
|
1219
|
+
* the path returned will be passed as a `<Buffer>` object.
|
|
1220
|
+
*
|
|
1221
|
+
* If `path` resolves to a socket or a pipe, the function will return a system
|
|
1222
|
+
* dependent name for that object.
|
|
1223
|
+
* @since v0.1.31
|
|
1224
|
+
*/
|
|
1225
|
+
export function realpath(path: PathLike, options: EncodingOption, callback: (err: NodeJS.ErrnoException | null, resolvedPath: string) => void): void;
|
|
773
1226
|
/**
|
|
774
1227
|
* Asynchronous realpath(3) - return the canonicalized absolute pathname.
|
|
775
1228
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
776
1229
|
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
|
777
1230
|
*/
|
|
778
1231
|
export function realpath(path: PathLike, options: BufferEncodingOption, callback: (err: NodeJS.ErrnoException | null, resolvedPath: Buffer) => void): void;
|
|
779
|
-
|
|
780
1232
|
/**
|
|
781
1233
|
* Asynchronous realpath(3) - return the canonicalized absolute pathname.
|
|
782
1234
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
783
1235
|
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
|
784
1236
|
*/
|
|
785
1237
|
export function realpath(path: PathLike, options: EncodingOption, callback: (err: NodeJS.ErrnoException | null, resolvedPath: string | Buffer) => void): void;
|
|
786
|
-
|
|
787
1238
|
/**
|
|
788
1239
|
* Asynchronous realpath(3) - return the canonicalized absolute pathname.
|
|
789
1240
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
790
1241
|
*/
|
|
791
1242
|
export function realpath(path: PathLike, callback: (err: NodeJS.ErrnoException | null, resolvedPath: string) => void): void;
|
|
792
|
-
|
|
793
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
794
1243
|
export namespace realpath {
|
|
795
1244
|
/**
|
|
796
1245
|
* Asynchronous realpath(3) - return the canonicalized absolute pathname.
|
|
@@ -798,65 +1247,85 @@ declare module 'fs' {
|
|
|
798
1247
|
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
|
799
1248
|
*/
|
|
800
1249
|
function __promisify__(path: PathLike, options?: EncodingOption): Promise<string>;
|
|
801
|
-
|
|
802
1250
|
/**
|
|
803
1251
|
* Asynchronous realpath(3) - return the canonicalized absolute pathname.
|
|
804
1252
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
805
1253
|
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
|
806
1254
|
*/
|
|
807
1255
|
function __promisify__(path: PathLike, options: BufferEncodingOption): Promise<Buffer>;
|
|
808
|
-
|
|
809
1256
|
/**
|
|
810
1257
|
* Asynchronous realpath(3) - return the canonicalized absolute pathname.
|
|
811
1258
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
812
1259
|
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
|
813
1260
|
*/
|
|
814
1261
|
function __promisify__(path: PathLike, options?: EncodingOption): Promise<string | Buffer>;
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
1262
|
+
/**
|
|
1263
|
+
* Asynchronous [`realpath(3)`](http://man7.org/linux/man-pages/man3/realpath.3.html).
|
|
1264
|
+
*
|
|
1265
|
+
* The `callback` gets two arguments `(err, resolvedPath)`.
|
|
1266
|
+
*
|
|
1267
|
+
* Only paths that can be converted to UTF8 strings are supported.
|
|
1268
|
+
*
|
|
1269
|
+
* The optional `options` argument can be a string specifying an encoding, or an
|
|
1270
|
+
* object with an `encoding` property specifying the character encoding to use for
|
|
1271
|
+
* the path passed to the callback. If the `encoding` is set to `'buffer'`,
|
|
1272
|
+
* the path returned will be passed as a `<Buffer>` object.
|
|
1273
|
+
*
|
|
1274
|
+
* On Linux, when Node.js is linked against musl libc, the procfs file system must
|
|
1275
|
+
* be mounted on `/proc` in order for this function to work. Glibc does not have
|
|
1276
|
+
* this restriction.
|
|
1277
|
+
* @since v9.2.0
|
|
1278
|
+
*/
|
|
1279
|
+
function native(path: PathLike, options: EncodingOption, callback: (err: NodeJS.ErrnoException | null, resolvedPath: string) => void): void;
|
|
821
1280
|
function native(path: PathLike, options: BufferEncodingOption, callback: (err: NodeJS.ErrnoException | null, resolvedPath: Buffer) => void): void;
|
|
822
1281
|
function native(path: PathLike, options: EncodingOption, callback: (err: NodeJS.ErrnoException | null, resolvedPath: string | Buffer) => void): void;
|
|
823
1282
|
function native(path: PathLike, callback: (err: NodeJS.ErrnoException | null, resolvedPath: string) => void): void;
|
|
824
1283
|
}
|
|
825
|
-
|
|
826
1284
|
/**
|
|
827
|
-
*
|
|
828
|
-
*
|
|
829
|
-
*
|
|
1285
|
+
* Returns the resolved pathname.
|
|
1286
|
+
*
|
|
1287
|
+
* For detailed information, see the documentation of the asynchronous version of
|
|
1288
|
+
* this API: {@link realpath}.
|
|
1289
|
+
* @since v0.1.31
|
|
830
1290
|
*/
|
|
831
1291
|
export function realpathSync(path: PathLike, options?: EncodingOption): string;
|
|
832
|
-
|
|
833
1292
|
/**
|
|
834
1293
|
* Synchronous realpath(3) - return the canonicalized absolute pathname.
|
|
835
1294
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
836
1295
|
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
|
837
1296
|
*/
|
|
838
1297
|
export function realpathSync(path: PathLike, options: BufferEncodingOption): Buffer;
|
|
839
|
-
|
|
840
1298
|
/**
|
|
841
1299
|
* Synchronous realpath(3) - return the canonicalized absolute pathname.
|
|
842
1300
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
843
1301
|
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
|
844
1302
|
*/
|
|
845
1303
|
export function realpathSync(path: PathLike, options?: EncodingOption): string | Buffer;
|
|
846
|
-
|
|
847
1304
|
export namespace realpathSync {
|
|
848
1305
|
function native(path: PathLike, options?: EncodingOption): string;
|
|
849
1306
|
function native(path: PathLike, options: BufferEncodingOption): Buffer;
|
|
850
1307
|
function native(path: PathLike, options?: EncodingOption): string | Buffer;
|
|
851
1308
|
}
|
|
852
|
-
|
|
853
1309
|
/**
|
|
854
|
-
*
|
|
855
|
-
*
|
|
1310
|
+
* Asynchronously removes a file or symbolic link. No arguments other than a
|
|
1311
|
+
* possible exception are given to the completion callback.
|
|
1312
|
+
*
|
|
1313
|
+
* ```js
|
|
1314
|
+
* import { unlink } from 'fs';
|
|
1315
|
+
* // Assuming that 'path/file.txt' is a regular file.
|
|
1316
|
+
* unlink('path/file.txt', (err) => {
|
|
1317
|
+
* if (err) throw err;
|
|
1318
|
+
* console.log('path/file.txt was deleted');
|
|
1319
|
+
* });
|
|
1320
|
+
* ```
|
|
1321
|
+
*
|
|
1322
|
+
* `fs.unlink()` will not work on a directory, empty or otherwise. To remove a
|
|
1323
|
+
* directory, use {@link rmdir}.
|
|
1324
|
+
*
|
|
1325
|
+
* See the POSIX [`unlink(2)`](http://man7.org/linux/man-pages/man2/unlink.2.html) documentation for more details.
|
|
1326
|
+
* @since v0.0.2
|
|
856
1327
|
*/
|
|
857
1328
|
export function unlink(path: PathLike, callback: NoParamCallback): void;
|
|
858
|
-
|
|
859
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
860
1329
|
export namespace unlink {
|
|
861
1330
|
/**
|
|
862
1331
|
* Asynchronous unlink(2) - delete a name and possibly the file it refers to.
|
|
@@ -864,13 +1333,11 @@ declare module 'fs' {
|
|
|
864
1333
|
*/
|
|
865
1334
|
function __promisify__(path: PathLike): Promise<void>;
|
|
866
1335
|
}
|
|
867
|
-
|
|
868
1336
|
/**
|
|
869
|
-
* Synchronous unlink(2)
|
|
870
|
-
* @
|
|
1337
|
+
* Synchronous [`unlink(2)`](http://man7.org/linux/man-pages/man2/unlink.2.html). Returns `undefined`.
|
|
1338
|
+
* @since v0.1.21
|
|
871
1339
|
*/
|
|
872
1340
|
export function unlinkSync(path: PathLike): void;
|
|
873
|
-
|
|
874
1341
|
export interface RmDirOptions {
|
|
875
1342
|
/**
|
|
876
1343
|
* If an `EBUSY`, `EMFILE`, `ENFILE`, `ENOTEMPTY`, or
|
|
@@ -898,15 +1365,18 @@ declare module 'fs' {
|
|
|
898
1365
|
*/
|
|
899
1366
|
retryDelay?: number | undefined;
|
|
900
1367
|
}
|
|
901
|
-
|
|
902
1368
|
/**
|
|
903
|
-
* Asynchronous rmdir(2)
|
|
904
|
-
*
|
|
1369
|
+
* Asynchronous [`rmdir(2)`](http://man7.org/linux/man-pages/man2/rmdir.2.html). No arguments other than a possible exception are given
|
|
1370
|
+
* to the completion callback.
|
|
1371
|
+
*
|
|
1372
|
+
* Using `fs.rmdir()` on a file (not a directory) results in an `ENOENT` error on
|
|
1373
|
+
* Windows and an `ENOTDIR` error on POSIX.
|
|
1374
|
+
*
|
|
1375
|
+
* To get a behavior similar to the `rm -rf` Unix command, use {@link rm} with options `{ recursive: true, force: true }`.
|
|
1376
|
+
* @since v0.0.2
|
|
905
1377
|
*/
|
|
906
1378
|
export function rmdir(path: PathLike, callback: NoParamCallback): void;
|
|
907
1379
|
export function rmdir(path: PathLike, options: RmDirOptions, callback: NoParamCallback): void;
|
|
908
|
-
|
|
909
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
910
1380
|
export namespace rmdir {
|
|
911
1381
|
/**
|
|
912
1382
|
* Asynchronous rmdir(2) - delete a directory.
|
|
@@ -914,13 +1384,16 @@ declare module 'fs' {
|
|
|
914
1384
|
*/
|
|
915
1385
|
function __promisify__(path: PathLike, options?: RmDirOptions): Promise<void>;
|
|
916
1386
|
}
|
|
917
|
-
|
|
918
1387
|
/**
|
|
919
|
-
* Synchronous rmdir(2)
|
|
920
|
-
*
|
|
1388
|
+
* Synchronous [`rmdir(2)`](http://man7.org/linux/man-pages/man2/rmdir.2.html). Returns `undefined`.
|
|
1389
|
+
*
|
|
1390
|
+
* Using `fs.rmdirSync()` on a file (not a directory) results in an `ENOENT` error
|
|
1391
|
+
* on Windows and an `ENOTDIR` error on POSIX.
|
|
1392
|
+
*
|
|
1393
|
+
* To get a behavior similar to the `rm -rf` Unix command, use {@link rmSync} with options `{ recursive: true, force: true }`.
|
|
1394
|
+
* @since v0.1.21
|
|
921
1395
|
*/
|
|
922
1396
|
export function rmdirSync(path: PathLike, options?: RmDirOptions): void;
|
|
923
|
-
|
|
924
1397
|
export interface RmOptions {
|
|
925
1398
|
/**
|
|
926
1399
|
* When `true`, exceptions will be ignored if `path` does not exist.
|
|
@@ -949,26 +1422,24 @@ declare module 'fs' {
|
|
|
949
1422
|
*/
|
|
950
1423
|
retryDelay?: number | undefined;
|
|
951
1424
|
}
|
|
952
|
-
|
|
953
1425
|
/**
|
|
954
|
-
* Asynchronously removes files and directories (modeled on the standard POSIX `rm`
|
|
1426
|
+
* Asynchronously removes files and directories (modeled on the standard POSIX `rm`utility). No arguments other than a possible exception are given to the
|
|
1427
|
+
* completion callback.
|
|
1428
|
+
* @since v14.14.0
|
|
955
1429
|
*/
|
|
956
1430
|
export function rm(path: PathLike, callback: NoParamCallback): void;
|
|
957
1431
|
export function rm(path: PathLike, options: RmOptions, callback: NoParamCallback): void;
|
|
958
|
-
|
|
959
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
960
1432
|
export namespace rm {
|
|
961
1433
|
/**
|
|
962
1434
|
* Asynchronously removes files and directories (modeled on the standard POSIX `rm` utility).
|
|
963
1435
|
*/
|
|
964
1436
|
function __promisify__(path: PathLike, options?: RmOptions): Promise<void>;
|
|
965
1437
|
}
|
|
966
|
-
|
|
967
1438
|
/**
|
|
968
|
-
* Synchronously removes files and directories (modeled on the standard POSIX `rm`
|
|
1439
|
+
* Synchronously removes files and directories (modeled on the standard POSIX `rm`utility). Returns `undefined`.
|
|
1440
|
+
* @since v14.14.0
|
|
969
1441
|
*/
|
|
970
1442
|
export function rmSync(path: PathLike, options?: RmOptions): void;
|
|
971
|
-
|
|
972
1443
|
export interface MakeDirectoryOptions {
|
|
973
1444
|
/**
|
|
974
1445
|
* Indicates whether parent folders should be created.
|
|
@@ -982,23 +1453,65 @@ declare module 'fs' {
|
|
|
982
1453
|
*/
|
|
983
1454
|
mode?: Mode | undefined;
|
|
984
1455
|
}
|
|
985
|
-
|
|
986
1456
|
/**
|
|
987
|
-
*
|
|
988
|
-
*
|
|
989
|
-
*
|
|
990
|
-
*
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
1457
|
+
* Asynchronously creates a directory.
|
|
1458
|
+
*
|
|
1459
|
+
* The callback is given a possible exception and, if `recursive` is `true`, the
|
|
1460
|
+
* first directory path created, `(err, [path])`.`path` can still be `undefined` when `recursive` is `true`, if no directory was
|
|
1461
|
+
* created.
|
|
1462
|
+
*
|
|
1463
|
+
* The optional `options` argument can be an integer specifying `mode` (permission
|
|
1464
|
+
* and sticky bits), or an object with a `mode` property and a `recursive`property indicating whether parent directories should be created. Calling`fs.mkdir()` when `path` is a directory that
|
|
1465
|
+
* exists results in an error only
|
|
1466
|
+
* when `recursive` is false.
|
|
1467
|
+
*
|
|
1468
|
+
* ```js
|
|
1469
|
+
* import { mkdir } from 'fs';
|
|
1470
|
+
*
|
|
1471
|
+
* // Creates /tmp/a/apple, regardless of whether `/tmp` and /tmp/a exist.
|
|
1472
|
+
* mkdir('/tmp/a/apple', { recursive: true }, (err) => {
|
|
1473
|
+
* if (err) throw err;
|
|
1474
|
+
* });
|
|
1475
|
+
* ```
|
|
1476
|
+
*
|
|
1477
|
+
* On Windows, using `fs.mkdir()` on the root directory even with recursion will
|
|
1478
|
+
* result in an error:
|
|
1479
|
+
*
|
|
1480
|
+
* ```js
|
|
1481
|
+
* import { mkdir } from 'fs';
|
|
1482
|
+
*
|
|
1483
|
+
* mkdir('/', { recursive: true }, (err) => {
|
|
1484
|
+
* // => [Error: EPERM: operation not permitted, mkdir 'C:\']
|
|
1485
|
+
* });
|
|
1486
|
+
* ```
|
|
1487
|
+
*
|
|
1488
|
+
* See the POSIX [`mkdir(2)`](http://man7.org/linux/man-pages/man2/mkdir.2.html) documentation for more details.
|
|
1489
|
+
* @since v0.1.8
|
|
1490
|
+
*/
|
|
1491
|
+
export function mkdir(
|
|
1492
|
+
path: PathLike,
|
|
1493
|
+
options: MakeDirectoryOptions & {
|
|
1494
|
+
recursive: true;
|
|
1495
|
+
},
|
|
1496
|
+
callback: (err: NodeJS.ErrnoException | null, path?: string) => void
|
|
1497
|
+
): void;
|
|
994
1498
|
/**
|
|
995
1499
|
* Asynchronous mkdir(2) - create a directory.
|
|
996
1500
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
997
1501
|
* @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
|
|
998
1502
|
* should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
|
|
999
1503
|
*/
|
|
1000
|
-
export function mkdir(
|
|
1001
|
-
|
|
1504
|
+
export function mkdir(
|
|
1505
|
+
path: PathLike,
|
|
1506
|
+
options:
|
|
1507
|
+
| Mode
|
|
1508
|
+
| (MakeDirectoryOptions & {
|
|
1509
|
+
recursive?: false | undefined;
|
|
1510
|
+
})
|
|
1511
|
+
| null
|
|
1512
|
+
| undefined,
|
|
1513
|
+
callback: NoParamCallback
|
|
1514
|
+
): void;
|
|
1002
1515
|
/**
|
|
1003
1516
|
* Asynchronous mkdir(2) - create a directory.
|
|
1004
1517
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
@@ -1006,14 +1519,11 @@ declare module 'fs' {
|
|
|
1006
1519
|
* should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
|
|
1007
1520
|
*/
|
|
1008
1521
|
export function mkdir(path: PathLike, options: Mode | MakeDirectoryOptions | null | undefined, callback: (err: NodeJS.ErrnoException | null, path?: string) => void): void;
|
|
1009
|
-
|
|
1010
1522
|
/**
|
|
1011
1523
|
* Asynchronous mkdir(2) - create a directory with a mode of `0o777`.
|
|
1012
1524
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
1013
1525
|
*/
|
|
1014
1526
|
export function mkdir(path: PathLike, callback: NoParamCallback): void;
|
|
1015
|
-
|
|
1016
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
1017
1527
|
export namespace mkdir {
|
|
1018
1528
|
/**
|
|
1019
1529
|
* Asynchronous mkdir(2) - create a directory.
|
|
@@ -1021,16 +1531,27 @@ declare module 'fs' {
|
|
|
1021
1531
|
* @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
|
|
1022
1532
|
* should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
|
|
1023
1533
|
*/
|
|
1024
|
-
function __promisify__(
|
|
1025
|
-
|
|
1534
|
+
function __promisify__(
|
|
1535
|
+
path: PathLike,
|
|
1536
|
+
options: MakeDirectoryOptions & {
|
|
1537
|
+
recursive: true;
|
|
1538
|
+
}
|
|
1539
|
+
): Promise<string | undefined>;
|
|
1026
1540
|
/**
|
|
1027
1541
|
* Asynchronous mkdir(2) - create a directory.
|
|
1028
1542
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
1029
1543
|
* @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
|
|
1030
1544
|
* should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
|
|
1031
1545
|
*/
|
|
1032
|
-
function __promisify__(
|
|
1033
|
-
|
|
1546
|
+
function __promisify__(
|
|
1547
|
+
path: PathLike,
|
|
1548
|
+
options?:
|
|
1549
|
+
| Mode
|
|
1550
|
+
| (MakeDirectoryOptions & {
|
|
1551
|
+
recursive?: false | undefined;
|
|
1552
|
+
})
|
|
1553
|
+
| null
|
|
1554
|
+
): Promise<void>;
|
|
1034
1555
|
/**
|
|
1035
1556
|
* Asynchronous mkdir(2) - create a directory.
|
|
1036
1557
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
@@ -1039,23 +1560,34 @@ declare module 'fs' {
|
|
|
1039
1560
|
*/
|
|
1040
1561
|
function __promisify__(path: PathLike, options?: Mode | MakeDirectoryOptions | null): Promise<string | undefined>;
|
|
1041
1562
|
}
|
|
1042
|
-
|
|
1043
1563
|
/**
|
|
1044
|
-
*
|
|
1045
|
-
*
|
|
1046
|
-
*
|
|
1047
|
-
*
|
|
1564
|
+
* Synchronously creates a directory. Returns `undefined`, or if `recursive` is`true`, the first directory path created.
|
|
1565
|
+
* This is the synchronous version of {@link mkdir}.
|
|
1566
|
+
*
|
|
1567
|
+
* See the POSIX [`mkdir(2)`](http://man7.org/linux/man-pages/man2/mkdir.2.html) documentation for more details.
|
|
1568
|
+
* @since v0.1.21
|
|
1048
1569
|
*/
|
|
1049
|
-
export function mkdirSync(
|
|
1050
|
-
|
|
1570
|
+
export function mkdirSync(
|
|
1571
|
+
path: PathLike,
|
|
1572
|
+
options: MakeDirectoryOptions & {
|
|
1573
|
+
recursive: true;
|
|
1574
|
+
}
|
|
1575
|
+
): string | undefined;
|
|
1051
1576
|
/**
|
|
1052
1577
|
* Synchronous mkdir(2) - create a directory.
|
|
1053
1578
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
1054
1579
|
* @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
|
|
1055
1580
|
* should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
|
|
1056
1581
|
*/
|
|
1057
|
-
export function mkdirSync(
|
|
1058
|
-
|
|
1582
|
+
export function mkdirSync(
|
|
1583
|
+
path: PathLike,
|
|
1584
|
+
options?:
|
|
1585
|
+
| Mode
|
|
1586
|
+
| (MakeDirectoryOptions & {
|
|
1587
|
+
recursive?: false | undefined;
|
|
1588
|
+
})
|
|
1589
|
+
| null
|
|
1590
|
+
): void;
|
|
1059
1591
|
/**
|
|
1060
1592
|
* Synchronous mkdir(2) - create a directory.
|
|
1061
1593
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
@@ -1063,35 +1595,89 @@ declare module 'fs' {
|
|
|
1063
1595
|
* should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
|
|
1064
1596
|
*/
|
|
1065
1597
|
export function mkdirSync(path: PathLike, options?: Mode | MakeDirectoryOptions | null): string | undefined;
|
|
1066
|
-
|
|
1067
1598
|
/**
|
|
1068
|
-
*
|
|
1069
|
-
*
|
|
1070
|
-
*
|
|
1599
|
+
* Creates a unique temporary directory.
|
|
1600
|
+
*
|
|
1601
|
+
* Generates six random characters to be appended behind a required`prefix` to create a unique temporary directory. Due to platform
|
|
1602
|
+
* inconsistencies, avoid trailing `X` characters in `prefix`. Some platforms,
|
|
1603
|
+
* notably the BSDs, can return more than six random characters, and replace
|
|
1604
|
+
* trailing `X` characters in `prefix` with random characters.
|
|
1605
|
+
*
|
|
1606
|
+
* The created directory path is passed as a string to the callback's second
|
|
1607
|
+
* parameter.
|
|
1608
|
+
*
|
|
1609
|
+
* The optional `options` argument can be a string specifying an encoding, or an
|
|
1610
|
+
* object with an `encoding` property specifying the character encoding to use.
|
|
1611
|
+
*
|
|
1612
|
+
* ```js
|
|
1613
|
+
* import { mkdtemp } from 'fs';
|
|
1614
|
+
*
|
|
1615
|
+
* mkdtemp(path.join(os.tmpdir(), 'foo-'), (err, directory) => {
|
|
1616
|
+
* if (err) throw err;
|
|
1617
|
+
* console.log(directory);
|
|
1618
|
+
* // Prints: /tmp/foo-itXde2 or C:\Users\...\AppData\Local\Temp\foo-itXde2
|
|
1619
|
+
* });
|
|
1620
|
+
* ```
|
|
1621
|
+
*
|
|
1622
|
+
* The `fs.mkdtemp()` method will append the six randomly selected characters
|
|
1623
|
+
* directly to the `prefix` string. For instance, given a directory `/tmp`, if the
|
|
1624
|
+
* intention is to create a temporary directory _within_`/tmp`, the `prefix`must end with a trailing platform-specific path separator
|
|
1625
|
+
* (`require('path').sep`).
|
|
1626
|
+
*
|
|
1627
|
+
* ```js
|
|
1628
|
+
* import { tmpdir } from 'os';
|
|
1629
|
+
* import { mkdtemp } from 'fs';
|
|
1630
|
+
*
|
|
1631
|
+
* // The parent directory for the new temporary directory
|
|
1632
|
+
* const tmpDir = tmpdir();
|
|
1633
|
+
*
|
|
1634
|
+
* // This method is *INCORRECT*:
|
|
1635
|
+
* mkdtemp(tmpDir, (err, directory) => {
|
|
1636
|
+
* if (err) throw err;
|
|
1637
|
+
* console.log(directory);
|
|
1638
|
+
* // Will print something similar to `/tmpabc123`.
|
|
1639
|
+
* // A new temporary directory is created at the file system root
|
|
1640
|
+
* // rather than *within* the /tmp directory.
|
|
1641
|
+
* });
|
|
1642
|
+
*
|
|
1643
|
+
* // This method is *CORRECT*:
|
|
1644
|
+
* import { sep } from 'path';
|
|
1645
|
+
* mkdtemp(`${tmpDir}${sep}`, (err, directory) => {
|
|
1646
|
+
* if (err) throw err;
|
|
1647
|
+
* console.log(directory);
|
|
1648
|
+
* // Will print something similar to `/tmp/abc123`.
|
|
1649
|
+
* // A new temporary directory is created within
|
|
1650
|
+
* // the /tmp directory.
|
|
1651
|
+
* });
|
|
1652
|
+
* ```
|
|
1653
|
+
* @since v5.10.0
|
|
1071
1654
|
*/
|
|
1072
1655
|
export function mkdtemp(prefix: string, options: EncodingOption, callback: (err: NodeJS.ErrnoException | null, folder: string) => void): void;
|
|
1073
|
-
|
|
1074
1656
|
/**
|
|
1075
1657
|
* Asynchronously creates a unique temporary directory.
|
|
1076
1658
|
* Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
|
|
1077
1659
|
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
|
1078
1660
|
*/
|
|
1079
|
-
export function mkdtemp(
|
|
1080
|
-
|
|
1661
|
+
export function mkdtemp(
|
|
1662
|
+
prefix: string,
|
|
1663
|
+
options:
|
|
1664
|
+
| 'buffer'
|
|
1665
|
+
| {
|
|
1666
|
+
encoding: 'buffer';
|
|
1667
|
+
},
|
|
1668
|
+
callback: (err: NodeJS.ErrnoException | null, folder: Buffer) => void
|
|
1669
|
+
): void;
|
|
1081
1670
|
/**
|
|
1082
1671
|
* Asynchronously creates a unique temporary directory.
|
|
1083
1672
|
* Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
|
|
1084
1673
|
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
|
1085
1674
|
*/
|
|
1086
1675
|
export function mkdtemp(prefix: string, options: EncodingOption, callback: (err: NodeJS.ErrnoException | null, folder: string | Buffer) => void): void;
|
|
1087
|
-
|
|
1088
1676
|
/**
|
|
1089
1677
|
* Asynchronously creates a unique temporary directory.
|
|
1090
1678
|
* Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
|
|
1091
1679
|
*/
|
|
1092
1680
|
export function mkdtemp(prefix: string, callback: (err: NodeJS.ErrnoException | null, folder: string) => void): void;
|
|
1093
|
-
|
|
1094
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
1095
1681
|
export namespace mkdtemp {
|
|
1096
1682
|
/**
|
|
1097
1683
|
* Asynchronously creates a unique temporary directory.
|
|
@@ -1099,14 +1685,12 @@ declare module 'fs' {
|
|
|
1099
1685
|
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
|
1100
1686
|
*/
|
|
1101
1687
|
function __promisify__(prefix: string, options?: EncodingOption): Promise<string>;
|
|
1102
|
-
|
|
1103
1688
|
/**
|
|
1104
1689
|
* Asynchronously creates a unique temporary directory.
|
|
1105
1690
|
* Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
|
|
1106
1691
|
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
|
1107
1692
|
*/
|
|
1108
1693
|
function __promisify__(prefix: string, options: BufferEncodingOption): Promise<Buffer>;
|
|
1109
|
-
|
|
1110
1694
|
/**
|
|
1111
1695
|
* Asynchronously creates a unique temporary directory.
|
|
1112
1696
|
* Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
|
|
@@ -1114,39 +1698,54 @@ declare module 'fs' {
|
|
|
1114
1698
|
*/
|
|
1115
1699
|
function __promisify__(prefix: string, options?: EncodingOption): Promise<string | Buffer>;
|
|
1116
1700
|
}
|
|
1117
|
-
|
|
1118
1701
|
/**
|
|
1119
|
-
*
|
|
1120
|
-
*
|
|
1121
|
-
*
|
|
1702
|
+
* Returns the created directory path.
|
|
1703
|
+
*
|
|
1704
|
+
* For detailed information, see the documentation of the asynchronous version of
|
|
1705
|
+
* this API: {@link mkdtemp}.
|
|
1706
|
+
*
|
|
1707
|
+
* The optional `options` argument can be a string specifying an encoding, or an
|
|
1708
|
+
* object with an `encoding` property specifying the character encoding to use.
|
|
1709
|
+
* @since v5.10.0
|
|
1122
1710
|
*/
|
|
1123
1711
|
export function mkdtempSync(prefix: string, options?: EncodingOption): string;
|
|
1124
|
-
|
|
1125
1712
|
/**
|
|
1126
1713
|
* Synchronously creates a unique temporary directory.
|
|
1127
1714
|
* Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
|
|
1128
1715
|
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
|
1129
1716
|
*/
|
|
1130
1717
|
export function mkdtempSync(prefix: string, options: BufferEncodingOption): Buffer;
|
|
1131
|
-
|
|
1132
1718
|
/**
|
|
1133
1719
|
* Synchronously creates a unique temporary directory.
|
|
1134
1720
|
* Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
|
|
1135
1721
|
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
|
1136
1722
|
*/
|
|
1137
1723
|
export function mkdtempSync(prefix: string, options?: EncodingOption): string | Buffer;
|
|
1138
|
-
|
|
1139
1724
|
/**
|
|
1140
|
-
*
|
|
1141
|
-
*
|
|
1142
|
-
*
|
|
1725
|
+
* Reads the contents of a directory. The callback gets two arguments `(err, files)`where `files` is an array of the names of the files in the directory excluding`'.'` and `'..'`.
|
|
1726
|
+
*
|
|
1727
|
+
* See the POSIX [`readdir(3)`](http://man7.org/linux/man-pages/man3/readdir.3.html) documentation for more details.
|
|
1728
|
+
*
|
|
1729
|
+
* The optional `options` argument can be a string specifying an encoding, or an
|
|
1730
|
+
* object with an `encoding` property specifying the character encoding to use for
|
|
1731
|
+
* the filenames passed to the callback. If the `encoding` is set to `'buffer'`,
|
|
1732
|
+
* the filenames returned will be passed as `<Buffer>` objects.
|
|
1733
|
+
*
|
|
1734
|
+
* If `options.withFileTypes` is set to `true`, the `files` array will contain `<fs.Dirent>` objects.
|
|
1735
|
+
* @since v0.1.8
|
|
1143
1736
|
*/
|
|
1144
1737
|
export function readdir(
|
|
1145
1738
|
path: PathLike,
|
|
1146
|
-
options:
|
|
1147
|
-
|
|
1739
|
+
options:
|
|
1740
|
+
| {
|
|
1741
|
+
encoding: BufferEncoding | null;
|
|
1742
|
+
withFileTypes?: false | undefined;
|
|
1743
|
+
}
|
|
1744
|
+
| BufferEncoding
|
|
1745
|
+
| undefined
|
|
1746
|
+
| null,
|
|
1747
|
+
callback: (err: NodeJS.ErrnoException | null, files: string[]) => void
|
|
1148
1748
|
): void;
|
|
1149
|
-
|
|
1150
1749
|
/**
|
|
1151
1750
|
* Asynchronous readdir(3) - read a directory.
|
|
1152
1751
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
@@ -1154,10 +1753,14 @@ declare module 'fs' {
|
|
|
1154
1753
|
*/
|
|
1155
1754
|
export function readdir(
|
|
1156
1755
|
path: PathLike,
|
|
1157
|
-
options:
|
|
1756
|
+
options:
|
|
1757
|
+
| {
|
|
1758
|
+
encoding: 'buffer';
|
|
1759
|
+
withFileTypes?: false | undefined;
|
|
1760
|
+
}
|
|
1761
|
+
| 'buffer',
|
|
1158
1762
|
callback: (err: NodeJS.ErrnoException | null, files: Buffer[]) => void
|
|
1159
1763
|
): void;
|
|
1160
|
-
|
|
1161
1764
|
/**
|
|
1162
1765
|
* Asynchronous readdir(3) - read a directory.
|
|
1163
1766
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
@@ -1165,89 +1768,161 @@ declare module 'fs' {
|
|
|
1165
1768
|
*/
|
|
1166
1769
|
export function readdir(
|
|
1167
1770
|
path: PathLike,
|
|
1168
|
-
options:
|
|
1169
|
-
|
|
1771
|
+
options:
|
|
1772
|
+
| (ObjectEncodingOptions & {
|
|
1773
|
+
withFileTypes?: false | undefined;
|
|
1774
|
+
})
|
|
1775
|
+
| BufferEncoding
|
|
1776
|
+
| undefined
|
|
1777
|
+
| null,
|
|
1778
|
+
callback: (err: NodeJS.ErrnoException | null, files: string[] | Buffer[]) => void
|
|
1170
1779
|
): void;
|
|
1171
|
-
|
|
1172
1780
|
/**
|
|
1173
1781
|
* Asynchronous readdir(3) - read a directory.
|
|
1174
1782
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
1175
1783
|
*/
|
|
1176
1784
|
export function readdir(path: PathLike, callback: (err: NodeJS.ErrnoException | null, files: string[]) => void): void;
|
|
1177
|
-
|
|
1178
1785
|
/**
|
|
1179
1786
|
* Asynchronous readdir(3) - read a directory.
|
|
1180
1787
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
1181
1788
|
* @param options If called with `withFileTypes: true` the result data will be an array of Dirent.
|
|
1182
1789
|
*/
|
|
1183
|
-
export function readdir(
|
|
1184
|
-
|
|
1185
|
-
|
|
1790
|
+
export function readdir(
|
|
1791
|
+
path: PathLike,
|
|
1792
|
+
options: ObjectEncodingOptions & {
|
|
1793
|
+
withFileTypes: true;
|
|
1794
|
+
},
|
|
1795
|
+
callback: (err: NodeJS.ErrnoException | null, files: Dirent[]) => void
|
|
1796
|
+
): void;
|
|
1186
1797
|
export namespace readdir {
|
|
1187
1798
|
/**
|
|
1188
1799
|
* Asynchronous readdir(3) - read a directory.
|
|
1189
1800
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
1190
1801
|
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
|
1191
1802
|
*/
|
|
1192
|
-
function __promisify__(
|
|
1193
|
-
|
|
1803
|
+
function __promisify__(
|
|
1804
|
+
path: PathLike,
|
|
1805
|
+
options?:
|
|
1806
|
+
| {
|
|
1807
|
+
encoding: BufferEncoding | null;
|
|
1808
|
+
withFileTypes?: false | undefined;
|
|
1809
|
+
}
|
|
1810
|
+
| BufferEncoding
|
|
1811
|
+
| null
|
|
1812
|
+
): Promise<string[]>;
|
|
1194
1813
|
/**
|
|
1195
1814
|
* Asynchronous readdir(3) - read a directory.
|
|
1196
1815
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
1197
1816
|
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
|
1198
1817
|
*/
|
|
1199
|
-
function __promisify__(
|
|
1200
|
-
|
|
1818
|
+
function __promisify__(
|
|
1819
|
+
path: PathLike,
|
|
1820
|
+
options:
|
|
1821
|
+
| 'buffer'
|
|
1822
|
+
| {
|
|
1823
|
+
encoding: 'buffer';
|
|
1824
|
+
withFileTypes?: false | undefined;
|
|
1825
|
+
}
|
|
1826
|
+
): Promise<Buffer[]>;
|
|
1201
1827
|
/**
|
|
1202
1828
|
* Asynchronous readdir(3) - read a directory.
|
|
1203
1829
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
1204
1830
|
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
|
1205
1831
|
*/
|
|
1206
|
-
function __promisify__(
|
|
1207
|
-
|
|
1832
|
+
function __promisify__(
|
|
1833
|
+
path: PathLike,
|
|
1834
|
+
options?:
|
|
1835
|
+
| (ObjectEncodingOptions & {
|
|
1836
|
+
withFileTypes?: false | undefined;
|
|
1837
|
+
})
|
|
1838
|
+
| BufferEncoding
|
|
1839
|
+
| null
|
|
1840
|
+
): Promise<string[] | Buffer[]>;
|
|
1208
1841
|
/**
|
|
1209
1842
|
* Asynchronous readdir(3) - read a directory.
|
|
1210
1843
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
1211
1844
|
* @param options If called with `withFileTypes: true` the result data will be an array of Dirent
|
|
1212
1845
|
*/
|
|
1213
|
-
function __promisify__(
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1846
|
+
function __promisify__(
|
|
1847
|
+
path: PathLike,
|
|
1848
|
+
options: ObjectEncodingOptions & {
|
|
1849
|
+
withFileTypes: true;
|
|
1850
|
+
}
|
|
1851
|
+
): Promise<Dirent[]>;
|
|
1852
|
+
}
|
|
1853
|
+
/**
|
|
1854
|
+
* Reads the contents of the directory.
|
|
1855
|
+
*
|
|
1856
|
+
* See the POSIX [`readdir(3)`](http://man7.org/linux/man-pages/man3/readdir.3.html) documentation for more details.
|
|
1857
|
+
*
|
|
1858
|
+
* The optional `options` argument can be a string specifying an encoding, or an
|
|
1859
|
+
* object with an `encoding` property specifying the character encoding to use for
|
|
1860
|
+
* the filenames returned. If the `encoding` is set to `'buffer'`,
|
|
1861
|
+
* the filenames returned will be passed as `<Buffer>` objects.
|
|
1862
|
+
*
|
|
1863
|
+
* If `options.withFileTypes` is set to `true`, the result will contain `<fs.Dirent>` objects.
|
|
1864
|
+
* @since v0.1.21
|
|
1865
|
+
*/
|
|
1866
|
+
export function readdirSync(
|
|
1867
|
+
path: PathLike,
|
|
1868
|
+
options?:
|
|
1869
|
+
| {
|
|
1870
|
+
encoding: BufferEncoding | null;
|
|
1871
|
+
withFileTypes?: false | undefined;
|
|
1872
|
+
}
|
|
1873
|
+
| BufferEncoding
|
|
1874
|
+
| null
|
|
1875
|
+
): string[];
|
|
1223
1876
|
/**
|
|
1224
1877
|
* Synchronous readdir(3) - read a directory.
|
|
1225
1878
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
1226
1879
|
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
|
1227
1880
|
*/
|
|
1228
|
-
export function readdirSync(
|
|
1229
|
-
|
|
1881
|
+
export function readdirSync(
|
|
1882
|
+
path: PathLike,
|
|
1883
|
+
options:
|
|
1884
|
+
| {
|
|
1885
|
+
encoding: 'buffer';
|
|
1886
|
+
withFileTypes?: false | undefined;
|
|
1887
|
+
}
|
|
1888
|
+
| 'buffer'
|
|
1889
|
+
): Buffer[];
|
|
1230
1890
|
/**
|
|
1231
1891
|
* Synchronous readdir(3) - read a directory.
|
|
1232
1892
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
1233
1893
|
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
|
1234
1894
|
*/
|
|
1235
|
-
export function readdirSync(
|
|
1236
|
-
|
|
1895
|
+
export function readdirSync(
|
|
1896
|
+
path: PathLike,
|
|
1897
|
+
options?:
|
|
1898
|
+
| (ObjectEncodingOptions & {
|
|
1899
|
+
withFileTypes?: false | undefined;
|
|
1900
|
+
})
|
|
1901
|
+
| BufferEncoding
|
|
1902
|
+
| null
|
|
1903
|
+
): string[] | Buffer[];
|
|
1237
1904
|
/**
|
|
1238
1905
|
* Synchronous readdir(3) - read a directory.
|
|
1239
1906
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
1240
1907
|
* @param options If called with `withFileTypes: true` the result data will be an array of Dirent.
|
|
1241
1908
|
*/
|
|
1242
|
-
export function readdirSync(
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1909
|
+
export function readdirSync(
|
|
1910
|
+
path: PathLike,
|
|
1911
|
+
options: ObjectEncodingOptions & {
|
|
1912
|
+
withFileTypes: true;
|
|
1913
|
+
}
|
|
1914
|
+
): Dirent[];
|
|
1915
|
+
/**
|
|
1916
|
+
* Closes the file descriptor. No arguments other than a possible exception are
|
|
1917
|
+
* given to the completion callback.
|
|
1918
|
+
*
|
|
1919
|
+
* Calling `fs.close()` on any file descriptor (`fd`) that is currently in use
|
|
1920
|
+
* through any other `fs` operation may lead to undefined behavior.
|
|
1921
|
+
*
|
|
1922
|
+
* See the POSIX [`close(2)`](http://man7.org/linux/man-pages/man2/close.2.html) documentation for more detail.
|
|
1923
|
+
* @since v0.0.2
|
|
1247
1924
|
*/
|
|
1248
1925
|
export function close(fd: number, callback?: NoParamCallback): void;
|
|
1249
|
-
|
|
1250
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
1251
1926
|
export namespace close {
|
|
1252
1927
|
/**
|
|
1253
1928
|
* Asynchronous close(2) - close a file descriptor.
|
|
@@ -1255,27 +1930,38 @@ declare module 'fs' {
|
|
|
1255
1930
|
*/
|
|
1256
1931
|
function __promisify__(fd: number): Promise<void>;
|
|
1257
1932
|
}
|
|
1258
|
-
|
|
1259
1933
|
/**
|
|
1260
|
-
*
|
|
1261
|
-
*
|
|
1934
|
+
* Closes the file descriptor. Returns `undefined`.
|
|
1935
|
+
*
|
|
1936
|
+
* Calling `fs.closeSync()` on any file descriptor (`fd`) that is currently in use
|
|
1937
|
+
* through any other `fs` operation may lead to undefined behavior.
|
|
1938
|
+
*
|
|
1939
|
+
* See the POSIX [`close(2)`](http://man7.org/linux/man-pages/man2/close.2.html) documentation for more detail.
|
|
1940
|
+
* @since v0.1.21
|
|
1262
1941
|
*/
|
|
1263
1942
|
export function closeSync(fd: number): void;
|
|
1264
|
-
|
|
1265
1943
|
/**
|
|
1266
|
-
* Asynchronous open(2)
|
|
1267
|
-
*
|
|
1268
|
-
*
|
|
1944
|
+
* Asynchronous file open. See the POSIX [`open(2)`](http://man7.org/linux/man-pages/man2/open.2.html) documentation for more details.
|
|
1945
|
+
*
|
|
1946
|
+
* `mode` sets the file mode (permission and sticky bits), but only if the file was
|
|
1947
|
+
* created. On Windows, only the write permission can be manipulated; see {@link chmod}.
|
|
1948
|
+
*
|
|
1949
|
+
* The callback gets two arguments `(err, fd)`.
|
|
1950
|
+
*
|
|
1951
|
+
* Some characters (`< > : " / \ | ? *`) are reserved under Windows as documented
|
|
1952
|
+
* by [Naming Files, Paths, and Namespaces](https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file). Under NTFS, if the filename contains
|
|
1953
|
+
* a colon, Node.js will open a file system stream, as described by[this MSDN page](https://docs.microsoft.com/en-us/windows/desktop/FileIO/using-streams).
|
|
1954
|
+
*
|
|
1955
|
+
* Functions based on `fs.open()` exhibit this behavior as well:`fs.writeFile()`, `fs.readFile()`, etc.
|
|
1956
|
+
* @since v0.0.2
|
|
1957
|
+
* @param flags See `support of file system `flags``.
|
|
1269
1958
|
*/
|
|
1270
1959
|
export function open(path: PathLike, flags: OpenMode, mode: Mode | undefined | null, callback: (err: NodeJS.ErrnoException | null, fd: number) => void): void;
|
|
1271
|
-
|
|
1272
1960
|
/**
|
|
1273
1961
|
* Asynchronous open(2) - open and possibly create a file. If the file is created, its mode will be `0o666`.
|
|
1274
1962
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
1275
1963
|
*/
|
|
1276
1964
|
export function open(path: PathLike, flags: OpenMode, callback: (err: NodeJS.ErrnoException | null, fd: number) => void): void;
|
|
1277
|
-
|
|
1278
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
1279
1965
|
export namespace open {
|
|
1280
1966
|
/**
|
|
1281
1967
|
* Asynchronous open(2) - open and possibly create a file.
|
|
@@ -1284,23 +1970,24 @@ declare module 'fs' {
|
|
|
1284
1970
|
*/
|
|
1285
1971
|
function __promisify__(path: PathLike, flags: OpenMode, mode?: Mode | null): Promise<number>;
|
|
1286
1972
|
}
|
|
1287
|
-
|
|
1288
1973
|
/**
|
|
1289
|
-
*
|
|
1290
|
-
*
|
|
1291
|
-
*
|
|
1974
|
+
* Returns an integer representing the file descriptor.
|
|
1975
|
+
*
|
|
1976
|
+
* For detailed information, see the documentation of the asynchronous version of
|
|
1977
|
+
* this API: {@link open}.
|
|
1978
|
+
* @since v0.1.21
|
|
1292
1979
|
*/
|
|
1293
1980
|
export function openSync(path: PathLike, flags: OpenMode, mode?: Mode | null): number;
|
|
1294
|
-
|
|
1295
1981
|
/**
|
|
1296
|
-
*
|
|
1297
|
-
*
|
|
1298
|
-
*
|
|
1299
|
-
*
|
|
1982
|
+
* Change the file system timestamps of the object referenced by `path`.
|
|
1983
|
+
*
|
|
1984
|
+
* The `atime` and `mtime` arguments follow these rules:
|
|
1985
|
+
*
|
|
1986
|
+
* * Values can be either numbers representing Unix epoch time in seconds,`Date`s, or a numeric string like `'123456789.0'`.
|
|
1987
|
+
* * If the value can not be converted to a number, or is `NaN`, `Infinity` or`-Infinity`, an `Error` will be thrown.
|
|
1988
|
+
* @since v0.4.2
|
|
1300
1989
|
*/
|
|
1301
1990
|
export function utimes(path: PathLike, atime: TimeLike, mtime: TimeLike, callback: NoParamCallback): void;
|
|
1302
|
-
|
|
1303
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
1304
1991
|
export namespace utimes {
|
|
1305
1992
|
/**
|
|
1306
1993
|
* Asynchronously change file timestamps of the file referenced by the supplied path.
|
|
@@ -1310,24 +1997,20 @@ declare module 'fs' {
|
|
|
1310
1997
|
*/
|
|
1311
1998
|
function __promisify__(path: PathLike, atime: TimeLike, mtime: TimeLike): Promise<void>;
|
|
1312
1999
|
}
|
|
1313
|
-
|
|
1314
2000
|
/**
|
|
1315
|
-
*
|
|
1316
|
-
*
|
|
1317
|
-
*
|
|
1318
|
-
*
|
|
2001
|
+
* Returns `undefined`.
|
|
2002
|
+
*
|
|
2003
|
+
* For detailed information, see the documentation of the asynchronous version of
|
|
2004
|
+
* this API: {@link utimes}.
|
|
2005
|
+
* @since v0.4.2
|
|
1319
2006
|
*/
|
|
1320
2007
|
export function utimesSync(path: PathLike, atime: TimeLike, mtime: TimeLike): void;
|
|
1321
|
-
|
|
1322
2008
|
/**
|
|
1323
|
-
*
|
|
1324
|
-
*
|
|
1325
|
-
* @
|
|
1326
|
-
* @param mtime The last modified time. If a string is provided, it will be coerced to number.
|
|
2009
|
+
* Change the file system timestamps of the object referenced by the supplied file
|
|
2010
|
+
* descriptor. See {@link utimes}.
|
|
2011
|
+
* @since v0.4.2
|
|
1327
2012
|
*/
|
|
1328
2013
|
export function futimes(fd: number, atime: TimeLike, mtime: TimeLike, callback: NoParamCallback): void;
|
|
1329
|
-
|
|
1330
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
1331
2014
|
export namespace futimes {
|
|
1332
2015
|
/**
|
|
1333
2016
|
* Asynchronously change file timestamps of the file referenced by the supplied file descriptor.
|
|
@@ -1337,22 +2020,19 @@ declare module 'fs' {
|
|
|
1337
2020
|
*/
|
|
1338
2021
|
function __promisify__(fd: number, atime: TimeLike, mtime: TimeLike): Promise<void>;
|
|
1339
2022
|
}
|
|
1340
|
-
|
|
1341
2023
|
/**
|
|
1342
|
-
*
|
|
1343
|
-
* @
|
|
1344
|
-
* @param atime The last access time. If a string is provided, it will be coerced to number.
|
|
1345
|
-
* @param mtime The last modified time. If a string is provided, it will be coerced to number.
|
|
2024
|
+
* Synchronous version of {@link futimes}. Returns `undefined`.
|
|
2025
|
+
* @since v0.4.2
|
|
1346
2026
|
*/
|
|
1347
2027
|
export function futimesSync(fd: number, atime: TimeLike, mtime: TimeLike): void;
|
|
1348
|
-
|
|
1349
2028
|
/**
|
|
1350
|
-
*
|
|
1351
|
-
*
|
|
2029
|
+
* Request that all data for the open file descriptor is flushed to the storage
|
|
2030
|
+
* device. The specific implementation is operating system and device specific.
|
|
2031
|
+
* Refer to the POSIX [`fsync(2)`](http://man7.org/linux/man-pages/man2/fsync.2.html) documentation for more detail. No arguments other
|
|
2032
|
+
* than a possible exception are given to the completion callback.
|
|
2033
|
+
* @since v0.1.96
|
|
1352
2034
|
*/
|
|
1353
2035
|
export function fsync(fd: number, callback: NoParamCallback): void;
|
|
1354
|
-
|
|
1355
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
1356
2036
|
export namespace fsync {
|
|
1357
2037
|
/**
|
|
1358
2038
|
* Asynchronous fsync(2) - synchronize a file's in-core state with the underlying storage device.
|
|
@@ -1360,19 +2040,37 @@ declare module 'fs' {
|
|
|
1360
2040
|
*/
|
|
1361
2041
|
function __promisify__(fd: number): Promise<void>;
|
|
1362
2042
|
}
|
|
1363
|
-
|
|
1364
2043
|
/**
|
|
1365
|
-
*
|
|
1366
|
-
*
|
|
2044
|
+
* Request that all data for the open file descriptor is flushed to the storage
|
|
2045
|
+
* device. The specific implementation is operating system and device specific.
|
|
2046
|
+
* Refer to the POSIX [`fsync(2)`](http://man7.org/linux/man-pages/man2/fsync.2.html) documentation for more detail. Returns `undefined`.
|
|
2047
|
+
* @since v0.1.96
|
|
1367
2048
|
*/
|
|
1368
2049
|
export function fsyncSync(fd: number): void;
|
|
1369
|
-
|
|
1370
2050
|
/**
|
|
1371
|
-
*
|
|
1372
|
-
*
|
|
1373
|
-
*
|
|
1374
|
-
*
|
|
1375
|
-
*
|
|
2051
|
+
* Write `buffer` to the file specified by `fd`. If `buffer` is a normal object, it
|
|
2052
|
+
* must have an own `toString` function property.
|
|
2053
|
+
*
|
|
2054
|
+
* `offset` determines the part of the buffer to be written, and `length` is
|
|
2055
|
+
* an integer specifying the number of bytes to write.
|
|
2056
|
+
*
|
|
2057
|
+
* `position` refers to the offset from the beginning of the file where this data
|
|
2058
|
+
* should be written. If `typeof position !== 'number'`, the data will be written
|
|
2059
|
+
* at the current position. See [`pwrite(2)`](http://man7.org/linux/man-pages/man2/pwrite.2.html).
|
|
2060
|
+
*
|
|
2061
|
+
* The callback will be given three arguments `(err, bytesWritten, buffer)` where`bytesWritten` specifies how many _bytes_ were written from `buffer`.
|
|
2062
|
+
*
|
|
2063
|
+
* If this method is invoked as its `util.promisify()` ed version, it returns
|
|
2064
|
+
* a promise for an `Object` with `bytesWritten` and `buffer` properties.
|
|
2065
|
+
*
|
|
2066
|
+
* It is unsafe to use `fs.write()` multiple times on the same file without waiting
|
|
2067
|
+
* for the callback. For this scenario, {@link createWriteStream} is
|
|
2068
|
+
* recommended.
|
|
2069
|
+
*
|
|
2070
|
+
* On Linux, positional writes don't work when the file is opened in append mode.
|
|
2071
|
+
* The kernel ignores the position argument and always appends the data to
|
|
2072
|
+
* the end of the file.
|
|
2073
|
+
* @since v0.0.2
|
|
1376
2074
|
*/
|
|
1377
2075
|
export function write<TBuffer extends NodeJS.ArrayBufferView>(
|
|
1378
2076
|
fd: number,
|
|
@@ -1380,9 +2078,8 @@ declare module 'fs' {
|
|
|
1380
2078
|
offset: number | undefined | null,
|
|
1381
2079
|
length: number | undefined | null,
|
|
1382
2080
|
position: number | undefined | null,
|
|
1383
|
-
callback: (err: NodeJS.ErrnoException | null, written: number, buffer: TBuffer) => void
|
|
2081
|
+
callback: (err: NodeJS.ErrnoException | null, written: number, buffer: TBuffer) => void
|
|
1384
2082
|
): void;
|
|
1385
|
-
|
|
1386
2083
|
/**
|
|
1387
2084
|
* Asynchronously writes `buffer` to the file referenced by the supplied file descriptor.
|
|
1388
2085
|
* @param fd A file descriptor.
|
|
@@ -1394,9 +2091,8 @@ declare module 'fs' {
|
|
|
1394
2091
|
buffer: TBuffer,
|
|
1395
2092
|
offset: number | undefined | null,
|
|
1396
2093
|
length: number | undefined | null,
|
|
1397
|
-
callback: (err: NodeJS.ErrnoException | null, written: number, buffer: TBuffer) => void
|
|
2094
|
+
callback: (err: NodeJS.ErrnoException | null, written: number, buffer: TBuffer) => void
|
|
1398
2095
|
): void;
|
|
1399
|
-
|
|
1400
2096
|
/**
|
|
1401
2097
|
* Asynchronously writes `buffer` to the file referenced by the supplied file descriptor.
|
|
1402
2098
|
* @param fd A file descriptor.
|
|
@@ -1408,13 +2104,11 @@ declare module 'fs' {
|
|
|
1408
2104
|
offset: number | undefined | null,
|
|
1409
2105
|
callback: (err: NodeJS.ErrnoException | null, written: number, buffer: TBuffer) => void
|
|
1410
2106
|
): void;
|
|
1411
|
-
|
|
1412
2107
|
/**
|
|
1413
2108
|
* Asynchronously writes `buffer` to the file referenced by the supplied file descriptor.
|
|
1414
2109
|
* @param fd A file descriptor.
|
|
1415
2110
|
*/
|
|
1416
2111
|
export function write<TBuffer extends NodeJS.ArrayBufferView>(fd: number, buffer: TBuffer, callback: (err: NodeJS.ErrnoException | null, written: number, buffer: TBuffer) => void): void;
|
|
1417
|
-
|
|
1418
2112
|
/**
|
|
1419
2113
|
* Asynchronously writes `string` to the file referenced by the supplied file descriptor.
|
|
1420
2114
|
* @param fd A file descriptor.
|
|
@@ -1427,9 +2121,8 @@ declare module 'fs' {
|
|
|
1427
2121
|
string: string,
|
|
1428
2122
|
position: number | undefined | null,
|
|
1429
2123
|
encoding: BufferEncoding | undefined | null,
|
|
1430
|
-
callback: (err: NodeJS.ErrnoException | null, written: number, str: string) => void
|
|
2124
|
+
callback: (err: NodeJS.ErrnoException | null, written: number, str: string) => void
|
|
1431
2125
|
): void;
|
|
1432
|
-
|
|
1433
2126
|
/**
|
|
1434
2127
|
* Asynchronously writes `string` to the file referenced by the supplied file descriptor.
|
|
1435
2128
|
* @param fd A file descriptor.
|
|
@@ -1437,15 +2130,12 @@ declare module 'fs' {
|
|
|
1437
2130
|
* @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
|
|
1438
2131
|
*/
|
|
1439
2132
|
export function write(fd: number, string: string, position: number | undefined | null, callback: (err: NodeJS.ErrnoException | null, written: number, str: string) => void): void;
|
|
1440
|
-
|
|
1441
2133
|
/**
|
|
1442
2134
|
* Asynchronously writes `string` to the file referenced by the supplied file descriptor.
|
|
1443
2135
|
* @param fd A file descriptor.
|
|
1444
2136
|
* @param string A string to write.
|
|
1445
2137
|
*/
|
|
1446
2138
|
export function write(fd: number, string: string, callback: (err: NodeJS.ErrnoException | null, written: number, str: string) => void): void;
|
|
1447
|
-
|
|
1448
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
1449
2139
|
export namespace write {
|
|
1450
2140
|
/**
|
|
1451
2141
|
* Asynchronously writes `buffer` to the file referenced by the supplied file descriptor.
|
|
@@ -1459,9 +2149,11 @@ declare module 'fs' {
|
|
|
1459
2149
|
buffer?: TBuffer,
|
|
1460
2150
|
offset?: number,
|
|
1461
2151
|
length?: number,
|
|
1462
|
-
position?: number | null
|
|
1463
|
-
): Promise<{
|
|
1464
|
-
|
|
2152
|
+
position?: number | null
|
|
2153
|
+
): Promise<{
|
|
2154
|
+
bytesWritten: number;
|
|
2155
|
+
buffer: TBuffer;
|
|
2156
|
+
}>;
|
|
1465
2157
|
/**
|
|
1466
2158
|
* Asynchronously writes `string` to the file referenced by the supplied file descriptor.
|
|
1467
2159
|
* @param fd A file descriptor.
|
|
@@ -1469,18 +2161,23 @@ declare module 'fs' {
|
|
|
1469
2161
|
* @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
|
|
1470
2162
|
* @param encoding The expected string encoding.
|
|
1471
2163
|
*/
|
|
1472
|
-
function __promisify__(
|
|
2164
|
+
function __promisify__(
|
|
2165
|
+
fd: number,
|
|
2166
|
+
string: string,
|
|
2167
|
+
position?: number | null,
|
|
2168
|
+
encoding?: BufferEncoding | null
|
|
2169
|
+
): Promise<{
|
|
2170
|
+
bytesWritten: number;
|
|
2171
|
+
buffer: string;
|
|
2172
|
+
}>;
|
|
1473
2173
|
}
|
|
1474
|
-
|
|
1475
2174
|
/**
|
|
1476
|
-
*
|
|
1477
|
-
*
|
|
1478
|
-
* @
|
|
1479
|
-
* @
|
|
1480
|
-
* @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
|
|
2175
|
+
* For detailed information, see the documentation of the asynchronous version of
|
|
2176
|
+
* this API: {@link write}.
|
|
2177
|
+
* @since v0.1.21
|
|
2178
|
+
* @return The number of bytes written.
|
|
1481
2179
|
*/
|
|
1482
2180
|
export function writeSync(fd: number, buffer: NodeJS.ArrayBufferView, offset?: number | null, length?: number | null, position?: number | null): number;
|
|
1483
|
-
|
|
1484
2181
|
/**
|
|
1485
2182
|
* Synchronously writes `string` to the file referenced by the supplied file descriptor, returning the number of bytes written.
|
|
1486
2183
|
* @param fd A file descriptor.
|
|
@@ -1489,16 +2186,23 @@ declare module 'fs' {
|
|
|
1489
2186
|
* @param encoding The expected string encoding.
|
|
1490
2187
|
*/
|
|
1491
2188
|
export function writeSync(fd: number, string: string, position?: number | null, encoding?: BufferEncoding | null): number;
|
|
1492
|
-
|
|
1493
2189
|
export type ReadPosition = number | bigint;
|
|
1494
|
-
|
|
1495
2190
|
/**
|
|
1496
|
-
*
|
|
1497
|
-
*
|
|
2191
|
+
* Read data from the file specified by `fd`.
|
|
2192
|
+
*
|
|
2193
|
+
* The callback is given the three arguments, `(err, bytesRead, buffer)`.
|
|
2194
|
+
*
|
|
2195
|
+
* If the file is not modified concurrently, the end-of-file is reached when the
|
|
2196
|
+
* number of bytes read is zero.
|
|
2197
|
+
*
|
|
2198
|
+
* If this method is invoked as its `util.promisify()` ed version, it returns
|
|
2199
|
+
* a promise for an `Object` with `bytesRead` and `buffer` properties.
|
|
2200
|
+
* @since v0.0.2
|
|
1498
2201
|
* @param buffer The buffer that the data will be written to.
|
|
1499
|
-
* @param offset The
|
|
2202
|
+
* @param offset The position in `buffer` to write the data to.
|
|
1500
2203
|
* @param length The number of bytes to read.
|
|
1501
|
-
* @param position
|
|
2204
|
+
* @param position Specifies where to begin reading from in the file. If `position` is `null` or `-1 `, data will be read from the current file position, and the file position will be updated. If
|
|
2205
|
+
* `position` is an integer, the file position will be unchanged.
|
|
1502
2206
|
*/
|
|
1503
2207
|
export function read<TBuffer extends NodeJS.ArrayBufferView>(
|
|
1504
2208
|
fd: number,
|
|
@@ -1506,10 +2210,8 @@ declare module 'fs' {
|
|
|
1506
2210
|
offset: number,
|
|
1507
2211
|
length: number,
|
|
1508
2212
|
position: ReadPosition | null,
|
|
1509
|
-
callback: (err: NodeJS.ErrnoException | null, bytesRead: number, buffer: TBuffer) => void
|
|
2213
|
+
callback: (err: NodeJS.ErrnoException | null, bytesRead: number, buffer: TBuffer) => void
|
|
1510
2214
|
): void;
|
|
1511
|
-
|
|
1512
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
1513
2215
|
export namespace read {
|
|
1514
2216
|
/**
|
|
1515
2217
|
* @param fd A file descriptor.
|
|
@@ -1524,9 +2226,11 @@ declare module 'fs' {
|
|
|
1524
2226
|
offset: number,
|
|
1525
2227
|
length: number,
|
|
1526
2228
|
position: number | null
|
|
1527
|
-
): Promise<{
|
|
2229
|
+
): Promise<{
|
|
2230
|
+
bytesRead: number;
|
|
2231
|
+
buffer: TBuffer;
|
|
2232
|
+
}>;
|
|
1528
2233
|
}
|
|
1529
|
-
|
|
1530
2234
|
export interface ReadSyncOptions {
|
|
1531
2235
|
/**
|
|
1532
2236
|
* @default 0
|
|
@@ -1541,36 +2245,96 @@ declare module 'fs' {
|
|
|
1541
2245
|
*/
|
|
1542
2246
|
position?: ReadPosition | null | undefined;
|
|
1543
2247
|
}
|
|
1544
|
-
|
|
1545
2248
|
/**
|
|
1546
|
-
*
|
|
1547
|
-
*
|
|
1548
|
-
*
|
|
1549
|
-
*
|
|
1550
|
-
* @
|
|
1551
|
-
* @param position The offset from the beginning of the file from which data should be read. If `null`, data will be read from the current position.
|
|
2249
|
+
* Returns the number of `bytesRead`.
|
|
2250
|
+
*
|
|
2251
|
+
* For detailed information, see the documentation of the asynchronous version of
|
|
2252
|
+
* this API: {@link read}.
|
|
2253
|
+
* @since v0.1.21
|
|
1552
2254
|
*/
|
|
1553
2255
|
export function readSync(fd: number, buffer: NodeJS.ArrayBufferView, offset: number, length: number, position: ReadPosition | null): number;
|
|
1554
|
-
|
|
1555
2256
|
/**
|
|
1556
2257
|
* Similar to the above `fs.readSync` function, this version takes an optional `options` object.
|
|
1557
2258
|
* If no `options` object is specified, it will default with the above values.
|
|
1558
2259
|
*/
|
|
1559
2260
|
export function readSync(fd: number, buffer: NodeJS.ArrayBufferView, opts?: ReadSyncOptions): number;
|
|
1560
|
-
|
|
1561
2261
|
/**
|
|
1562
2262
|
* Asynchronously reads the entire contents of a file.
|
|
1563
|
-
*
|
|
1564
|
-
*
|
|
1565
|
-
*
|
|
1566
|
-
*
|
|
2263
|
+
*
|
|
2264
|
+
* ```js
|
|
2265
|
+
* import { readFile } from 'fs';
|
|
2266
|
+
*
|
|
2267
|
+
* readFile('/etc/passwd', (err, data) => {
|
|
2268
|
+
* if (err) throw err;
|
|
2269
|
+
* console.log(data);
|
|
2270
|
+
* });
|
|
2271
|
+
* ```
|
|
2272
|
+
*
|
|
2273
|
+
* The callback is passed two arguments `(err, data)`, where `data` is the
|
|
2274
|
+
* contents of the file.
|
|
2275
|
+
*
|
|
2276
|
+
* If no encoding is specified, then the raw buffer is returned.
|
|
2277
|
+
*
|
|
2278
|
+
* If `options` is a string, then it specifies the encoding:
|
|
2279
|
+
*
|
|
2280
|
+
* ```js
|
|
2281
|
+
* import { readFile } from 'fs';
|
|
2282
|
+
*
|
|
2283
|
+
* readFile('/etc/passwd', 'utf8', callback);
|
|
2284
|
+
* ```
|
|
2285
|
+
*
|
|
2286
|
+
* When the path is a directory, the behavior of `fs.readFile()` and {@link readFileSync} is platform-specific. On macOS, Linux, and Windows, an
|
|
2287
|
+
* error will be returned. On FreeBSD, a representation of the directory's contents
|
|
2288
|
+
* will be returned.
|
|
2289
|
+
*
|
|
2290
|
+
* ```js
|
|
2291
|
+
* import { readFile } from 'fs';
|
|
2292
|
+
*
|
|
2293
|
+
* // macOS, Linux, and Windows
|
|
2294
|
+
* readFile('<directory>', (err, data) => {
|
|
2295
|
+
* // => [Error: EISDIR: illegal operation on a directory, read <directory>]
|
|
2296
|
+
* });
|
|
2297
|
+
*
|
|
2298
|
+
* // FreeBSD
|
|
2299
|
+
* readFile('<directory>', (err, data) => {
|
|
2300
|
+
* // => null, <data>
|
|
2301
|
+
* });
|
|
2302
|
+
* ```
|
|
2303
|
+
*
|
|
2304
|
+
* It is possible to abort an ongoing request using an `AbortSignal`. If a
|
|
2305
|
+
* request is aborted the callback is called with an `AbortError`:
|
|
2306
|
+
*
|
|
2307
|
+
* ```js
|
|
2308
|
+
* import { readFile } from 'fs';
|
|
2309
|
+
*
|
|
2310
|
+
* const controller = new AbortController();
|
|
2311
|
+
* const signal = controller.signal;
|
|
2312
|
+
* readFile(fileInfo[0].name, { signal }, (err, buf) => {
|
|
2313
|
+
* // ...
|
|
2314
|
+
* });
|
|
2315
|
+
* // When you want to abort the request
|
|
2316
|
+
* controller.abort();
|
|
2317
|
+
* ```
|
|
2318
|
+
*
|
|
2319
|
+
* The `fs.readFile()` function buffers the entire file. To minimize memory costs,
|
|
2320
|
+
* when possible prefer streaming via `fs.createReadStream()`.
|
|
2321
|
+
*
|
|
2322
|
+
* Aborting an ongoing request does not abort individual operating
|
|
2323
|
+
* system requests but rather the internal buffering `fs.readFile` performs.
|
|
2324
|
+
* @since v0.1.29
|
|
2325
|
+
* @param path filename or file descriptor
|
|
1567
2326
|
*/
|
|
1568
2327
|
export function readFile(
|
|
1569
2328
|
path: PathOrFileDescriptor,
|
|
1570
|
-
options:
|
|
1571
|
-
|
|
2329
|
+
options:
|
|
2330
|
+
| ({
|
|
2331
|
+
encoding?: null | undefined;
|
|
2332
|
+
flag?: string | undefined;
|
|
2333
|
+
} & Abortable)
|
|
2334
|
+
| undefined
|
|
2335
|
+
| null,
|
|
2336
|
+
callback: (err: NodeJS.ErrnoException | null, data: Buffer) => void
|
|
1572
2337
|
): void;
|
|
1573
|
-
|
|
1574
2338
|
/**
|
|
1575
2339
|
* Asynchronously reads the entire contents of a file.
|
|
1576
2340
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
@@ -1580,10 +2344,14 @@ declare module 'fs' {
|
|
|
1580
2344
|
*/
|
|
1581
2345
|
export function readFile(
|
|
1582
2346
|
path: PathOrFileDescriptor,
|
|
1583
|
-
options:
|
|
1584
|
-
|
|
2347
|
+
options:
|
|
2348
|
+
| ({
|
|
2349
|
+
encoding: BufferEncoding;
|
|
2350
|
+
flag?: string | undefined;
|
|
2351
|
+
} & Abortable)
|
|
2352
|
+
| string,
|
|
2353
|
+
callback: (err: NodeJS.ErrnoException | null, data: string) => void
|
|
1585
2354
|
): void;
|
|
1586
|
-
|
|
1587
2355
|
/**
|
|
1588
2356
|
* Asynchronously reads the entire contents of a file.
|
|
1589
2357
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
@@ -1593,18 +2361,21 @@ declare module 'fs' {
|
|
|
1593
2361
|
*/
|
|
1594
2362
|
export function readFile(
|
|
1595
2363
|
path: PathOrFileDescriptor,
|
|
1596
|
-
options:
|
|
1597
|
-
|
|
2364
|
+
options:
|
|
2365
|
+
| (ObjectEncodingOptions & {
|
|
2366
|
+
flag?: string | undefined;
|
|
2367
|
+
} & Abortable)
|
|
2368
|
+
| string
|
|
2369
|
+
| undefined
|
|
2370
|
+
| null,
|
|
2371
|
+
callback: (err: NodeJS.ErrnoException | null, data: string | Buffer) => void
|
|
1598
2372
|
): void;
|
|
1599
|
-
|
|
1600
2373
|
/**
|
|
1601
2374
|
* Asynchronously reads the entire contents of a file.
|
|
1602
2375
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
1603
2376
|
* If a file descriptor is provided, the underlying file will _not_ be closed automatically.
|
|
1604
2377
|
*/
|
|
1605
2378
|
export function readFile(path: PathOrFileDescriptor, callback: (err: NodeJS.ErrnoException | null, data: Buffer) => void): void;
|
|
1606
|
-
|
|
1607
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
1608
2379
|
export namespace readFile {
|
|
1609
2380
|
/**
|
|
1610
2381
|
* Asynchronously reads the entire contents of a file.
|
|
@@ -1613,8 +2384,13 @@ declare module 'fs' {
|
|
|
1613
2384
|
* @param options An object that may contain an optional flag.
|
|
1614
2385
|
* If a flag is not provided, it defaults to `'r'`.
|
|
1615
2386
|
*/
|
|
1616
|
-
function __promisify__(
|
|
1617
|
-
|
|
2387
|
+
function __promisify__(
|
|
2388
|
+
path: PathOrFileDescriptor,
|
|
2389
|
+
options?: {
|
|
2390
|
+
encoding?: null | undefined;
|
|
2391
|
+
flag?: string | undefined;
|
|
2392
|
+
} | null
|
|
2393
|
+
): Promise<Buffer>;
|
|
1618
2394
|
/**
|
|
1619
2395
|
* Asynchronously reads the entire contents of a file.
|
|
1620
2396
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
@@ -1623,8 +2399,15 @@ declare module 'fs' {
|
|
|
1623
2399
|
* @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
|
|
1624
2400
|
* If a flag is not provided, it defaults to `'r'`.
|
|
1625
2401
|
*/
|
|
1626
|
-
function __promisify__(
|
|
1627
|
-
|
|
2402
|
+
function __promisify__(
|
|
2403
|
+
path: PathOrFileDescriptor,
|
|
2404
|
+
options:
|
|
2405
|
+
| {
|
|
2406
|
+
encoding: BufferEncoding;
|
|
2407
|
+
flag?: string | undefined;
|
|
2408
|
+
}
|
|
2409
|
+
| string
|
|
2410
|
+
): Promise<string>;
|
|
1628
2411
|
/**
|
|
1629
2412
|
* Asynchronously reads the entire contents of a file.
|
|
1630
2413
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
@@ -1633,17 +2416,47 @@ declare module 'fs' {
|
|
|
1633
2416
|
* @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
|
|
1634
2417
|
* If a flag is not provided, it defaults to `'r'`.
|
|
1635
2418
|
*/
|
|
1636
|
-
function __promisify__(
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
2419
|
+
function __promisify__(
|
|
2420
|
+
path: PathOrFileDescriptor,
|
|
2421
|
+
options?:
|
|
2422
|
+
| (ObjectEncodingOptions & {
|
|
2423
|
+
flag?: string | undefined;
|
|
2424
|
+
})
|
|
2425
|
+
| string
|
|
2426
|
+
| null
|
|
2427
|
+
): Promise<string | Buffer>;
|
|
2428
|
+
}
|
|
2429
|
+
/**
|
|
2430
|
+
* Returns the contents of the `path`.
|
|
2431
|
+
*
|
|
2432
|
+
* For detailed information, see the documentation of the asynchronous version of
|
|
2433
|
+
* this API: {@link readFile}.
|
|
2434
|
+
*
|
|
2435
|
+
* If the `encoding` option is specified then this function returns a
|
|
2436
|
+
* string. Otherwise it returns a buffer.
|
|
2437
|
+
*
|
|
2438
|
+
* Similar to {@link readFile}, when the path is a directory, the behavior of`fs.readFileSync()` is platform-specific.
|
|
2439
|
+
*
|
|
2440
|
+
* ```js
|
|
2441
|
+
* import { readFileSync } from 'fs';
|
|
2442
|
+
*
|
|
2443
|
+
* // macOS, Linux, and Windows
|
|
2444
|
+
* readFileSync('<directory>');
|
|
2445
|
+
* // => [Error: EISDIR: illegal operation on a directory, read <directory>]
|
|
2446
|
+
*
|
|
2447
|
+
* // FreeBSD
|
|
2448
|
+
* readFileSync('<directory>'); // => <data>
|
|
2449
|
+
* ```
|
|
2450
|
+
* @since v0.1.8
|
|
2451
|
+
* @param path filename or file descriptor
|
|
2452
|
+
*/
|
|
2453
|
+
export function readFileSync(
|
|
2454
|
+
path: PathOrFileDescriptor,
|
|
2455
|
+
options?: {
|
|
2456
|
+
encoding?: null | undefined;
|
|
2457
|
+
flag?: string | undefined;
|
|
2458
|
+
} | null
|
|
2459
|
+
): Buffer;
|
|
1647
2460
|
/**
|
|
1648
2461
|
* Synchronously reads the entire contents of a file.
|
|
1649
2462
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
@@ -1651,8 +2464,15 @@ declare module 'fs' {
|
|
|
1651
2464
|
* @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
|
|
1652
2465
|
* If a flag is not provided, it defaults to `'r'`.
|
|
1653
2466
|
*/
|
|
1654
|
-
export function readFileSync(
|
|
1655
|
-
|
|
2467
|
+
export function readFileSync(
|
|
2468
|
+
path: PathOrFileDescriptor,
|
|
2469
|
+
options:
|
|
2470
|
+
| {
|
|
2471
|
+
encoding: BufferEncoding;
|
|
2472
|
+
flag?: string | undefined;
|
|
2473
|
+
}
|
|
2474
|
+
| BufferEncoding
|
|
2475
|
+
): string;
|
|
1656
2476
|
/**
|
|
1657
2477
|
* Synchronously reads the entire contents of a file.
|
|
1658
2478
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
@@ -1660,23 +2480,82 @@ declare module 'fs' {
|
|
|
1660
2480
|
* @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
|
|
1661
2481
|
* If a flag is not provided, it defaults to `'r'`.
|
|
1662
2482
|
*/
|
|
1663
|
-
export function readFileSync(
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
2483
|
+
export function readFileSync(
|
|
2484
|
+
path: PathOrFileDescriptor,
|
|
2485
|
+
options?:
|
|
2486
|
+
| (ObjectEncodingOptions & {
|
|
2487
|
+
flag?: string | undefined;
|
|
2488
|
+
})
|
|
2489
|
+
| BufferEncoding
|
|
2490
|
+
| null
|
|
2491
|
+
): string | Buffer;
|
|
2492
|
+
export type WriteFileOptions =
|
|
2493
|
+
| (ObjectEncodingOptions &
|
|
2494
|
+
Abortable & {
|
|
2495
|
+
mode?: Mode | undefined;
|
|
2496
|
+
flag?: string | undefined;
|
|
2497
|
+
})
|
|
2498
|
+
| string
|
|
2499
|
+
| null;
|
|
2500
|
+
/**
|
|
2501
|
+
* When `file` is a filename, asynchronously writes data to the file, replacing the
|
|
2502
|
+
* file if it already exists. `data` can be a string or a buffer.
|
|
2503
|
+
*
|
|
2504
|
+
* When `file` is a file descriptor, the behavior is similar to calling`fs.write()` directly (which is recommended). See the notes below on using
|
|
2505
|
+
* a file descriptor.
|
|
2506
|
+
*
|
|
2507
|
+
* The `encoding` option is ignored if `data` is a buffer.
|
|
2508
|
+
* If `data` is a normal object, it must have an own `toString` function property.
|
|
2509
|
+
*
|
|
2510
|
+
* ```js
|
|
2511
|
+
* import { writeFile } from 'fs';
|
|
2512
|
+
*
|
|
2513
|
+
* const data = new Uint8Array(Buffer.from('Hello Node.js'));
|
|
2514
|
+
* writeFile('message.txt', data, (err) => {
|
|
2515
|
+
* if (err) throw err;
|
|
2516
|
+
* console.log('The file has been saved!');
|
|
2517
|
+
* });
|
|
2518
|
+
* ```
|
|
2519
|
+
*
|
|
2520
|
+
* If `options` is a string, then it specifies the encoding:
|
|
2521
|
+
*
|
|
2522
|
+
* ```js
|
|
2523
|
+
* import { writeFile } from 'fs';
|
|
2524
|
+
*
|
|
2525
|
+
* writeFile('message.txt', 'Hello Node.js', 'utf8', callback);
|
|
2526
|
+
* ```
|
|
2527
|
+
*
|
|
2528
|
+
* It is unsafe to use `fs.writeFile()` multiple times on the same file without
|
|
2529
|
+
* waiting for the callback. For this scenario, {@link createWriteStream} is
|
|
2530
|
+
* recommended.
|
|
2531
|
+
*
|
|
2532
|
+
* Similarly to `fs.readFile` \- `fs.writeFile` is a convenience method that
|
|
2533
|
+
* performs multiple `write` calls internally to write the buffer passed to it.
|
|
2534
|
+
* For performance sensitive code consider using {@link createWriteStream}.
|
|
2535
|
+
*
|
|
2536
|
+
* It is possible to use an `<AbortSignal>` to cancel an `fs.writeFile()`.
|
|
2537
|
+
* Cancelation is "best effort", and some amount of data is likely still
|
|
2538
|
+
* to be written.
|
|
2539
|
+
*
|
|
2540
|
+
* ```js
|
|
2541
|
+
* import { writeFile } from 'fs';
|
|
2542
|
+
*
|
|
2543
|
+
* const controller = new AbortController();
|
|
2544
|
+
* const { signal } = controller;
|
|
2545
|
+
* const data = new Uint8Array(Buffer.from('Hello Node.js'));
|
|
2546
|
+
* writeFile('message.txt', data, { signal }, (err) => {
|
|
2547
|
+
* // When a request is aborted - the callback is called with an AbortError
|
|
2548
|
+
* });
|
|
2549
|
+
* // When the request should be aborted
|
|
2550
|
+
* controller.abort();
|
|
2551
|
+
* ```
|
|
2552
|
+
*
|
|
2553
|
+
* Aborting an ongoing request does not abort individual operating
|
|
2554
|
+
* system requests but rather the internal buffering `fs.writeFile` performs.
|
|
2555
|
+
* @since v0.1.29
|
|
2556
|
+
* @param file filename or file descriptor
|
|
2557
|
+
*/
|
|
2558
|
+
export function writeFile(file: PathOrFileDescriptor, data: string | NodeJS.ArrayBufferView, options: WriteFileOptions, callback: NoParamCallback): void;
|
|
1680
2559
|
/**
|
|
1681
2560
|
* Asynchronously writes data to a file, replacing the file if it already exists.
|
|
1682
2561
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
@@ -1684,8 +2563,6 @@ declare module 'fs' {
|
|
|
1684
2563
|
* @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
|
|
1685
2564
|
*/
|
|
1686
2565
|
export function writeFile(path: PathOrFileDescriptor, data: string | NodeJS.ArrayBufferView, callback: NoParamCallback): void;
|
|
1687
|
-
|
|
1688
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
1689
2566
|
export namespace writeFile {
|
|
1690
2567
|
/**
|
|
1691
2568
|
* Asynchronously writes data to a file, replacing the file if it already exists.
|
|
@@ -1701,33 +2578,67 @@ declare module 'fs' {
|
|
|
1701
2578
|
*/
|
|
1702
2579
|
function __promisify__(path: PathOrFileDescriptor, data: string | NodeJS.ArrayBufferView, options?: WriteFileOptions): Promise<void>;
|
|
1703
2580
|
}
|
|
1704
|
-
|
|
1705
|
-
/**
|
|
1706
|
-
* Synchronously writes data to a file, replacing the file if it already exists.
|
|
1707
|
-
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
1708
|
-
* If a file descriptor is provided, the underlying file will _not_ be closed automatically.
|
|
1709
|
-
* @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
|
|
1710
|
-
* @param options Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
|
|
1711
|
-
* If `encoding` is not supplied, the default of `'utf8'` is used.
|
|
1712
|
-
* If `mode` is not supplied, the default of `0o666` is used.
|
|
1713
|
-
* If `mode` is a string, it is parsed as an octal integer.
|
|
1714
|
-
* If `flag` is not supplied, the default of `'w'` is used.
|
|
1715
|
-
*/
|
|
1716
|
-
export function writeFileSync(path: PathOrFileDescriptor, data: string | NodeJS.ArrayBufferView, options?: WriteFileOptions): void;
|
|
1717
|
-
|
|
1718
2581
|
/**
|
|
1719
|
-
*
|
|
1720
|
-
*
|
|
1721
|
-
*
|
|
1722
|
-
*
|
|
1723
|
-
* @
|
|
1724
|
-
*
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
2582
|
+
* Returns `undefined`.
|
|
2583
|
+
*
|
|
2584
|
+
* For detailed information, see the documentation of the asynchronous version of
|
|
2585
|
+
* this API: {@link writeFile}.
|
|
2586
|
+
* @since v0.1.29
|
|
2587
|
+
* @param file filename or file descriptor
|
|
2588
|
+
*/
|
|
2589
|
+
export function writeFileSync(file: PathOrFileDescriptor, data: string | NodeJS.ArrayBufferView, options?: WriteFileOptions): void;
|
|
2590
|
+
/**
|
|
2591
|
+
* Asynchronously append data to a file, creating the file if it does not yet
|
|
2592
|
+
* exist. `data` can be a string or a `<Buffer>`.
|
|
2593
|
+
*
|
|
2594
|
+
* ```js
|
|
2595
|
+
* import { appendFile } from 'fs';
|
|
2596
|
+
*
|
|
2597
|
+
* appendFile('message.txt', 'data to append', (err) => {
|
|
2598
|
+
* if (err) throw err;
|
|
2599
|
+
* console.log('The "data to append" was appended to file!');
|
|
2600
|
+
* });
|
|
2601
|
+
* ```
|
|
2602
|
+
*
|
|
2603
|
+
* If `options` is a string, then it specifies the encoding:
|
|
2604
|
+
*
|
|
2605
|
+
* ```js
|
|
2606
|
+
* import { appendFile } from 'fs';
|
|
2607
|
+
*
|
|
2608
|
+
* appendFile('message.txt', 'data to append', 'utf8', callback);
|
|
2609
|
+
* ```
|
|
2610
|
+
*
|
|
2611
|
+
* The `path` may be specified as a numeric file descriptor that has been opened
|
|
2612
|
+
* for appending (using `fs.open()` or `fs.openSync()`). The file descriptor will
|
|
2613
|
+
* not be closed automatically.
|
|
2614
|
+
*
|
|
2615
|
+
* ```js
|
|
2616
|
+
* import { open, close, appendFile } from 'fs';
|
|
2617
|
+
*
|
|
2618
|
+
* function closeFd(fd) {
|
|
2619
|
+
* close(fd, (err) => {
|
|
2620
|
+
* if (err) throw err;
|
|
2621
|
+
* });
|
|
2622
|
+
* }
|
|
2623
|
+
*
|
|
2624
|
+
* open('message.txt', 'a', (err, fd) => {
|
|
2625
|
+
* if (err) throw err;
|
|
2626
|
+
*
|
|
2627
|
+
* try {
|
|
2628
|
+
* appendFile(fd, 'data to append', 'utf8', (err) => {
|
|
2629
|
+
* closeFd(fd);
|
|
2630
|
+
* if (err) throw err;
|
|
2631
|
+
* });
|
|
2632
|
+
* } catch (err) {
|
|
2633
|
+
* closeFd(fd);
|
|
2634
|
+
* throw err;
|
|
2635
|
+
* }
|
|
2636
|
+
* });
|
|
2637
|
+
* ```
|
|
2638
|
+
* @since v0.6.7
|
|
2639
|
+
* @param path filename or file descriptor
|
|
2640
|
+
*/
|
|
2641
|
+
export function appendFile(path: PathOrFileDescriptor, data: string | Uint8Array, options: WriteFileOptions, callback: NoParamCallback): void;
|
|
1731
2642
|
/**
|
|
1732
2643
|
* Asynchronously append data to a file, creating the file if it does not exist.
|
|
1733
2644
|
* @param file A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
@@ -1735,8 +2646,6 @@ declare module 'fs' {
|
|
|
1735
2646
|
* @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
|
|
1736
2647
|
*/
|
|
1737
2648
|
export function appendFile(file: PathOrFileDescriptor, data: string | Uint8Array, callback: NoParamCallback): void;
|
|
1738
|
-
|
|
1739
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
1740
2649
|
export namespace appendFile {
|
|
1741
2650
|
/**
|
|
1742
2651
|
* Asynchronously append data to a file, creating the file if it does not exist.
|
|
@@ -1752,55 +2661,160 @@ declare module 'fs' {
|
|
|
1752
2661
|
*/
|
|
1753
2662
|
function __promisify__(file: PathOrFileDescriptor, data: string | Uint8Array, options?: WriteFileOptions): Promise<void>;
|
|
1754
2663
|
}
|
|
1755
|
-
|
|
1756
2664
|
/**
|
|
1757
|
-
* Synchronously append data to a file, creating the file if it does not
|
|
1758
|
-
*
|
|
1759
|
-
*
|
|
1760
|
-
*
|
|
1761
|
-
*
|
|
1762
|
-
*
|
|
1763
|
-
*
|
|
1764
|
-
*
|
|
1765
|
-
*
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
*
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
2665
|
+
* Synchronously append data to a file, creating the file if it does not yet
|
|
2666
|
+
* exist. `data` can be a string or a `<Buffer>`.
|
|
2667
|
+
*
|
|
2668
|
+
* ```js
|
|
2669
|
+
* import { appendFileSync } from 'fs';
|
|
2670
|
+
*
|
|
2671
|
+
* try {
|
|
2672
|
+
* appendFileSync('message.txt', 'data to append');
|
|
2673
|
+
* console.log('The "data to append" was appended to file!');
|
|
2674
|
+
* } catch (err) {
|
|
2675
|
+
* // Handle the error
|
|
2676
|
+
* }
|
|
2677
|
+
* ```
|
|
2678
|
+
*
|
|
2679
|
+
* If `options` is a string, then it specifies the encoding:
|
|
2680
|
+
*
|
|
2681
|
+
* ```js
|
|
2682
|
+
* import { appendFileSync } from 'fs';
|
|
2683
|
+
*
|
|
2684
|
+
* appendFileSync('message.txt', 'data to append', 'utf8');
|
|
2685
|
+
* ```
|
|
2686
|
+
*
|
|
2687
|
+
* The `path` may be specified as a numeric file descriptor that has been opened
|
|
2688
|
+
* for appending (using `fs.open()` or `fs.openSync()`). The file descriptor will
|
|
2689
|
+
* not be closed automatically.
|
|
2690
|
+
*
|
|
2691
|
+
* ```js
|
|
2692
|
+
* import { openSync, closeSync, appendFileSync } from 'fs';
|
|
2693
|
+
*
|
|
2694
|
+
* let fd;
|
|
2695
|
+
*
|
|
2696
|
+
* try {
|
|
2697
|
+
* fd = openSync('message.txt', 'a');
|
|
2698
|
+
* appendFileSync(fd, 'data to append', 'utf8');
|
|
2699
|
+
* } catch (err) {
|
|
2700
|
+
* // Handle the error
|
|
2701
|
+
* } finally {
|
|
2702
|
+
* if (fd !== undefined)
|
|
2703
|
+
* closeSync(fd);
|
|
2704
|
+
* }
|
|
2705
|
+
* ```
|
|
2706
|
+
* @since v0.6.7
|
|
2707
|
+
* @param path filename or file descriptor
|
|
2708
|
+
*/
|
|
2709
|
+
export function appendFileSync(path: PathOrFileDescriptor, data: string | Uint8Array, options?: WriteFileOptions): void;
|
|
2710
|
+
/**
|
|
2711
|
+
* Watch for changes on `filename`. The callback `listener` will be called each
|
|
2712
|
+
* time the file is accessed.
|
|
2713
|
+
*
|
|
2714
|
+
* The `options` argument may be omitted. If provided, it should be an object. The`options` object may contain a boolean named `persistent` that indicates
|
|
2715
|
+
* whether the process should continue to run as long as files are being watched.
|
|
2716
|
+
* The `options` object may specify an `interval` property indicating how often the
|
|
2717
|
+
* target should be polled in milliseconds.
|
|
2718
|
+
*
|
|
2719
|
+
* The `listener` gets two arguments the current stat object and the previous
|
|
2720
|
+
* stat object:
|
|
2721
|
+
*
|
|
2722
|
+
* ```js
|
|
2723
|
+
* import { watchFile } from 'fs';
|
|
2724
|
+
*
|
|
2725
|
+
* watchFile('message.text', (curr, prev) => {
|
|
2726
|
+
* console.log(`the current mtime is: ${curr.mtime}`);
|
|
2727
|
+
* console.log(`the previous mtime was: ${prev.mtime}`);
|
|
2728
|
+
* });
|
|
2729
|
+
* ```
|
|
2730
|
+
*
|
|
2731
|
+
* These stat objects are instances of `fs.Stat`. If the `bigint` option is `true`,
|
|
2732
|
+
* the numeric values in these objects are specified as `BigInt`s.
|
|
2733
|
+
*
|
|
2734
|
+
* To be notified when the file was modified, not just accessed, it is necessary
|
|
2735
|
+
* to compare `curr.mtime` and `prev.mtime`.
|
|
2736
|
+
*
|
|
2737
|
+
* When an `fs.watchFile` operation results in an `ENOENT` error, it
|
|
2738
|
+
* will invoke the listener once, with all the fields zeroed (or, for dates, the
|
|
2739
|
+
* Unix Epoch). If the file is created later on, the listener will be called
|
|
2740
|
+
* again, with the latest stat objects. This is a change in functionality since
|
|
2741
|
+
* v0.10.
|
|
2742
|
+
*
|
|
2743
|
+
* Using {@link watch} is more efficient than `fs.watchFile` and`fs.unwatchFile`. `fs.watch` should be used instead of `fs.watchFile` and`fs.unwatchFile` when possible.
|
|
2744
|
+
*
|
|
2745
|
+
* When a file being watched by `fs.watchFile()` disappears and reappears,
|
|
2746
|
+
* then the contents of `previous` in the second callback event (the file's
|
|
2747
|
+
* reappearance) will be the same as the contents of `previous` in the first
|
|
2748
|
+
* callback event (its disappearance).
|
|
2749
|
+
*
|
|
2750
|
+
* This happens when:
|
|
2751
|
+
*
|
|
2752
|
+
* * the file is deleted, followed by a restore
|
|
2753
|
+
* * the file is renamed and then renamed a second time back to its original name
|
|
2754
|
+
* @since v0.1.31
|
|
2755
|
+
*/
|
|
2756
|
+
export function watchFile(
|
|
2757
|
+
filename: PathLike,
|
|
2758
|
+
options:
|
|
2759
|
+
| {
|
|
2760
|
+
persistent?: boolean | undefined;
|
|
2761
|
+
interval?: number | undefined;
|
|
2762
|
+
}
|
|
2763
|
+
| undefined,
|
|
2764
|
+
listener: (curr: Stats, prev: Stats) => void
|
|
2765
|
+
): void;
|
|
1774
2766
|
/**
|
|
1775
2767
|
* Watch for changes on `filename`. The callback `listener` will be called each time the file is accessed.
|
|
1776
2768
|
* @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
|
|
1777
2769
|
*/
|
|
1778
2770
|
export function watchFile(filename: PathLike, listener: (curr: Stats, prev: Stats) => void): void;
|
|
1779
|
-
|
|
1780
2771
|
/**
|
|
1781
|
-
* Stop watching for changes on `filename`.
|
|
1782
|
-
*
|
|
2772
|
+
* Stop watching for changes on `filename`. If `listener` is specified, only that
|
|
2773
|
+
* particular listener is removed. Otherwise, _all_ listeners are removed,
|
|
2774
|
+
* effectively stopping watching of `filename`.
|
|
2775
|
+
*
|
|
2776
|
+
* Calling `fs.unwatchFile()` with a filename that is not being watched is a
|
|
2777
|
+
* no-op, not an error.
|
|
2778
|
+
*
|
|
2779
|
+
* Using {@link watch} is more efficient than `fs.watchFile()` and`fs.unwatchFile()`. `fs.watch()` should be used instead of `fs.watchFile()`and `fs.unwatchFile()` when possible.
|
|
2780
|
+
* @since v0.1.31
|
|
2781
|
+
* @param listener Optional, a listener previously attached using `fs.watchFile()`
|
|
1783
2782
|
*/
|
|
1784
2783
|
export function unwatchFile(filename: PathLike, listener?: (curr: Stats, prev: Stats) => void): void;
|
|
1785
|
-
|
|
1786
2784
|
export interface WatchOptions extends Abortable {
|
|
1787
|
-
encoding?: BufferEncoding |
|
|
2785
|
+
encoding?: BufferEncoding | 'buffer' | undefined;
|
|
1788
2786
|
persistent?: boolean | undefined;
|
|
1789
2787
|
recursive?: boolean | undefined;
|
|
1790
2788
|
}
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
*
|
|
1796
|
-
*
|
|
1797
|
-
*
|
|
1798
|
-
*
|
|
1799
|
-
*
|
|
1800
|
-
*
|
|
2789
|
+
export type WatchListener<T> = (event: 'rename' | 'change', filename: T) => void;
|
|
2790
|
+
/**
|
|
2791
|
+
* Watch for changes on `filename`, where `filename` is either a file or a
|
|
2792
|
+
* directory.
|
|
2793
|
+
*
|
|
2794
|
+
* The second argument is optional. If `options` is provided as a string, it
|
|
2795
|
+
* specifies the `encoding`. Otherwise `options` should be passed as an object.
|
|
2796
|
+
*
|
|
2797
|
+
* The listener callback gets two arguments `(eventType, filename)`. `eventType`is either `'rename'` or `'change'`, and `filename` is the name of the file
|
|
2798
|
+
* which triggered the event.
|
|
2799
|
+
*
|
|
2800
|
+
* On most platforms, `'rename'` is emitted whenever a filename appears or
|
|
2801
|
+
* disappears in the directory.
|
|
2802
|
+
*
|
|
2803
|
+
* The listener callback is attached to the `'change'` event fired by `<fs.FSWatcher>`, but it is not the same thing as the `'change'` value of`eventType`.
|
|
2804
|
+
*
|
|
2805
|
+
* If a `signal` is passed, aborting the corresponding AbortController will close
|
|
2806
|
+
* the returned `<fs.FSWatcher>`.
|
|
2807
|
+
* @since v0.5.10
|
|
1801
2808
|
*/
|
|
1802
|
-
export function watch(
|
|
1803
|
-
|
|
2809
|
+
export function watch(
|
|
2810
|
+
filename: PathLike,
|
|
2811
|
+
options:
|
|
2812
|
+
| (WatchOptions & {
|
|
2813
|
+
encoding: 'buffer';
|
|
2814
|
+
})
|
|
2815
|
+
| 'buffer',
|
|
2816
|
+
listener?: WatchListener<Buffer>
|
|
2817
|
+
): FSWatcher;
|
|
1804
2818
|
/**
|
|
1805
2819
|
* Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`.
|
|
1806
2820
|
* @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
|
|
@@ -1809,12 +2823,7 @@ declare module 'fs' {
|
|
|
1809
2823
|
* If `persistent` is not supplied, the default of `true` is used.
|
|
1810
2824
|
* If `recursive` is not supplied, the default of `false` is used.
|
|
1811
2825
|
*/
|
|
1812
|
-
export function watch(
|
|
1813
|
-
filename: PathLike,
|
|
1814
|
-
options?: WatchOptions | BufferEncoding | null,
|
|
1815
|
-
listener?: WatchListener<string>,
|
|
1816
|
-
): FSWatcher;
|
|
1817
|
-
|
|
2826
|
+
export function watch(filename: PathLike, options?: WatchOptions | BufferEncoding | null, listener?: WatchListener<string>): FSWatcher;
|
|
1818
2827
|
/**
|
|
1819
2828
|
* Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`.
|
|
1820
2829
|
* @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
|
|
@@ -1824,21 +2833,141 @@ declare module 'fs' {
|
|
|
1824
2833
|
* If `recursive` is not supplied, the default of `false` is used.
|
|
1825
2834
|
*/
|
|
1826
2835
|
export function watch(filename: PathLike, options: WatchOptions | string, listener?: WatchListener<string | Buffer>): FSWatcher;
|
|
1827
|
-
|
|
1828
2836
|
/**
|
|
1829
2837
|
* Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`.
|
|
1830
2838
|
* @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
|
|
1831
2839
|
*/
|
|
1832
2840
|
export function watch(filename: PathLike, listener?: WatchListener<string>): FSWatcher;
|
|
1833
|
-
|
|
1834
2841
|
/**
|
|
1835
|
-
*
|
|
1836
|
-
*
|
|
1837
|
-
*
|
|
2842
|
+
* Test whether or not the given path exists by checking with the file system.
|
|
2843
|
+
* Then call the `callback` argument with either true or false:
|
|
2844
|
+
*
|
|
2845
|
+
* ```js
|
|
2846
|
+
* import { exists } from 'fs';
|
|
2847
|
+
*
|
|
2848
|
+
* exists('/etc/passwd', (e) => {
|
|
2849
|
+
* console.log(e ? 'it exists' : 'no passwd!');
|
|
2850
|
+
* });
|
|
2851
|
+
* ```
|
|
2852
|
+
*
|
|
2853
|
+
* **The parameters for this callback are not consistent with other Node.js**
|
|
2854
|
+
* **callbacks.** Normally, the first parameter to a Node.js callback is an `err`parameter, optionally followed by other parameters. The `fs.exists()` callback
|
|
2855
|
+
* has only one boolean parameter. This is one reason `fs.access()` is recommended
|
|
2856
|
+
* instead of `fs.exists()`.
|
|
2857
|
+
*
|
|
2858
|
+
* Using `fs.exists()` to check for the existence of a file before calling`fs.open()`, `fs.readFile()` or `fs.writeFile()` is not recommended. Doing
|
|
2859
|
+
* so introduces a race condition, since other processes may change the file's
|
|
2860
|
+
* state between the two calls. Instead, user code should open/read/write the
|
|
2861
|
+
* file directly and handle the error raised if the file does not exist.
|
|
2862
|
+
*
|
|
2863
|
+
* **write (NOT RECOMMENDED)**
|
|
2864
|
+
*
|
|
2865
|
+
* ```js
|
|
2866
|
+
* import { exists, open, close } from 'fs';
|
|
2867
|
+
*
|
|
2868
|
+
* exists('myfile', (e) => {
|
|
2869
|
+
* if (e) {
|
|
2870
|
+
* console.error('myfile already exists');
|
|
2871
|
+
* } else {
|
|
2872
|
+
* open('myfile', 'wx', (err, fd) => {
|
|
2873
|
+
* if (err) throw err;
|
|
2874
|
+
*
|
|
2875
|
+
* try {
|
|
2876
|
+
* writeMyData(fd);
|
|
2877
|
+
* } finally {
|
|
2878
|
+
* close(fd, (err) => {
|
|
2879
|
+
* if (err) throw err;
|
|
2880
|
+
* });
|
|
2881
|
+
* }
|
|
2882
|
+
* });
|
|
2883
|
+
* }
|
|
2884
|
+
* });
|
|
2885
|
+
* ```
|
|
2886
|
+
*
|
|
2887
|
+
* **write (RECOMMENDED)**
|
|
2888
|
+
*
|
|
2889
|
+
* ```js
|
|
2890
|
+
* import { open, close } from 'fs';
|
|
2891
|
+
* open('myfile', 'wx', (err, fd) => {
|
|
2892
|
+
* if (err) {
|
|
2893
|
+
* if (err.code === 'EEXIST') {
|
|
2894
|
+
* console.error('myfile already exists');
|
|
2895
|
+
* return;
|
|
2896
|
+
* }
|
|
2897
|
+
*
|
|
2898
|
+
* throw err;
|
|
2899
|
+
* }
|
|
2900
|
+
*
|
|
2901
|
+
* try {
|
|
2902
|
+
* writeMyData(fd);
|
|
2903
|
+
* } finally {
|
|
2904
|
+
* close(fd, (err) => {
|
|
2905
|
+
* if (err) throw err;
|
|
2906
|
+
* });
|
|
2907
|
+
* }
|
|
2908
|
+
* });
|
|
2909
|
+
* ```
|
|
2910
|
+
*
|
|
2911
|
+
* **read (NOT RECOMMENDED)**
|
|
2912
|
+
*
|
|
2913
|
+
* ```js
|
|
2914
|
+
* import { open, close, exists } from 'fs';
|
|
2915
|
+
*
|
|
2916
|
+
* exists('myfile', (e) => {
|
|
2917
|
+
* if (e) {
|
|
2918
|
+
* open('myfile', 'r', (err, fd) => {
|
|
2919
|
+
* if (err) throw err;
|
|
2920
|
+
*
|
|
2921
|
+
* try {
|
|
2922
|
+
* readMyData(fd);
|
|
2923
|
+
* } finally {
|
|
2924
|
+
* close(fd, (err) => {
|
|
2925
|
+
* if (err) throw err;
|
|
2926
|
+
* });
|
|
2927
|
+
* }
|
|
2928
|
+
* });
|
|
2929
|
+
* } else {
|
|
2930
|
+
* console.error('myfile does not exist');
|
|
2931
|
+
* }
|
|
2932
|
+
* });
|
|
2933
|
+
* ```
|
|
2934
|
+
*
|
|
2935
|
+
* **read (RECOMMENDED)**
|
|
2936
|
+
*
|
|
2937
|
+
* ```js
|
|
2938
|
+
* import { open, close } from 'fs';
|
|
2939
|
+
*
|
|
2940
|
+
* open('myfile', 'r', (err, fd) => {
|
|
2941
|
+
* if (err) {
|
|
2942
|
+
* if (err.code === 'ENOENT') {
|
|
2943
|
+
* console.error('myfile does not exist');
|
|
2944
|
+
* return;
|
|
2945
|
+
* }
|
|
2946
|
+
*
|
|
2947
|
+
* throw err;
|
|
2948
|
+
* }
|
|
2949
|
+
*
|
|
2950
|
+
* try {
|
|
2951
|
+
* readMyData(fd);
|
|
2952
|
+
* } finally {
|
|
2953
|
+
* close(fd, (err) => {
|
|
2954
|
+
* if (err) throw err;
|
|
2955
|
+
* });
|
|
2956
|
+
* }
|
|
2957
|
+
* });
|
|
2958
|
+
* ```
|
|
2959
|
+
*
|
|
2960
|
+
* The "not recommended" examples above check for existence and then use the
|
|
2961
|
+
* file; the "recommended" examples are better because they use the file directly
|
|
2962
|
+
* and handle the error, if any.
|
|
2963
|
+
*
|
|
2964
|
+
* In general, check for the existence of a file only if the file won’t be
|
|
2965
|
+
* used directly, for example when its existence is a signal from another
|
|
2966
|
+
* process.
|
|
2967
|
+
* @since v0.0.2
|
|
2968
|
+
* @deprecated Since v1.0.0 - Use {@link stat} or {@link access} instead.
|
|
1838
2969
|
*/
|
|
1839
2970
|
export function exists(path: PathLike, callback: (exists: boolean) => void): void;
|
|
1840
|
-
|
|
1841
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
1842
2971
|
export namespace exists {
|
|
1843
2972
|
/**
|
|
1844
2973
|
* @param path A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
|
|
@@ -1846,78 +2975,70 @@ declare module 'fs' {
|
|
|
1846
2975
|
*/
|
|
1847
2976
|
function __promisify__(path: PathLike): Promise<boolean>;
|
|
1848
2977
|
}
|
|
1849
|
-
|
|
1850
2978
|
/**
|
|
1851
|
-
*
|
|
1852
|
-
*
|
|
2979
|
+
* Returns `true` if the path exists, `false` otherwise.
|
|
2980
|
+
*
|
|
2981
|
+
* For detailed information, see the documentation of the asynchronous version of
|
|
2982
|
+
* this API: {@link exists}.
|
|
2983
|
+
*
|
|
2984
|
+
* `fs.exists()` is deprecated, but `fs.existsSync()` is not. The `callback`parameter to `fs.exists()` accepts parameters that are inconsistent with other
|
|
2985
|
+
* Node.js callbacks. `fs.existsSync()` does not use a callback.
|
|
2986
|
+
*
|
|
2987
|
+
* ```js
|
|
2988
|
+
* import { existsSync } from 'fs';
|
|
2989
|
+
*
|
|
2990
|
+
* if (existsSync('/etc/passwd'))
|
|
2991
|
+
* console.log('The path exists.');
|
|
2992
|
+
* ```
|
|
2993
|
+
* @since v0.1.21
|
|
1853
2994
|
*/
|
|
1854
2995
|
export function existsSync(path: PathLike): boolean;
|
|
1855
|
-
|
|
1856
2996
|
export namespace constants {
|
|
1857
2997
|
// File Access Constants
|
|
1858
|
-
|
|
1859
2998
|
/** Constant for fs.access(). File is visible to the calling process. */
|
|
1860
2999
|
const F_OK: number;
|
|
1861
|
-
|
|
1862
3000
|
/** Constant for fs.access(). File can be read by the calling process. */
|
|
1863
3001
|
const R_OK: number;
|
|
1864
|
-
|
|
1865
3002
|
/** Constant for fs.access(). File can be written by the calling process. */
|
|
1866
3003
|
const W_OK: number;
|
|
1867
|
-
|
|
1868
3004
|
/** Constant for fs.access(). File can be executed by the calling process. */
|
|
1869
3005
|
const X_OK: number;
|
|
1870
|
-
|
|
1871
3006
|
// File Copy Constants
|
|
1872
|
-
|
|
1873
3007
|
/** Constant for fs.copyFile. Flag indicating the destination file should not be overwritten if it already exists. */
|
|
1874
3008
|
const COPYFILE_EXCL: number;
|
|
1875
|
-
|
|
1876
3009
|
/**
|
|
1877
3010
|
* Constant for fs.copyFile. copy operation will attempt to create a copy-on-write reflink.
|
|
1878
3011
|
* If the underlying platform does not support copy-on-write, then a fallback copy mechanism is used.
|
|
1879
3012
|
*/
|
|
1880
3013
|
const COPYFILE_FICLONE: number;
|
|
1881
|
-
|
|
1882
3014
|
/**
|
|
1883
3015
|
* Constant for fs.copyFile. Copy operation will attempt to create a copy-on-write reflink.
|
|
1884
3016
|
* If the underlying platform does not support copy-on-write, then the operation will fail with an error.
|
|
1885
3017
|
*/
|
|
1886
3018
|
const COPYFILE_FICLONE_FORCE: number;
|
|
1887
|
-
|
|
1888
3019
|
// File Open Constants
|
|
1889
|
-
|
|
1890
3020
|
/** Constant for fs.open(). Flag indicating to open a file for read-only access. */
|
|
1891
3021
|
const O_RDONLY: number;
|
|
1892
|
-
|
|
1893
3022
|
/** Constant for fs.open(). Flag indicating to open a file for write-only access. */
|
|
1894
3023
|
const O_WRONLY: number;
|
|
1895
|
-
|
|
1896
3024
|
/** Constant for fs.open(). Flag indicating to open a file for read-write access. */
|
|
1897
3025
|
const O_RDWR: number;
|
|
1898
|
-
|
|
1899
3026
|
/** Constant for fs.open(). Flag indicating to create the file if it does not already exist. */
|
|
1900
3027
|
const O_CREAT: number;
|
|
1901
|
-
|
|
1902
3028
|
/** Constant for fs.open(). Flag indicating that opening a file should fail if the O_CREAT flag is set and the file already exists. */
|
|
1903
3029
|
const O_EXCL: number;
|
|
1904
|
-
|
|
1905
3030
|
/**
|
|
1906
3031
|
* Constant for fs.open(). Flag indicating that if path identifies a terminal device,
|
|
1907
3032
|
* opening the path shall not cause that terminal to become the controlling terminal for the process
|
|
1908
3033
|
* (if the process does not already have one).
|
|
1909
3034
|
*/
|
|
1910
3035
|
const O_NOCTTY: number;
|
|
1911
|
-
|
|
1912
3036
|
/** Constant for fs.open(). Flag indicating that if the file exists and is a regular file, and the file is opened successfully for write access, its length shall be truncated to zero. */
|
|
1913
3037
|
const O_TRUNC: number;
|
|
1914
|
-
|
|
1915
3038
|
/** Constant for fs.open(). Flag indicating that data will be appended to the end of the file. */
|
|
1916
3039
|
const O_APPEND: number;
|
|
1917
|
-
|
|
1918
3040
|
/** Constant for fs.open(). Flag indicating that the open should fail if the path is not a directory. */
|
|
1919
3041
|
const O_DIRECTORY: number;
|
|
1920
|
-
|
|
1921
3042
|
/**
|
|
1922
3043
|
* constant for fs.open().
|
|
1923
3044
|
* Flag indicating reading accesses to the file system will no longer result in
|
|
@@ -1925,89 +3046,60 @@ declare module 'fs' {
|
|
|
1925
3046
|
* This flag is available on Linux operating systems only.
|
|
1926
3047
|
*/
|
|
1927
3048
|
const O_NOATIME: number;
|
|
1928
|
-
|
|
1929
3049
|
/** Constant for fs.open(). Flag indicating that the open should fail if the path is a symbolic link. */
|
|
1930
3050
|
const O_NOFOLLOW: number;
|
|
1931
|
-
|
|
1932
3051
|
/** Constant for fs.open(). Flag indicating that the file is opened for synchronous I/O. */
|
|
1933
3052
|
const O_SYNC: number;
|
|
1934
|
-
|
|
1935
3053
|
/** Constant for fs.open(). Flag indicating that the file is opened for synchronous I/O with write operations waiting for data integrity. */
|
|
1936
3054
|
const O_DSYNC: number;
|
|
1937
|
-
|
|
1938
3055
|
/** Constant for fs.open(). Flag indicating to open the symbolic link itself rather than the resource it is pointing to. */
|
|
1939
3056
|
const O_SYMLINK: number;
|
|
1940
|
-
|
|
1941
3057
|
/** Constant for fs.open(). When set, an attempt will be made to minimize caching effects of file I/O. */
|
|
1942
3058
|
const O_DIRECT: number;
|
|
1943
|
-
|
|
1944
3059
|
/** Constant for fs.open(). Flag indicating to open the file in nonblocking mode when possible. */
|
|
1945
3060
|
const O_NONBLOCK: number;
|
|
1946
|
-
|
|
1947
3061
|
// File Type Constants
|
|
1948
|
-
|
|
1949
3062
|
/** Constant for fs.Stats mode property for determining a file's type. Bit mask used to extract the file type code. */
|
|
1950
3063
|
const S_IFMT: number;
|
|
1951
|
-
|
|
1952
3064
|
/** Constant for fs.Stats mode property for determining a file's type. File type constant for a regular file. */
|
|
1953
3065
|
const S_IFREG: number;
|
|
1954
|
-
|
|
1955
3066
|
/** Constant for fs.Stats mode property for determining a file's type. File type constant for a directory. */
|
|
1956
3067
|
const S_IFDIR: number;
|
|
1957
|
-
|
|
1958
3068
|
/** Constant for fs.Stats mode property for determining a file's type. File type constant for a character-oriented device file. */
|
|
1959
3069
|
const S_IFCHR: number;
|
|
1960
|
-
|
|
1961
3070
|
/** Constant for fs.Stats mode property for determining a file's type. File type constant for a block-oriented device file. */
|
|
1962
3071
|
const S_IFBLK: number;
|
|
1963
|
-
|
|
1964
3072
|
/** Constant for fs.Stats mode property for determining a file's type. File type constant for a FIFO/pipe. */
|
|
1965
3073
|
const S_IFIFO: number;
|
|
1966
|
-
|
|
1967
3074
|
/** Constant for fs.Stats mode property for determining a file's type. File type constant for a symbolic link. */
|
|
1968
3075
|
const S_IFLNK: number;
|
|
1969
|
-
|
|
1970
3076
|
/** Constant for fs.Stats mode property for determining a file's type. File type constant for a socket. */
|
|
1971
3077
|
const S_IFSOCK: number;
|
|
1972
|
-
|
|
1973
3078
|
// File Mode Constants
|
|
1974
|
-
|
|
1975
3079
|
/** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable, writable and executable by owner. */
|
|
1976
3080
|
const S_IRWXU: number;
|
|
1977
|
-
|
|
1978
3081
|
/** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable by owner. */
|
|
1979
3082
|
const S_IRUSR: number;
|
|
1980
|
-
|
|
1981
3083
|
/** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating writable by owner. */
|
|
1982
3084
|
const S_IWUSR: number;
|
|
1983
|
-
|
|
1984
3085
|
/** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating executable by owner. */
|
|
1985
3086
|
const S_IXUSR: number;
|
|
1986
|
-
|
|
1987
3087
|
/** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable, writable and executable by group. */
|
|
1988
3088
|
const S_IRWXG: number;
|
|
1989
|
-
|
|
1990
3089
|
/** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable by group. */
|
|
1991
3090
|
const S_IRGRP: number;
|
|
1992
|
-
|
|
1993
3091
|
/** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating writable by group. */
|
|
1994
3092
|
const S_IWGRP: number;
|
|
1995
|
-
|
|
1996
3093
|
/** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating executable by group. */
|
|
1997
3094
|
const S_IXGRP: number;
|
|
1998
|
-
|
|
1999
3095
|
/** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable, writable and executable by others. */
|
|
2000
3096
|
const S_IRWXO: number;
|
|
2001
|
-
|
|
2002
3097
|
/** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable by others. */
|
|
2003
3098
|
const S_IROTH: number;
|
|
2004
|
-
|
|
2005
3099
|
/** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating writable by others. */
|
|
2006
3100
|
const S_IWOTH: number;
|
|
2007
|
-
|
|
2008
3101
|
/** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating executable by others. */
|
|
2009
3102
|
const S_IXOTH: number;
|
|
2010
|
-
|
|
2011
3103
|
/**
|
|
2012
3104
|
* When set, a memory file mapping is used to access the file. This flag
|
|
2013
3105
|
* is available on Windows operating systems only. On other operating systems,
|
|
@@ -2015,20 +3107,176 @@ declare module 'fs' {
|
|
|
2015
3107
|
*/
|
|
2016
3108
|
const UV_FS_O_FILEMAP: number;
|
|
2017
3109
|
}
|
|
2018
|
-
|
|
2019
3110
|
/**
|
|
2020
|
-
*
|
|
2021
|
-
*
|
|
3111
|
+
* Tests a user's permissions for the file or directory specified by `path`.
|
|
3112
|
+
* The `mode` argument is an optional integer that specifies the accessibility
|
|
3113
|
+
* checks to be performed. Check `File access constants` for possible values
|
|
3114
|
+
* of `mode`. It is possible to create a mask consisting of the bitwise OR of
|
|
3115
|
+
* two or more values (e.g. `fs.constants.W_OK | fs.constants.R_OK`).
|
|
3116
|
+
*
|
|
3117
|
+
* The final argument, `callback`, is a callback function that is invoked with
|
|
3118
|
+
* a possible error argument. If any of the accessibility checks fail, the error
|
|
3119
|
+
* argument will be an `Error` object. The following examples check if`package.json` exists, and if it is readable or writable.
|
|
3120
|
+
*
|
|
3121
|
+
* ```js
|
|
3122
|
+
* import { access, constants } from 'fs';
|
|
3123
|
+
*
|
|
3124
|
+
* const file = 'package.json';
|
|
3125
|
+
*
|
|
3126
|
+
* // Check if the file exists in the current directory.
|
|
3127
|
+
* access(file, constants.F_OK, (err) => {
|
|
3128
|
+
* console.log(`${file} ${err ? 'does not exist' : 'exists'}`);
|
|
3129
|
+
* });
|
|
3130
|
+
*
|
|
3131
|
+
* // Check if the file is readable.
|
|
3132
|
+
* access(file, constants.R_OK, (err) => {
|
|
3133
|
+
* console.log(`${file} ${err ? 'is not readable' : 'is readable'}`);
|
|
3134
|
+
* });
|
|
3135
|
+
*
|
|
3136
|
+
* // Check if the file is writable.
|
|
3137
|
+
* access(file, constants.W_OK, (err) => {
|
|
3138
|
+
* console.log(`${file} ${err ? 'is not writable' : 'is writable'}`);
|
|
3139
|
+
* });
|
|
3140
|
+
*
|
|
3141
|
+
* // Check if the file exists in the current directory, and if it is writable.
|
|
3142
|
+
* access(file, constants.F_OK | fs.constants.W_OK, (err) => {
|
|
3143
|
+
* if (err) {
|
|
3144
|
+
* console.error(
|
|
3145
|
+
* `${file} ${err.code === 'ENOENT' ? 'does not exist' : 'is read-only'}`);
|
|
3146
|
+
* } else {
|
|
3147
|
+
* console.log(`${file} exists, and it is writable`);
|
|
3148
|
+
* }
|
|
3149
|
+
* });
|
|
3150
|
+
* ```
|
|
3151
|
+
*
|
|
3152
|
+
* Do not use `fs.access()` to check for the accessibility of a file before calling`fs.open()`, `fs.readFile()` or `fs.writeFile()`. Doing
|
|
3153
|
+
* so introduces a race condition, since other processes may change the file's
|
|
3154
|
+
* state between the two calls. Instead, user code should open/read/write the
|
|
3155
|
+
* file directly and handle the error raised if the file is not accessible.
|
|
3156
|
+
*
|
|
3157
|
+
* **write (NOT RECOMMENDED)**
|
|
3158
|
+
*
|
|
3159
|
+
* ```js
|
|
3160
|
+
* import { access, open, close } from 'fs';
|
|
3161
|
+
*
|
|
3162
|
+
* access('myfile', (err) => {
|
|
3163
|
+
* if (!err) {
|
|
3164
|
+
* console.error('myfile already exists');
|
|
3165
|
+
* return;
|
|
3166
|
+
* }
|
|
3167
|
+
*
|
|
3168
|
+
* open('myfile', 'wx', (err, fd) => {
|
|
3169
|
+
* if (err) throw err;
|
|
3170
|
+
*
|
|
3171
|
+
* try {
|
|
3172
|
+
* writeMyData(fd);
|
|
3173
|
+
* } finally {
|
|
3174
|
+
* close(fd, (err) => {
|
|
3175
|
+
* if (err) throw err;
|
|
3176
|
+
* });
|
|
3177
|
+
* }
|
|
3178
|
+
* });
|
|
3179
|
+
* });
|
|
3180
|
+
* ```
|
|
3181
|
+
*
|
|
3182
|
+
* **write (RECOMMENDED)**
|
|
3183
|
+
*
|
|
3184
|
+
* ```js
|
|
3185
|
+
* import { open, close } from 'fs';
|
|
3186
|
+
*
|
|
3187
|
+
* open('myfile', 'wx', (err, fd) => {
|
|
3188
|
+
* if (err) {
|
|
3189
|
+
* if (err.code === 'EEXIST') {
|
|
3190
|
+
* console.error('myfile already exists');
|
|
3191
|
+
* return;
|
|
3192
|
+
* }
|
|
3193
|
+
*
|
|
3194
|
+
* throw err;
|
|
3195
|
+
* }
|
|
3196
|
+
*
|
|
3197
|
+
* try {
|
|
3198
|
+
* writeMyData(fd);
|
|
3199
|
+
* } finally {
|
|
3200
|
+
* close(fd, (err) => {
|
|
3201
|
+
* if (err) throw err;
|
|
3202
|
+
* });
|
|
3203
|
+
* }
|
|
3204
|
+
* });
|
|
3205
|
+
* ```
|
|
3206
|
+
*
|
|
3207
|
+
* **read (NOT RECOMMENDED)**
|
|
3208
|
+
*
|
|
3209
|
+
* ```js
|
|
3210
|
+
* import { access, open, close } from 'fs';
|
|
3211
|
+
* access('myfile', (err) => {
|
|
3212
|
+
* if (err) {
|
|
3213
|
+
* if (err.code === 'ENOENT') {
|
|
3214
|
+
* console.error('myfile does not exist');
|
|
3215
|
+
* return;
|
|
3216
|
+
* }
|
|
3217
|
+
*
|
|
3218
|
+
* throw err;
|
|
3219
|
+
* }
|
|
3220
|
+
*
|
|
3221
|
+
* open('myfile', 'r', (err, fd) => {
|
|
3222
|
+
* if (err) throw err;
|
|
3223
|
+
*
|
|
3224
|
+
* try {
|
|
3225
|
+
* readMyData(fd);
|
|
3226
|
+
* } finally {
|
|
3227
|
+
* close(fd, (err) => {
|
|
3228
|
+
* if (err) throw err;
|
|
3229
|
+
* });
|
|
3230
|
+
* }
|
|
3231
|
+
* });
|
|
3232
|
+
* });
|
|
3233
|
+
* ```
|
|
3234
|
+
*
|
|
3235
|
+
* **read (RECOMMENDED)**
|
|
3236
|
+
*
|
|
3237
|
+
* ```js
|
|
3238
|
+
* import { open, close } from 'fs';
|
|
3239
|
+
*
|
|
3240
|
+
* open('myfile', 'r', (err, fd) => {
|
|
3241
|
+
* if (err) {
|
|
3242
|
+
* if (err.code === 'ENOENT') {
|
|
3243
|
+
* console.error('myfile does not exist');
|
|
3244
|
+
* return;
|
|
3245
|
+
* }
|
|
3246
|
+
*
|
|
3247
|
+
* throw err;
|
|
3248
|
+
* }
|
|
3249
|
+
*
|
|
3250
|
+
* try {
|
|
3251
|
+
* readMyData(fd);
|
|
3252
|
+
* } finally {
|
|
3253
|
+
* close(fd, (err) => {
|
|
3254
|
+
* if (err) throw err;
|
|
3255
|
+
* });
|
|
3256
|
+
* }
|
|
3257
|
+
* });
|
|
3258
|
+
* ```
|
|
3259
|
+
*
|
|
3260
|
+
* The "not recommended" examples above check for accessibility and then use the
|
|
3261
|
+
* file; the "recommended" examples are better because they use the file directly
|
|
3262
|
+
* and handle the error, if any.
|
|
3263
|
+
*
|
|
3264
|
+
* In general, check for the accessibility of a file only if the file will not be
|
|
3265
|
+
* used directly, for example when its accessibility is a signal from another
|
|
3266
|
+
* process.
|
|
3267
|
+
*
|
|
3268
|
+
* On Windows, access-control policies (ACLs) on a directory may limit access to
|
|
3269
|
+
* a file or directory. The `fs.access()` function, however, does not check the
|
|
3270
|
+
* ACL and therefore may report that a path is accessible even if the ACL restricts
|
|
3271
|
+
* the user from reading or writing to it.
|
|
3272
|
+
* @since v0.11.15
|
|
2022
3273
|
*/
|
|
2023
3274
|
export function access(path: PathLike, mode: number | undefined, callback: NoParamCallback): void;
|
|
2024
|
-
|
|
2025
3275
|
/**
|
|
2026
3276
|
* Asynchronously tests a user's permissions for the file specified by path.
|
|
2027
3277
|
* @param path A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
|
|
2028
3278
|
*/
|
|
2029
3279
|
export function access(path: PathLike, callback: NoParamCallback): void;
|
|
2030
|
-
|
|
2031
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
2032
3280
|
export namespace access {
|
|
2033
3281
|
/**
|
|
2034
3282
|
* Asynchronously tests a user's permissions for the file specified by path.
|
|
@@ -2037,13 +3285,30 @@ declare module 'fs' {
|
|
|
2037
3285
|
*/
|
|
2038
3286
|
function __promisify__(path: PathLike, mode?: number): Promise<void>;
|
|
2039
3287
|
}
|
|
2040
|
-
|
|
2041
3288
|
/**
|
|
2042
|
-
* Synchronously tests a user's permissions for the file
|
|
2043
|
-
*
|
|
3289
|
+
* Synchronously tests a user's permissions for the file or directory specified
|
|
3290
|
+
* by `path`. The `mode` argument is an optional integer that specifies the
|
|
3291
|
+
* accessibility checks to be performed. Check `File access constants` for
|
|
3292
|
+
* possible values of `mode`. It is possible to create a mask consisting of
|
|
3293
|
+
* the bitwise OR of two or more values
|
|
3294
|
+
* (e.g. `fs.constants.W_OK | fs.constants.R_OK`).
|
|
3295
|
+
*
|
|
3296
|
+
* If any of the accessibility checks fail, an `Error` will be thrown. Otherwise,
|
|
3297
|
+
* the method will return `undefined`.
|
|
3298
|
+
*
|
|
3299
|
+
* ```js
|
|
3300
|
+
* import { accessSync, constants } from 'fs';
|
|
3301
|
+
*
|
|
3302
|
+
* try {
|
|
3303
|
+
* accessSync('etc/passwd', constants.R_OK | constants.W_OK);
|
|
3304
|
+
* console.log('can read/write');
|
|
3305
|
+
* } catch (err) {
|
|
3306
|
+
* console.error('no access!');
|
|
3307
|
+
* }
|
|
3308
|
+
* ```
|
|
3309
|
+
* @since v0.11.15
|
|
2044
3310
|
*/
|
|
2045
3311
|
export function accessSync(path: PathLike, mode?: number): void;
|
|
2046
|
-
|
|
2047
3312
|
interface StreamOptions {
|
|
2048
3313
|
flags?: string | undefined;
|
|
2049
3314
|
encoding?: BufferEncoding | undefined;
|
|
@@ -2057,30 +3322,110 @@ declare module 'fs' {
|
|
|
2057
3322
|
start?: number | undefined;
|
|
2058
3323
|
highWaterMark?: number | undefined;
|
|
2059
3324
|
}
|
|
2060
|
-
|
|
2061
3325
|
interface ReadStreamOptions extends StreamOptions {
|
|
2062
3326
|
end?: number | undefined;
|
|
2063
3327
|
}
|
|
2064
|
-
|
|
2065
3328
|
/**
|
|
2066
|
-
*
|
|
2067
|
-
*
|
|
3329
|
+
* Unlike the 16 kb default `highWaterMark` for a readable stream, the stream
|
|
3330
|
+
* returned by this method has a default `highWaterMark` of 64 kb.
|
|
3331
|
+
*
|
|
3332
|
+
* `options` can include `start` and `end` values to read a range of bytes from
|
|
3333
|
+
* the file instead of the entire file. Both `start` and `end` are inclusive and
|
|
3334
|
+
* start counting at 0, allowed values are in the
|
|
3335
|
+
* \[0, [`Number.MAX_SAFE_INTEGER`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER)\] range. If `fd` is specified and `start` is
|
|
3336
|
+
* omitted or `undefined`, `fs.createReadStream()` reads sequentially from the
|
|
3337
|
+
* current file position. The `encoding` can be any one of those accepted by `<Buffer>`.
|
|
3338
|
+
*
|
|
3339
|
+
* If `fd` is specified, `ReadStream` will ignore the `path` argument and will use
|
|
3340
|
+
* the specified file descriptor. This means that no `'open'` event will be
|
|
3341
|
+
* emitted. `fd` should be blocking; non-blocking `fd`s should be passed to `<net.Socket>`.
|
|
3342
|
+
*
|
|
3343
|
+
* If `fd` points to a character device that only supports blocking reads
|
|
3344
|
+
* (such as keyboard or sound card), read operations do not finish until data is
|
|
3345
|
+
* available. This can prevent the process from exiting and the stream from
|
|
3346
|
+
* closing naturally.
|
|
3347
|
+
*
|
|
3348
|
+
* By default, the stream will emit a `'close'` event after it has been
|
|
3349
|
+
* destroyed, like most `Readable` streams. Set the `emitClose` option to`false` to change this behavior.
|
|
3350
|
+
*
|
|
3351
|
+
* By providing the `fs` option, it is possible to override the corresponding `fs`implementations for `open`, `read`, and `close`. When providing the `fs` option,
|
|
3352
|
+
* overrides for `open`, `read`, and `close` are required.
|
|
3353
|
+
*
|
|
3354
|
+
* ```js
|
|
3355
|
+
* import { createReadStream } from 'fs';
|
|
3356
|
+
*
|
|
3357
|
+
* // Create a stream from some character device.
|
|
3358
|
+
* const stream = createReadStream('/dev/input/event0');
|
|
3359
|
+
* setTimeout(() => {
|
|
3360
|
+
* stream.close(); // This may not close the stream.
|
|
3361
|
+
* // Artificially marking end-of-stream, as if the underlying resource had
|
|
3362
|
+
* // indicated end-of-file by itself, allows the stream to close.
|
|
3363
|
+
* // This does not cancel pending read operations, and if there is such an
|
|
3364
|
+
* // operation, the process may still not be able to exit successfully
|
|
3365
|
+
* // until it finishes.
|
|
3366
|
+
* stream.push(null);
|
|
3367
|
+
* stream.read(0);
|
|
3368
|
+
* }, 100);
|
|
3369
|
+
* ```
|
|
3370
|
+
*
|
|
3371
|
+
* If `autoClose` is false, then the file descriptor won't be closed, even if
|
|
3372
|
+
* there's an error. It is the application's responsibility to close it and make
|
|
3373
|
+
* sure there's no file descriptor leak. If `autoClose` is set to true (default
|
|
3374
|
+
* behavior), on `'error'` or `'end'` the file descriptor will be closed
|
|
3375
|
+
* automatically.
|
|
3376
|
+
*
|
|
3377
|
+
* `mode` sets the file mode (permission and sticky bits), but only if the
|
|
3378
|
+
* file was created.
|
|
3379
|
+
*
|
|
3380
|
+
* An example to read the last 10 bytes of a file which is 100 bytes long:
|
|
3381
|
+
*
|
|
3382
|
+
* ```js
|
|
3383
|
+
* import { createReadStream } from 'fs';
|
|
3384
|
+
*
|
|
3385
|
+
* createReadStream('sample.txt', { start: 90, end: 99 });
|
|
3386
|
+
* ```
|
|
3387
|
+
*
|
|
3388
|
+
* If `options` is a string, then it specifies the encoding.
|
|
3389
|
+
* @since v0.1.31
|
|
3390
|
+
* @return See `Readable Stream`.
|
|
2068
3391
|
*/
|
|
2069
3392
|
export function createReadStream(path: PathLike, options?: string | ReadStreamOptions): ReadStream;
|
|
2070
|
-
|
|
2071
3393
|
/**
|
|
2072
|
-
*
|
|
2073
|
-
*
|
|
3394
|
+
* `options` may also include a `start` option to allow writing data at some
|
|
3395
|
+
* position past the beginning of the file, allowed values are in the
|
|
3396
|
+
* \[0, [`Number.MAX_SAFE_INTEGER`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER)\] range. Modifying a file rather than replacing
|
|
3397
|
+
* it may require the `flags` option to be set to `r+` rather than the default `w`.
|
|
3398
|
+
* The `encoding` can be any one of those accepted by `<Buffer>`.
|
|
3399
|
+
*
|
|
3400
|
+
* If `autoClose` is set to true (default behavior) on `'error'` or `'finish'`the file descriptor will be closed automatically. If `autoClose` is false,
|
|
3401
|
+
* then the file descriptor won't be closed, even if there's an error.
|
|
3402
|
+
* It is the application's responsibility to close it and make sure there's no
|
|
3403
|
+
* file descriptor leak.
|
|
3404
|
+
*
|
|
3405
|
+
* By default, the stream will emit a `'close'` event after it has been
|
|
3406
|
+
* destroyed, like most `Writable` streams. Set the `emitClose` option to`false` to change this behavior.
|
|
3407
|
+
*
|
|
3408
|
+
* By providing the `fs` option it is possible to override the corresponding `fs`implementations for `open`, `write`, `writev` and `close`. Overriding `write()`without `writev()` can reduce
|
|
3409
|
+
* performance as some optimizations (`_writev()`)
|
|
3410
|
+
* will be disabled. When providing the `fs` option, overrides for `open`,`close`, and at least one of `write` and `writev` are required.
|
|
3411
|
+
*
|
|
3412
|
+
* Like `<fs.ReadStream>`, if `fd` is specified, `<fs.WriteStream>` will ignore the`path` argument and will use the specified file descriptor. This means that no`'open'` event will be
|
|
3413
|
+
* emitted. `fd` should be blocking; non-blocking `fd`s
|
|
3414
|
+
* should be passed to `<net.Socket>`.
|
|
3415
|
+
*
|
|
3416
|
+
* If `options` is a string, then it specifies the encoding.
|
|
3417
|
+
* @since v0.1.31
|
|
3418
|
+
* @return See `Writable Stream`.
|
|
2074
3419
|
*/
|
|
2075
3420
|
export function createWriteStream(path: PathLike, options?: string | StreamOptions): WriteStream;
|
|
2076
|
-
|
|
2077
3421
|
/**
|
|
2078
|
-
*
|
|
2079
|
-
*
|
|
3422
|
+
* Forces all currently queued I/O operations associated with the file to the
|
|
3423
|
+
* operating system's synchronized I/O completion state. Refer to the POSIX[`fdatasync(2)`](http://man7.org/linux/man-pages/man2/fdatasync.2.html) documentation for details. No arguments other
|
|
3424
|
+
* than a possible
|
|
3425
|
+
* exception are given to the completion callback.
|
|
3426
|
+
* @since v0.1.96
|
|
2080
3427
|
*/
|
|
2081
3428
|
export function fdatasync(fd: number, callback: NoParamCallback): void;
|
|
2082
|
-
|
|
2083
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
2084
3429
|
export namespace fdatasync {
|
|
2085
3430
|
/**
|
|
2086
3431
|
* Asynchronous fdatasync(2) - synchronize a file's in-core state with storage device.
|
|
@@ -2088,123 +3433,166 @@ declare module 'fs' {
|
|
|
2088
3433
|
*/
|
|
2089
3434
|
function __promisify__(fd: number): Promise<void>;
|
|
2090
3435
|
}
|
|
2091
|
-
|
|
2092
3436
|
/**
|
|
2093
|
-
*
|
|
2094
|
-
*
|
|
3437
|
+
* Forces all currently queued I/O operations associated with the file to the
|
|
3438
|
+
* operating system's synchronized I/O completion state. Refer to the POSIX[`fdatasync(2)`](http://man7.org/linux/man-pages/man2/fdatasync.2.html) documentation for details. Returns `undefined`.
|
|
3439
|
+
* @since v0.1.96
|
|
2095
3440
|
*/
|
|
2096
3441
|
export function fdatasyncSync(fd: number): void;
|
|
2097
|
-
|
|
2098
3442
|
/**
|
|
2099
|
-
* Asynchronously copies src to dest
|
|
2100
|
-
* No arguments other than a possible exception are given to the
|
|
2101
|
-
* Node.js makes no guarantees about the atomicity of the copy
|
|
2102
|
-
* If an error occurs after the destination file has been opened for
|
|
2103
|
-
* to remove the destination.
|
|
2104
|
-
*
|
|
2105
|
-
*
|
|
3443
|
+
* Asynchronously copies `src` to `dest`. By default, `dest` is overwritten if it
|
|
3444
|
+
* already exists. No arguments other than a possible exception are given to the
|
|
3445
|
+
* callback function. Node.js makes no guarantees about the atomicity of the copy
|
|
3446
|
+
* operation. If an error occurs after the destination file has been opened for
|
|
3447
|
+
* writing, Node.js will attempt to remove the destination.
|
|
3448
|
+
*
|
|
3449
|
+
* `mode` is an optional integer that specifies the behavior
|
|
3450
|
+
* of the copy operation. It is possible to create a mask consisting of the bitwise
|
|
3451
|
+
* OR of two or more values (e.g.`fs.constants.COPYFILE_EXCL | fs.constants.COPYFILE_FICLONE`).
|
|
3452
|
+
*
|
|
3453
|
+
* * `fs.constants.COPYFILE_EXCL`: The copy operation will fail if `dest` already
|
|
3454
|
+
* exists.
|
|
3455
|
+
* * `fs.constants.COPYFILE_FICLONE`: The copy operation will attempt to create a
|
|
3456
|
+
* copy-on-write reflink. If the platform does not support copy-on-write, then a
|
|
3457
|
+
* fallback copy mechanism is used.
|
|
3458
|
+
* * `fs.constants.COPYFILE_FICLONE_FORCE`: The copy operation will attempt to
|
|
3459
|
+
* create a copy-on-write reflink. If the platform does not support
|
|
3460
|
+
* copy-on-write, then the operation will fail.
|
|
3461
|
+
*
|
|
3462
|
+
* ```js
|
|
3463
|
+
* import { copyFile, constants } from 'fs';
|
|
3464
|
+
*
|
|
3465
|
+
* function callback(err) {
|
|
3466
|
+
* if (err) throw err;
|
|
3467
|
+
* console.log('source.txt was copied to destination.txt');
|
|
3468
|
+
* }
|
|
3469
|
+
*
|
|
3470
|
+
* // destination.txt will be created or overwritten by default.
|
|
3471
|
+
* copyFile('source.txt', 'destination.txt', callback);
|
|
3472
|
+
*
|
|
3473
|
+
* // By using COPYFILE_EXCL, the operation will fail if destination.txt exists.
|
|
3474
|
+
* copyFile('source.txt', 'destination.txt', constants.COPYFILE_EXCL, callback);
|
|
3475
|
+
* ```
|
|
3476
|
+
* @since v8.5.0
|
|
3477
|
+
* @param src source filename to copy
|
|
3478
|
+
* @param dest destination filename of the copy operation
|
|
3479
|
+
* @param mode modifiers for copy operation.
|
|
2106
3480
|
*/
|
|
2107
3481
|
export function copyFile(src: PathLike, dest: PathLike, callback: NoParamCallback): void;
|
|
2108
|
-
|
|
2109
|
-
* Asynchronously copies src to dest. By default, dest is overwritten if it already exists.
|
|
2110
|
-
* No arguments other than a possible exception are given to the callback function.
|
|
2111
|
-
* Node.js makes no guarantees about the atomicity of the copy operation.
|
|
2112
|
-
* If an error occurs after the destination file has been opened for writing, Node.js will attempt
|
|
2113
|
-
* to remove the destination.
|
|
2114
|
-
* @param src A path to the source file.
|
|
2115
|
-
* @param dest A path to the destination file.
|
|
2116
|
-
* @param flags An integer that specifies the behavior of the copy operation. The only supported flag is fs.constants.COPYFILE_EXCL, which causes the copy operation to fail if dest already exists.
|
|
2117
|
-
*/
|
|
2118
|
-
export function copyFile(src: PathLike, dest: PathLike, flags: number, callback: NoParamCallback): void;
|
|
2119
|
-
|
|
2120
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
3482
|
+
export function copyFile(src: PathLike, dest: PathLike, mode: number, callback: NoParamCallback): void;
|
|
2121
3483
|
export namespace copyFile {
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
*
|
|
2139
|
-
*
|
|
2140
|
-
*
|
|
2141
|
-
*
|
|
2142
|
-
*
|
|
2143
|
-
*
|
|
2144
|
-
*
|
|
2145
|
-
*
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
*
|
|
2151
|
-
*
|
|
2152
|
-
*
|
|
3484
|
+
function __promisify__(src: PathLike, dst: PathLike, mode?: number): Promise<void>;
|
|
3485
|
+
}
|
|
3486
|
+
/**
|
|
3487
|
+
* Synchronously copies `src` to `dest`. By default, `dest` is overwritten if it
|
|
3488
|
+
* already exists. Returns `undefined`. Node.js makes no guarantees about the
|
|
3489
|
+
* atomicity of the copy operation. If an error occurs after the destination file
|
|
3490
|
+
* has been opened for writing, Node.js will attempt to remove the destination.
|
|
3491
|
+
*
|
|
3492
|
+
* `mode` is an optional integer that specifies the behavior
|
|
3493
|
+
* of the copy operation. It is possible to create a mask consisting of the bitwise
|
|
3494
|
+
* OR of two or more values (e.g.`fs.constants.COPYFILE_EXCL | fs.constants.COPYFILE_FICLONE`).
|
|
3495
|
+
*
|
|
3496
|
+
* * `fs.constants.COPYFILE_EXCL`: The copy operation will fail if `dest` already
|
|
3497
|
+
* exists.
|
|
3498
|
+
* * `fs.constants.COPYFILE_FICLONE`: The copy operation will attempt to create a
|
|
3499
|
+
* copy-on-write reflink. If the platform does not support copy-on-write, then a
|
|
3500
|
+
* fallback copy mechanism is used.
|
|
3501
|
+
* * `fs.constants.COPYFILE_FICLONE_FORCE`: The copy operation will attempt to
|
|
3502
|
+
* create a copy-on-write reflink. If the platform does not support
|
|
3503
|
+
* copy-on-write, then the operation will fail.
|
|
3504
|
+
*
|
|
3505
|
+
* ```js
|
|
3506
|
+
* import { copyFileSync, constants } from 'fs';
|
|
3507
|
+
*
|
|
3508
|
+
* // destination.txt will be created or overwritten by default.
|
|
3509
|
+
* copyFileSync('source.txt', 'destination.txt');
|
|
3510
|
+
* console.log('source.txt was copied to destination.txt');
|
|
3511
|
+
*
|
|
3512
|
+
* // By using COPYFILE_EXCL, the operation will fail if destination.txt exists.
|
|
3513
|
+
* copyFileSync('source.txt', 'destination.txt', constants.COPYFILE_EXCL);
|
|
3514
|
+
* ```
|
|
3515
|
+
* @since v8.5.0
|
|
3516
|
+
* @param src source filename to copy
|
|
3517
|
+
* @param dest destination filename of the copy operation
|
|
3518
|
+
* @param mode modifiers for copy operation.
|
|
3519
|
+
*/
|
|
3520
|
+
export function copyFileSync(src: PathLike, dest: PathLike, mode?: number): void;
|
|
3521
|
+
/**
|
|
3522
|
+
* Write an array of `ArrayBufferView`s to the file specified by `fd` using`writev()`.
|
|
3523
|
+
*
|
|
3524
|
+
* `position` is the offset from the beginning of the file where this data
|
|
3525
|
+
* should be written. If `typeof position !== 'number'`, the data will be written
|
|
3526
|
+
* at the current position.
|
|
3527
|
+
*
|
|
3528
|
+
* The callback will be given three arguments: `err`, `bytesWritten`, and`buffers`. `bytesWritten` is how many bytes were written from `buffers`.
|
|
3529
|
+
*
|
|
3530
|
+
* If this method is `util.promisify()` ed, it returns a promise for an`Object` with `bytesWritten` and `buffers` properties.
|
|
3531
|
+
*
|
|
3532
|
+
* It is unsafe to use `fs.writev()` multiple times on the same file without
|
|
3533
|
+
* waiting for the callback. For this scenario, use {@link createWriteStream}.
|
|
3534
|
+
*
|
|
2153
3535
|
* On Linux, positional writes don't work when the file is opened in append mode.
|
|
2154
|
-
* The kernel ignores the position argument and always appends the data to
|
|
3536
|
+
* The kernel ignores the position argument and always appends the data to
|
|
3537
|
+
* the end of the file.
|
|
3538
|
+
* @since v12.9.0
|
|
2155
3539
|
*/
|
|
2156
|
-
export function writev(
|
|
2157
|
-
fd: number,
|
|
2158
|
-
buffers: ReadonlyArray<NodeJS.ArrayBufferView>,
|
|
2159
|
-
cb: (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: NodeJS.ArrayBufferView[]) => void
|
|
2160
|
-
): void;
|
|
3540
|
+
export function writev(fd: number, buffers: ReadonlyArray<NodeJS.ArrayBufferView>, cb: (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: NodeJS.ArrayBufferView[]) => void): void;
|
|
2161
3541
|
export function writev(
|
|
2162
3542
|
fd: number,
|
|
2163
3543
|
buffers: ReadonlyArray<NodeJS.ArrayBufferView>,
|
|
2164
3544
|
position: number,
|
|
2165
3545
|
cb: (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: NodeJS.ArrayBufferView[]) => void
|
|
2166
3546
|
): void;
|
|
2167
|
-
|
|
2168
3547
|
export interface WriteVResult {
|
|
2169
3548
|
bytesWritten: number;
|
|
2170
3549
|
buffers: NodeJS.ArrayBufferView[];
|
|
2171
3550
|
}
|
|
2172
|
-
|
|
2173
3551
|
export namespace writev {
|
|
2174
3552
|
function __promisify__(fd: number, buffers: ReadonlyArray<NodeJS.ArrayBufferView>, position?: number): Promise<WriteVResult>;
|
|
2175
3553
|
}
|
|
2176
|
-
|
|
2177
3554
|
/**
|
|
2178
|
-
*
|
|
3555
|
+
* For detailed information, see the documentation of the asynchronous version of
|
|
3556
|
+
* this API: {@link writev}.
|
|
3557
|
+
* @since v12.9.0
|
|
3558
|
+
* @return The number of bytes written.
|
|
2179
3559
|
*/
|
|
2180
3560
|
export function writevSync(fd: number, buffers: ReadonlyArray<NodeJS.ArrayBufferView>, position?: number): number;
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
3561
|
+
/**
|
|
3562
|
+
* Read from a file specified by `fd` and write to an array of `ArrayBufferView`s
|
|
3563
|
+
* using `readv()`.
|
|
3564
|
+
*
|
|
3565
|
+
* `position` is the offset from the beginning of the file from where data
|
|
3566
|
+
* should be read. If `typeof position !== 'number'`, the data will be read
|
|
3567
|
+
* from the current position.
|
|
3568
|
+
*
|
|
3569
|
+
* The callback will be given three arguments: `err`, `bytesRead`, and`buffers`. `bytesRead` is how many bytes were read from the file.
|
|
3570
|
+
*
|
|
3571
|
+
* If this method is invoked as its `util.promisify()` ed version, it returns
|
|
3572
|
+
* a promise for an `Object` with `bytesRead` and `buffers` properties.
|
|
3573
|
+
* @since v13.13.0, v12.17.0
|
|
3574
|
+
*/
|
|
3575
|
+
export function readv(fd: number, buffers: ReadonlyArray<NodeJS.ArrayBufferView>, cb: (err: NodeJS.ErrnoException | null, bytesRead: number, buffers: NodeJS.ArrayBufferView[]) => void): void;
|
|
2187
3576
|
export function readv(
|
|
2188
3577
|
fd: number,
|
|
2189
3578
|
buffers: ReadonlyArray<NodeJS.ArrayBufferView>,
|
|
2190
3579
|
position: number,
|
|
2191
3580
|
cb: (err: NodeJS.ErrnoException | null, bytesRead: number, buffers: NodeJS.ArrayBufferView[]) => void
|
|
2192
3581
|
): void;
|
|
2193
|
-
|
|
2194
3582
|
export interface ReadVResult {
|
|
2195
3583
|
bytesRead: number;
|
|
2196
3584
|
buffers: NodeJS.ArrayBufferView[];
|
|
2197
3585
|
}
|
|
2198
|
-
|
|
2199
3586
|
export namespace readv {
|
|
2200
3587
|
function __promisify__(fd: number, buffers: ReadonlyArray<NodeJS.ArrayBufferView>, position?: number): Promise<ReadVResult>;
|
|
2201
3588
|
}
|
|
2202
|
-
|
|
2203
3589
|
/**
|
|
2204
|
-
*
|
|
3590
|
+
* For detailed information, see the documentation of the asynchronous version of
|
|
3591
|
+
* this API: {@link readv}.
|
|
3592
|
+
* @since v13.13.0, v12.17.0
|
|
3593
|
+
* @return The number of bytes read.
|
|
2205
3594
|
*/
|
|
2206
3595
|
export function readvSync(fd: number, buffers: ReadonlyArray<NodeJS.ArrayBufferView>, position?: number): number;
|
|
2207
|
-
|
|
2208
3596
|
export interface OpenDirOptions {
|
|
2209
3597
|
encoding?: BufferEncoding | undefined;
|
|
2210
3598
|
/**
|
|
@@ -2215,36 +3603,47 @@ declare module 'fs' {
|
|
|
2215
3603
|
*/
|
|
2216
3604
|
bufferSize?: number | undefined;
|
|
2217
3605
|
}
|
|
2218
|
-
|
|
3606
|
+
/**
|
|
3607
|
+
* Synchronously open a directory. See [`opendir(3)`](http://man7.org/linux/man-pages/man3/opendir.3.html).
|
|
3608
|
+
*
|
|
3609
|
+
* Creates an `<fs.Dir>`, which contains all further functions for reading from
|
|
3610
|
+
* and cleaning up the directory.
|
|
3611
|
+
*
|
|
3612
|
+
* The `encoding` option sets the encoding for the `path` while opening the
|
|
3613
|
+
* directory and subsequent read operations.
|
|
3614
|
+
* @since v12.12.0
|
|
3615
|
+
*/
|
|
2219
3616
|
export function opendirSync(path: string, options?: OpenDirOptions): Dir;
|
|
2220
|
-
|
|
3617
|
+
/**
|
|
3618
|
+
* Asynchronously open a directory. See the POSIX [`opendir(3)`](http://man7.org/linux/man-pages/man3/opendir.3.html) documentation for
|
|
3619
|
+
* more details.
|
|
3620
|
+
*
|
|
3621
|
+
* Creates an `<fs.Dir>`, which contains all further functions for reading from
|
|
3622
|
+
* and cleaning up the directory.
|
|
3623
|
+
*
|
|
3624
|
+
* The `encoding` option sets the encoding for the `path` while opening the
|
|
3625
|
+
* directory and subsequent read operations.
|
|
3626
|
+
* @since v12.12.0
|
|
3627
|
+
*/
|
|
2221
3628
|
export function opendir(path: string, cb: (err: NodeJS.ErrnoException | null, dir: Dir) => void): void;
|
|
2222
3629
|
export function opendir(path: string, options: OpenDirOptions, cb: (err: NodeJS.ErrnoException | null, dir: Dir) => void): void;
|
|
2223
|
-
|
|
2224
3630
|
export namespace opendir {
|
|
2225
3631
|
function __promisify__(path: string, options?: OpenDirOptions): Promise<Dir>;
|
|
2226
3632
|
}
|
|
2227
|
-
|
|
2228
3633
|
export interface BigIntStats extends StatsBase<bigint> {
|
|
2229
|
-
}
|
|
2230
|
-
|
|
2231
|
-
export class BigIntStats {
|
|
2232
3634
|
atimeNs: bigint;
|
|
2233
3635
|
mtimeNs: bigint;
|
|
2234
3636
|
ctimeNs: bigint;
|
|
2235
3637
|
birthtimeNs: bigint;
|
|
2236
3638
|
}
|
|
2237
|
-
|
|
2238
3639
|
export interface BigIntOptions {
|
|
2239
3640
|
bigint: true;
|
|
2240
3641
|
}
|
|
2241
|
-
|
|
2242
3642
|
export interface StatOptions {
|
|
2243
3643
|
bigint?: boolean | undefined;
|
|
2244
3644
|
throwIfNoEntry?: boolean | undefined;
|
|
2245
3645
|
}
|
|
2246
3646
|
}
|
|
2247
|
-
|
|
2248
3647
|
declare module 'node:fs' {
|
|
2249
3648
|
export * from 'fs';
|
|
2250
3649
|
}
|