@tauri-apps/plugin-fs 2.0.0-alpha.4 → 2.0.0-alpha.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.
- package/dist-js/index.cjs +556 -170
- package/dist-js/index.d.ts +593 -180
- package/dist-js/index.js +542 -158
- package/package.json +2 -2
package/dist-js/index.d.ts
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
*
|
|
13
13
|
* The scope configuration is an array of glob patterns describing folder paths that are allowed.
|
|
14
14
|
* For instance, this scope configuration only allows accessing files on the
|
|
15
|
-
* *databases* folder of the {@link
|
|
15
|
+
* *databases* folder of the {@link https://beta.tauri.app/2/reference/js/core/namespacepath/#appdatadir | `$APPDATA` directory}:
|
|
16
16
|
* ```json
|
|
17
17
|
* {
|
|
18
18
|
* "plugins": {
|
|
@@ -23,16 +23,32 @@
|
|
|
23
23
|
* }
|
|
24
24
|
* ```
|
|
25
25
|
*
|
|
26
|
-
* Notice the use of the `$APPDATA` variable. The value is injected at runtime, resolving to the {@link
|
|
26
|
+
* Notice the use of the `$APPDATA` variable. The value is injected at runtime, resolving to the {@link https://beta.tauri.app/2/reference/js/core/namespacepath/#appdatadir | app data directory}.
|
|
27
|
+
*
|
|
27
28
|
* The available variables are:
|
|
28
|
-
* {@
|
|
29
|
-
* {@
|
|
30
|
-
* {@
|
|
31
|
-
* {@
|
|
32
|
-
* {@
|
|
33
|
-
* {@
|
|
34
|
-
* {@
|
|
35
|
-
* {@
|
|
29
|
+
* {@linkcode https://beta.tauri.app/2/reference/js/core/namespacepath/#appconfigdir | $APPCONFIG},
|
|
30
|
+
* {@linkcode https://beta.tauri.app/2/reference/js/core/namespacepath/#appdatadir | $APPDATA},
|
|
31
|
+
* {@linkcode https://beta.tauri.app/2/reference/js/core/namespacepath/#appLocaldatadir | $APPLOCALDATA},
|
|
32
|
+
* {@linkcode https://beta.tauri.app/2/reference/js/core/namespacepath/#appcachedir | $APPCACHE},
|
|
33
|
+
* {@linkcode https://beta.tauri.app/2/reference/js/core/namespacepath/#applogdir | $APPLOG},
|
|
34
|
+
* {@linkcode https://beta.tauri.app/2/reference/js/core/namespacepath/#audiodir | $AUDIO},
|
|
35
|
+
* {@linkcode https://beta.tauri.app/2/reference/js/core/namespacepath/#cachedir | $CACHE},
|
|
36
|
+
* {@linkcode https://beta.tauri.app/2/reference/js/core/namespacepath/#configdir | $CONFIG},
|
|
37
|
+
* {@linkcode https://beta.tauri.app/2/reference/js/core/namespacepath/#datadir | $DATA},
|
|
38
|
+
* {@linkcode https://beta.tauri.app/2/reference/js/core/namespacepath/#localdatadir | $LOCALDATA},
|
|
39
|
+
* {@linkcode https://beta.tauri.app/2/reference/js/core/namespacepath/#desktopdir | $DESKTOP},
|
|
40
|
+
* {@linkcode https://beta.tauri.app/2/reference/js/core/namespacepath/#documentdir | $DOCUMENT},
|
|
41
|
+
* {@linkcode https://beta.tauri.app/2/reference/js/core/namespacepath/#downloaddir | $DOWNLOAD},
|
|
42
|
+
* {@linkcode https://beta.tauri.app/2/reference/js/core/namespacepath/#executabledir | $EXE},
|
|
43
|
+
* {@linkcode https://beta.tauri.app/2/reference/js/core/namespacepath/#fontdir | $FONT},
|
|
44
|
+
* {@linkcode https://beta.tauri.app/2/reference/js/core/namespacepath/#homedir | $HOME},
|
|
45
|
+
* {@linkcode https://beta.tauri.app/2/reference/js/core/namespacepath/#picturedir | $PICTURE},
|
|
46
|
+
* {@linkcode https://beta.tauri.app/2/reference/js/core/namespacepath/#publicdir | $PUBLIC},
|
|
47
|
+
* {@linkcode https://beta.tauri.app/2/reference/js/core/namespacepath/#runtimedir | $RUNTIME},
|
|
48
|
+
* {@linkcode https://beta.tauri.app/2/reference/js/core/namespacepath/#templatedir | $TEMPLATE},
|
|
49
|
+
* {@linkcode https://beta.tauri.app/2/reference/js/core/namespacepath/#videodir | $VIDEO},
|
|
50
|
+
* {@linkcode https://beta.tauri.app/2/reference/js/core/namespacepath/#resourcedir | $RESOURCE},
|
|
51
|
+
* {@linkcode https://beta.tauri.app/2/reference/js/core/namespacepath/#tempdir | $TEMP}.
|
|
36
52
|
*
|
|
37
53
|
* Trying to execute any API with a URL not configured on the scope results in a promise rejection due to denied access.
|
|
38
54
|
*
|
|
@@ -41,314 +57,655 @@
|
|
|
41
57
|
* @module
|
|
42
58
|
*/
|
|
43
59
|
import { BaseDirectory } from "@tauri-apps/api/path";
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* The underlying raw `st_mode` bits that contain the standard Unix permissions for this file.
|
|
51
|
-
*/
|
|
52
|
-
mode: number | undefined;
|
|
60
|
+
import { Resource } from "@tauri-apps/api/core";
|
|
61
|
+
declare enum SeekMode {
|
|
62
|
+
Start = 0,
|
|
63
|
+
Current = 1,
|
|
64
|
+
End = 2
|
|
53
65
|
}
|
|
54
66
|
/**
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
67
|
+
* A FileInfo describes a file and is returned by `stat`, `lstat` or `fstat`.
|
|
68
|
+
*
|
|
69
|
+
* @since 2.0.0
|
|
58
70
|
*/
|
|
59
|
-
interface
|
|
71
|
+
interface FileInfo {
|
|
60
72
|
/**
|
|
61
|
-
*
|
|
73
|
+
* True if this is info for a regular file. Mutually exclusive to
|
|
74
|
+
* `FileInfo.isDirectory` and `FileInfo.isSymlink`.
|
|
62
75
|
*/
|
|
63
|
-
|
|
76
|
+
isFile: boolean;
|
|
64
77
|
/**
|
|
65
|
-
*
|
|
78
|
+
* True if this is info for a regular directory. Mutually exclusive to
|
|
79
|
+
* `FileInfo.isFile` and `FileInfo.isSymlink`.
|
|
66
80
|
*/
|
|
67
|
-
|
|
81
|
+
isDirectory: boolean;
|
|
68
82
|
/**
|
|
69
|
-
*
|
|
83
|
+
* True if this is info for a symlink. Mutually exclusive to
|
|
84
|
+
* `FileInfo.isFile` and `FileInfo.isDirectory`.
|
|
70
85
|
*/
|
|
71
|
-
|
|
86
|
+
isSymlink: boolean;
|
|
72
87
|
/**
|
|
73
|
-
*
|
|
88
|
+
* The size of the file, in bytes.
|
|
74
89
|
*/
|
|
75
|
-
|
|
90
|
+
size: number;
|
|
76
91
|
/**
|
|
77
|
-
*
|
|
92
|
+
* The last modification time of the file. This corresponds to the `mtime`
|
|
93
|
+
* field from `stat` on Linux/Mac OS and `ftLastWriteTime` on Windows. This
|
|
94
|
+
* may not be available on all platforms.
|
|
78
95
|
*/
|
|
79
|
-
|
|
96
|
+
mtime: Date | null;
|
|
80
97
|
/**
|
|
81
|
-
*
|
|
98
|
+
* The last access time of the file. This corresponds to the `atime`
|
|
99
|
+
* field from `stat` on Unix and `ftLastAccessTime` on Windows. This may not
|
|
100
|
+
* be available on all platforms.
|
|
82
101
|
*/
|
|
83
|
-
|
|
102
|
+
atime: Date | null;
|
|
84
103
|
/**
|
|
85
|
-
* The
|
|
104
|
+
* The creation time of the file. This corresponds to the `birthtime`
|
|
105
|
+
* field from `stat` on Mac/BSD and `ftCreationTime` on Windows. This may
|
|
106
|
+
* not be available on all platforms.
|
|
86
107
|
*/
|
|
87
|
-
|
|
108
|
+
birthtime: Date | null;
|
|
109
|
+
/** Whether this is a readonly (unwritable) file. */
|
|
110
|
+
readonly: boolean;
|
|
88
111
|
/**
|
|
89
|
-
*
|
|
112
|
+
* This field contains the file system attribute information for a file
|
|
113
|
+
* or directory. For possible values and their descriptions, see
|
|
114
|
+
* {@link https://docs.microsoft.com/en-us/windows/win32/fileio/file-attribute-constants | File Attribute Constants} in the Windows Dev Center
|
|
115
|
+
*
|
|
116
|
+
* #### Platform-specific
|
|
117
|
+
*
|
|
118
|
+
* - **macOS / Linux / Android / iOS:** Unsupported.
|
|
90
119
|
*/
|
|
91
|
-
|
|
120
|
+
fileAttributes: number | null;
|
|
92
121
|
/**
|
|
93
|
-
*
|
|
122
|
+
* ID of the device containing the file.
|
|
123
|
+
*
|
|
124
|
+
* #### Platform-specific
|
|
125
|
+
*
|
|
126
|
+
* - **Windows:** Unsupported.
|
|
94
127
|
*/
|
|
95
|
-
dev: number |
|
|
128
|
+
dev: number | null;
|
|
96
129
|
/**
|
|
97
|
-
*
|
|
130
|
+
* Inode number.
|
|
131
|
+
*
|
|
132
|
+
* #### Platform-specific
|
|
133
|
+
*
|
|
134
|
+
* - **Windows:** Unsupported.
|
|
98
135
|
*/
|
|
99
|
-
ino: number |
|
|
136
|
+
ino: number | null;
|
|
100
137
|
/**
|
|
101
|
-
* The
|
|
138
|
+
* The underlying raw `st_mode` bits that contain the standard Unix
|
|
139
|
+
* permissions for this file/directory.
|
|
140
|
+
*
|
|
141
|
+
* #### Platform-specific
|
|
142
|
+
*
|
|
143
|
+
* - **Windows:** Unsupported.
|
|
102
144
|
*/
|
|
103
|
-
mode: number |
|
|
145
|
+
mode: number | null;
|
|
104
146
|
/**
|
|
105
|
-
*
|
|
147
|
+
* Number of hard links pointing to this file.
|
|
148
|
+
*
|
|
149
|
+
* #### Platform-specific
|
|
150
|
+
*
|
|
151
|
+
* - **Windows:** Unsupported.
|
|
106
152
|
*/
|
|
107
|
-
nlink: number |
|
|
153
|
+
nlink: number | null;
|
|
108
154
|
/**
|
|
109
|
-
*
|
|
155
|
+
* User ID of the owner of this file.
|
|
156
|
+
*
|
|
157
|
+
* #### Platform-specific
|
|
158
|
+
*
|
|
159
|
+
* - **Windows:** Unsupported.
|
|
110
160
|
*/
|
|
111
|
-
uid: number |
|
|
161
|
+
uid: number | null;
|
|
112
162
|
/**
|
|
113
|
-
*
|
|
163
|
+
* Group ID of the owner of this file.
|
|
164
|
+
*
|
|
165
|
+
* #### Platform-specific
|
|
166
|
+
*
|
|
167
|
+
* - **Windows:** Unsupported.
|
|
114
168
|
*/
|
|
115
|
-
gid: number |
|
|
169
|
+
gid: number | null;
|
|
116
170
|
/**
|
|
117
|
-
*
|
|
171
|
+
* Device ID of this file.
|
|
172
|
+
*
|
|
173
|
+
* #### Platform-specific
|
|
174
|
+
*
|
|
175
|
+
* - **Windows:** Unsupported.
|
|
118
176
|
*/
|
|
119
|
-
rdev: number |
|
|
177
|
+
rdev: number | null;
|
|
120
178
|
/**
|
|
121
|
-
*
|
|
179
|
+
* Blocksize for filesystem I/O.
|
|
180
|
+
*
|
|
181
|
+
* #### Platform-specific
|
|
182
|
+
*
|
|
183
|
+
* - **Windows:** Unsupported.
|
|
122
184
|
*/
|
|
123
|
-
blksize: number |
|
|
185
|
+
blksize: number | null;
|
|
124
186
|
/**
|
|
125
|
-
*
|
|
187
|
+
* Number of blocks allocated to the file, in 512-byte units.
|
|
188
|
+
*
|
|
189
|
+
* #### Platform-specific
|
|
190
|
+
*
|
|
191
|
+
* - **Windows:** Unsupported.
|
|
126
192
|
*/
|
|
127
|
-
blocks: number |
|
|
193
|
+
blocks: number | null;
|
|
128
194
|
}
|
|
129
195
|
/**
|
|
196
|
+
* The Tauri abstraction for reading and writing files.
|
|
197
|
+
*
|
|
130
198
|
* @since 2.0.0
|
|
131
199
|
*/
|
|
132
|
-
|
|
133
|
-
|
|
200
|
+
declare class FileHandle extends Resource {
|
|
201
|
+
constructor(rid: number);
|
|
202
|
+
/**
|
|
203
|
+
* Reads up to `p.byteLength` bytes into `p`. It resolves to the number of
|
|
204
|
+
* bytes read (`0` < `n` <= `p.byteLength`) and rejects if any error
|
|
205
|
+
* encountered. Even if `read()` resolves to `n` < `p.byteLength`, it may
|
|
206
|
+
* use all of `p` as scratch space during the call. If some data is
|
|
207
|
+
* available but not `p.byteLength` bytes, `read()` conventionally resolves
|
|
208
|
+
* to what is available instead of waiting for more.
|
|
209
|
+
*
|
|
210
|
+
* When `read()` encounters end-of-file condition, it resolves to EOF
|
|
211
|
+
* (`null`).
|
|
212
|
+
*
|
|
213
|
+
* When `read()` encounters an error, it rejects with an error.
|
|
214
|
+
*
|
|
215
|
+
* Callers should always process the `n` > `0` bytes returned before
|
|
216
|
+
* considering the EOF (`null`). Doing so correctly handles I/O errors that
|
|
217
|
+
* happen after reading some bytes and also both of the allowed EOF
|
|
218
|
+
* behaviors.
|
|
219
|
+
*
|
|
220
|
+
* @example
|
|
221
|
+
* ```typescript
|
|
222
|
+
* import { open, read, close, BaseDirectory } from "@tauri-apps/plugin-fs"
|
|
223
|
+
* // if "$APP/foo/bar.txt" contains the text "hello world":
|
|
224
|
+
* const file = await open("foo/bar.txt", { dir: BaseDirectory.App });
|
|
225
|
+
* const buf = new Uint8Array(100);
|
|
226
|
+
* const numberOfBytesRead = await file.read(buf); // 11 bytes
|
|
227
|
+
* const text = new TextDecoder().decode(buf); // "hello world"
|
|
228
|
+
* await close(file.rid);
|
|
229
|
+
* ```
|
|
230
|
+
*
|
|
231
|
+
* @since 2.0.0
|
|
232
|
+
*/
|
|
233
|
+
read(buffer: Uint8Array): Promise<number | null>;
|
|
234
|
+
/**
|
|
235
|
+
* Seek sets the offset for the next `read()` or `write()` to offset,
|
|
236
|
+
* interpreted according to `whence`: `Start` means relative to the
|
|
237
|
+
* start of the file, `Current` means relative to the current offset,
|
|
238
|
+
* and `End` means relative to the end. Seek resolves to the new offset
|
|
239
|
+
* relative to the start of the file.
|
|
240
|
+
*
|
|
241
|
+
* Seeking to an offset before the start of the file is an error. Seeking to
|
|
242
|
+
* any positive offset is legal, but the behavior of subsequent I/O
|
|
243
|
+
* operations on the underlying object is implementation-dependent.
|
|
244
|
+
* It returns the number of cursor position.
|
|
245
|
+
*
|
|
246
|
+
* @example
|
|
247
|
+
* ```typescript
|
|
248
|
+
* import { open, seek, write, SeekMode, BaseDirectory } from '@tauri-apps/plugin-fs';
|
|
249
|
+
*
|
|
250
|
+
* // Given hello.txt pointing to file with "Hello world", which is 11 bytes long:
|
|
251
|
+
* const file = await open('hello.txt', { read: true, write: true, truncate: true, create: true, dir: BaseDirectory.App });
|
|
252
|
+
* await file.write(new TextEncoder().encode("Hello world"), { dir: BaseDirectory.App });
|
|
253
|
+
*
|
|
254
|
+
* // Seek 6 bytes from the start of the file
|
|
255
|
+
* console.log(await file.seek(6, SeekMode.Start)); // "6"
|
|
256
|
+
* // Seek 2 more bytes from the current position
|
|
257
|
+
* console.log(await file.seek(2, SeekMode.Current)); // "8"
|
|
258
|
+
* // Seek backwards 2 bytes from the end of the file
|
|
259
|
+
* console.log(await file.seek(-2, SeekMode.End)); // "9" (e.g. 11-2)
|
|
260
|
+
* ```
|
|
261
|
+
*
|
|
262
|
+
* @since 2.0.0
|
|
263
|
+
*/
|
|
264
|
+
seek(offset: number, whence: SeekMode): Promise<number>;
|
|
265
|
+
/**
|
|
266
|
+
* Returns a {@linkcode FileInfo } for this file.
|
|
267
|
+
*
|
|
268
|
+
* @example
|
|
269
|
+
* ```typescript
|
|
270
|
+
* import { open, fstat, BaseDirectory } from '@tauri-apps/plugin-fs';
|
|
271
|
+
* const file = await open("file.txt", { read: true, dir: BaseDirectory.App });
|
|
272
|
+
* const fileInfo = await fstat(file.rid);
|
|
273
|
+
* console.log(fileInfo.isFile); // true
|
|
274
|
+
* ```
|
|
275
|
+
*
|
|
276
|
+
* @since 2.0.0
|
|
277
|
+
*/
|
|
278
|
+
stat(): Promise<FileInfo>;
|
|
279
|
+
/**
|
|
280
|
+
* Truncates or extends this file, to reach the specified `len`.
|
|
281
|
+
* If `len` is not specified then the entire file contents are truncated.
|
|
282
|
+
*
|
|
283
|
+
* @example
|
|
284
|
+
* ```typescript
|
|
285
|
+
* import { ftruncate, open, write, read, BaseDirectory } from '@tauri-apps/plugin-fs';
|
|
286
|
+
*
|
|
287
|
+
* // truncate the entire file
|
|
288
|
+
* const file = await open("my_file.txt", { read: true, write: true, create: true, dir: BaseDirectory.App });
|
|
289
|
+
* await ftruncate(file.rid);
|
|
290
|
+
*
|
|
291
|
+
* // truncate part of the file
|
|
292
|
+
* const file = await open("my_file.txt", { read: true, write: true, create: true, dir: BaseDirectory.App });
|
|
293
|
+
* await write(file.rid, new TextEncoder().encode("Hello World"));
|
|
294
|
+
* await ftruncate(file.rid, 7);
|
|
295
|
+
* const data = new Uint8Array(32);
|
|
296
|
+
* await read(file.rid, data);
|
|
297
|
+
* console.log(new TextDecoder().decode(data)); // Hello W
|
|
298
|
+
* ```
|
|
299
|
+
*
|
|
300
|
+
* @since 2.0.0
|
|
301
|
+
*/
|
|
302
|
+
truncate(len?: number): Promise<void>;
|
|
303
|
+
/**
|
|
304
|
+
* Writes `p.byteLength` bytes from `p` to the underlying data stream. It
|
|
305
|
+
* resolves to the number of bytes written from `p` (`0` <= `n` <=
|
|
306
|
+
* `p.byteLength`) or reject with the error encountered that caused the
|
|
307
|
+
* write to stop early. `write()` must reject with a non-null error if
|
|
308
|
+
* would resolve to `n` < `p.byteLength`. `write()` must not modify the
|
|
309
|
+
* slice data, even temporarily.
|
|
310
|
+
*
|
|
311
|
+
* @example
|
|
312
|
+
* ```typescript
|
|
313
|
+
* import { open, write, close, BaseDirectory } from '@tauri-apps/plugin-fs';
|
|
314
|
+
* const encoder = new TextEncoder();
|
|
315
|
+
* const data = encoder.encode("Hello world");
|
|
316
|
+
* const file = await open("bar.txt", { write: true, dir: BaseDirectory.App });
|
|
317
|
+
* const bytesWritten = await write(file.rid, data); // 11
|
|
318
|
+
* await close(file.rid);
|
|
319
|
+
* ```
|
|
320
|
+
*
|
|
321
|
+
* @since 2.0.0
|
|
322
|
+
*/
|
|
323
|
+
write(data: Uint8Array): Promise<number>;
|
|
134
324
|
}
|
|
135
325
|
/**
|
|
136
326
|
* @since 2.0.0
|
|
137
327
|
*/
|
|
138
|
-
interface
|
|
139
|
-
|
|
140
|
-
|
|
328
|
+
interface CreateOptions {
|
|
329
|
+
/** Base directory for `path` */
|
|
330
|
+
baseDir?: BaseDirectory;
|
|
141
331
|
}
|
|
142
332
|
/**
|
|
143
|
-
*
|
|
333
|
+
* Creates a file if none exists or truncates an existing file and resolves to
|
|
334
|
+
* an instance of {@linkcode FileHandle }.
|
|
144
335
|
*
|
|
145
|
-
* @
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
/** The UTF-8 string to write to the file. */
|
|
151
|
-
contents: string;
|
|
152
|
-
}
|
|
153
|
-
type BinaryFileContents = Iterable<number> | ArrayLike<number> | ArrayBuffer;
|
|
154
|
-
/**
|
|
155
|
-
* Options object used to write a binary data to a file.
|
|
336
|
+
* @example
|
|
337
|
+
* ```typescript
|
|
338
|
+
* import { create, BaseDirectory } from "@tauri-apps/plugin-fs"
|
|
339
|
+
* const file = await create("foo/bar.txt", { dir: BaseDirectory.App });
|
|
340
|
+
* ```
|
|
156
341
|
*
|
|
157
342
|
* @since 2.0.0
|
|
158
343
|
*/
|
|
159
|
-
|
|
160
|
-
/** Path to the file to write. */
|
|
161
|
-
path: string;
|
|
162
|
-
/** The byte array contents. */
|
|
163
|
-
contents: BinaryFileContents;
|
|
164
|
-
}
|
|
344
|
+
declare function create(path: string | URL, options?: CreateOptions): Promise<FileHandle>;
|
|
165
345
|
/**
|
|
166
346
|
* @since 2.0.0
|
|
167
347
|
*/
|
|
168
|
-
interface
|
|
169
|
-
|
|
348
|
+
interface OpenOptions {
|
|
349
|
+
/**
|
|
350
|
+
* Sets the option for read access. This option, when `true`, means that the
|
|
351
|
+
* file should be read-able if opened.
|
|
352
|
+
*/
|
|
353
|
+
read?: boolean;
|
|
354
|
+
/**
|
|
355
|
+
* Sets the option for write access. This option, when `true`, means that
|
|
356
|
+
* the file should be write-able if opened. If the file already exists,
|
|
357
|
+
* any write calls on it will overwrite its contents, by default without
|
|
358
|
+
* truncating it.
|
|
359
|
+
*/
|
|
360
|
+
write?: boolean;
|
|
361
|
+
/**
|
|
362
|
+
* Sets the option for the append mode. This option, when `true`, means that
|
|
363
|
+
* writes will append to a file instead of overwriting previous contents.
|
|
364
|
+
* Note that setting `{ write: true, append: true }` has the same effect as
|
|
365
|
+
* setting only `{ append: true }`.
|
|
366
|
+
*/
|
|
367
|
+
append?: boolean;
|
|
170
368
|
/**
|
|
171
|
-
*
|
|
172
|
-
*
|
|
369
|
+
* Sets the option for truncating a previous file. If a file is
|
|
370
|
+
* successfully opened with this option set it will truncate the file to `0`
|
|
371
|
+
* size if it already exists. The file must be opened with write access
|
|
372
|
+
* for truncate to work.
|
|
173
373
|
*/
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
|
|
374
|
+
truncate?: boolean;
|
|
375
|
+
/**
|
|
376
|
+
* Sets the option to allow creating a new file, if one doesn't already
|
|
377
|
+
* exist at the specified path. Requires write or append access to be
|
|
378
|
+
* used.
|
|
379
|
+
*/
|
|
380
|
+
create?: boolean;
|
|
381
|
+
/**
|
|
382
|
+
* Defaults to `false`. If set to `true`, no file, directory, or symlink is
|
|
383
|
+
* allowed to exist at the target location. Requires write or append
|
|
384
|
+
* access to be used. When createNew is set to `true`, create and truncate
|
|
385
|
+
* are ignored.
|
|
386
|
+
*/
|
|
387
|
+
createNew?: boolean;
|
|
388
|
+
/**
|
|
389
|
+
* Permissions to use if creating the file (defaults to `0o666`, before
|
|
390
|
+
* the process's umask).
|
|
391
|
+
* Ignored on Windows.
|
|
392
|
+
*/
|
|
393
|
+
mode?: number;
|
|
394
|
+
/** Base directory for `path` */
|
|
395
|
+
baseDir?: BaseDirectory;
|
|
177
396
|
}
|
|
178
397
|
/**
|
|
179
|
-
*
|
|
398
|
+
* Open a file and resolve to an instance of {@linkcode FileHandle}. The
|
|
399
|
+
* file does not need to previously exist if using the `create` or `createNew`
|
|
400
|
+
* open options. It is the callers responsibility to close the file when finished
|
|
401
|
+
* with it.
|
|
402
|
+
*
|
|
180
403
|
* @example
|
|
181
404
|
* ```typescript
|
|
182
|
-
* import {
|
|
183
|
-
*
|
|
184
|
-
*
|
|
405
|
+
* import { open, BaseDirectory } from "@tauri-apps/plugin-fs"
|
|
406
|
+
* const file = await open("foo/bar.txt", { read: true, write: true, dir: BaseDirectory.App });
|
|
407
|
+
* // Do work with file
|
|
408
|
+
* await close(file.rid);
|
|
185
409
|
* ```
|
|
186
410
|
*
|
|
187
411
|
* @since 2.0.0
|
|
188
412
|
*/
|
|
189
|
-
declare function
|
|
413
|
+
declare function open(path: string | URL, options?: OpenOptions): Promise<FileHandle>;
|
|
190
414
|
/**
|
|
191
|
-
*
|
|
415
|
+
* @since 2.0.0
|
|
416
|
+
*/
|
|
417
|
+
interface CopyFileOptions {
|
|
418
|
+
/** Base directory for `fromPath`. */
|
|
419
|
+
fromPathBaseDir?: BaseDirectory;
|
|
420
|
+
/** Base directory for `toPath`. */
|
|
421
|
+
toPathBaseDir?: BaseDirectory;
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Copies the contents and permissions of one file to another specified path, by default creating a new file if needed, else overwriting.
|
|
192
425
|
* @example
|
|
193
426
|
* ```typescript
|
|
194
|
-
* import {
|
|
195
|
-
*
|
|
196
|
-
* const contents = await readBinaryFile('avatar.png', { dir: BaseDirectory.Resource });
|
|
427
|
+
* import { copyFile, BaseDirectory } from '@tauri-apps/plugin-fs';
|
|
428
|
+
* await copyFile('app.conf', 'app.conf.bk', { dir: BaseDirectory.App });
|
|
197
429
|
* ```
|
|
198
430
|
*
|
|
199
431
|
* @since 2.0.0
|
|
200
432
|
*/
|
|
201
|
-
declare function
|
|
433
|
+
declare function copyFile(fromPath: string | URL, toPath: string | URL, options?: CopyFileOptions): Promise<void>;
|
|
202
434
|
/**
|
|
203
|
-
*
|
|
435
|
+
* @since 2.0.0
|
|
436
|
+
*/
|
|
437
|
+
interface MkdirOptions {
|
|
438
|
+
/** Permissions to use when creating the directory (defaults to `0o777`, before the process's umask). Ignored on Windows. */
|
|
439
|
+
mode?: number;
|
|
440
|
+
/**
|
|
441
|
+
* Defaults to `false`. If set to `true`, means that any intermediate directories will also be created (as with the shell command `mkdir -p`).
|
|
442
|
+
* */
|
|
443
|
+
recursive?: boolean;
|
|
444
|
+
/** Base directory for `path` */
|
|
445
|
+
baseDir?: BaseDirectory;
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* Creates a new directory with the specified path.
|
|
204
449
|
* @example
|
|
205
450
|
* ```typescript
|
|
206
|
-
* import {
|
|
207
|
-
*
|
|
208
|
-
* await writeTextFile('app.conf', 'file contents', { dir: BaseDirectory.AppConfig });
|
|
451
|
+
* import { mkdir, BaseDirectory } from '@tauri-apps/plugin-fs';
|
|
452
|
+
* await mkdir('users', { dir: BaseDirectory.App });
|
|
209
453
|
* ```
|
|
210
454
|
*
|
|
211
455
|
* @since 2.0.0
|
|
212
456
|
*/
|
|
213
|
-
declare function
|
|
457
|
+
declare function mkdir(path: string | URL, options?: MkdirOptions): Promise<void>;
|
|
458
|
+
/**
|
|
459
|
+
* @since 2.0.0
|
|
460
|
+
*/
|
|
461
|
+
interface ReadDirOptions {
|
|
462
|
+
/** Base directory for `path` */
|
|
463
|
+
baseDir?: BaseDirectory;
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* A disk entry which is either a file, a directory or a symlink.
|
|
467
|
+
*
|
|
468
|
+
* This is the result of the {@linkcode readDir}.
|
|
469
|
+
*
|
|
470
|
+
* @since 2.0.0
|
|
471
|
+
*/
|
|
472
|
+
interface DirEntry {
|
|
473
|
+
/** The name of the entry (file name with extension or directory name). */
|
|
474
|
+
name: string;
|
|
475
|
+
/** Specifies whether this entry is a directory or not. */
|
|
476
|
+
isDirectory: boolean;
|
|
477
|
+
/** Specifies whether this entry is a file or not. */
|
|
478
|
+
isFile: boolean;
|
|
479
|
+
/** Specifies whether this entry is a symlink or not. */
|
|
480
|
+
isSymlink: boolean;
|
|
481
|
+
}
|
|
214
482
|
/**
|
|
215
|
-
*
|
|
483
|
+
* Reads the directory given by path and returns an array of `DirEntry`.
|
|
216
484
|
* @example
|
|
217
485
|
* ```typescript
|
|
218
|
-
* import {
|
|
219
|
-
*
|
|
220
|
-
*
|
|
486
|
+
* import { readDir, BaseDirectory } from '@tauri-apps/plugin-fs';
|
|
487
|
+
* const dir = "users"
|
|
488
|
+
* const entries = await readDir('users', { dir: BaseDirectory.App });
|
|
489
|
+
* processEntriesRecursive(dir, entries);
|
|
490
|
+
* async function processEntriesRecursive(parent, entries) {
|
|
491
|
+
* for (const entry of entries) {
|
|
492
|
+
* console.log(`Entry: ${entry.name}`);
|
|
493
|
+
* if (entry.isDirectory) {
|
|
494
|
+
* const dir = parent + entry.name;
|
|
495
|
+
* processEntriesRecursive(dir, await readDir(dir, { dir: BaseDirectory.App }))
|
|
496
|
+
* }
|
|
497
|
+
* }
|
|
498
|
+
* }
|
|
221
499
|
* ```
|
|
222
|
-
* @returns A promise indicating the success or failure of the operation.
|
|
223
500
|
*
|
|
224
501
|
* @since 2.0.0
|
|
225
502
|
*/
|
|
226
|
-
declare function
|
|
503
|
+
declare function readDir(path: string | URL, options?: ReadDirOptions): Promise<DirEntry[]>;
|
|
504
|
+
/**
|
|
505
|
+
* @since 2.0.0
|
|
506
|
+
*/
|
|
507
|
+
interface ReadFileOptions {
|
|
508
|
+
/** Base directory for `path` */
|
|
509
|
+
baseDir?: BaseDirectory;
|
|
510
|
+
}
|
|
227
511
|
/**
|
|
228
|
-
*
|
|
512
|
+
* Reads and resolves to the entire contents of a file as an array of bytes.
|
|
513
|
+
* TextDecoder can be used to transform the bytes to string if required.
|
|
229
514
|
* @example
|
|
230
515
|
* ```typescript
|
|
231
|
-
* import {
|
|
232
|
-
*
|
|
233
|
-
* await writeBinaryFile('avatar.png', new Uint8Array([]), { dir: BaseDirectory.AppData });
|
|
516
|
+
* import { readFile, BaseDirectory } from '@tauri-apps/plugin-fs';
|
|
517
|
+
* const contents = await readFile('avatar.png', { dir: BaseDirectory.Resource });
|
|
234
518
|
* ```
|
|
235
519
|
*
|
|
236
|
-
* @param options Configuration object.
|
|
237
|
-
* @returns A promise indicating the success or failure of the operation.
|
|
238
|
-
*
|
|
239
520
|
* @since 2.0.0
|
|
240
521
|
*/
|
|
241
|
-
declare function
|
|
522
|
+
declare function readFile(path: string | URL, options?: ReadFileOptions): Promise<Uint8Array>;
|
|
242
523
|
/**
|
|
243
|
-
*
|
|
524
|
+
* Reads and returns the entire contents of a file as UTF-8 string.
|
|
244
525
|
* @example
|
|
245
526
|
* ```typescript
|
|
246
|
-
* import {
|
|
247
|
-
*
|
|
248
|
-
* await writeBinaryFile({ path: 'avatar.png', contents: new Uint8Array([]) }, { dir: BaseDirectory.AppData });
|
|
527
|
+
* import { readTextFile, BaseDirectory } from '@tauri-apps/plugin-fs';
|
|
528
|
+
* const contents = await readTextFile('app.conf', { dir: BaseDirectory.App });
|
|
249
529
|
* ```
|
|
250
530
|
*
|
|
251
|
-
* @param file The object containing the file path and contents.
|
|
252
|
-
* @param options Configuration object.
|
|
253
|
-
* @returns A promise indicating the success or failure of the operation.
|
|
254
|
-
*
|
|
255
531
|
* @since 2.0.0
|
|
256
532
|
*/
|
|
257
|
-
declare function
|
|
533
|
+
declare function readTextFile(path: string | URL, options?: ReadFileOptions): Promise<string>;
|
|
258
534
|
/**
|
|
259
|
-
*
|
|
535
|
+
* Returns an async {@linkcode AsyncIterableIterator} over the lines of a file as UTF-8 string.
|
|
260
536
|
* @example
|
|
261
537
|
* ```typescript
|
|
262
|
-
* import {
|
|
263
|
-
*
|
|
264
|
-
*
|
|
265
|
-
*
|
|
266
|
-
* function processEntries(entries) {
|
|
267
|
-
* for (const entry of entries) {
|
|
268
|
-
* console.log(`Entry: ${entry.path}`);
|
|
269
|
-
* if (entry.children) {
|
|
270
|
-
* processEntries(entry.children)
|
|
271
|
-
* }
|
|
272
|
-
* }
|
|
538
|
+
* import { readTextFileLines, BaseDirectory } from '@tauri-apps/plugin-fs';
|
|
539
|
+
* const lines = await readTextFileLines('app.conf', { dir: BaseDirectory.App });
|
|
540
|
+
* for await (const line of lines) {
|
|
541
|
+
* console.log(line);
|
|
273
542
|
* }
|
|
274
543
|
* ```
|
|
544
|
+
* You could also call {@linkcode AsyncIterableIterator.next} to advance the
|
|
545
|
+
* iterator so you can lazily read the next line whenever you want.
|
|
275
546
|
*
|
|
276
547
|
* @since 2.0.0
|
|
277
548
|
*/
|
|
278
|
-
declare function
|
|
549
|
+
declare function readTextFileLines(path: string | URL, options?: ReadFileOptions): Promise<AsyncIterableIterator<string>>;
|
|
279
550
|
/**
|
|
280
|
-
*
|
|
281
|
-
|
|
282
|
-
|
|
551
|
+
* @since 2.0.0
|
|
552
|
+
*/
|
|
553
|
+
interface RemoveOptions {
|
|
554
|
+
/** Defaults to `false`. If set to `true`, path will be removed even if it's a non-empty directory. */
|
|
555
|
+
recursive?: boolean;
|
|
556
|
+
/** Base directory for `path` */
|
|
557
|
+
baseDir?: BaseDirectory;
|
|
558
|
+
}
|
|
559
|
+
/**
|
|
560
|
+
* Removes the named file or directory.
|
|
561
|
+
* If the directory is not empty and the `recursive` option isn't set to true, the promise will be rejected.
|
|
283
562
|
* @example
|
|
284
563
|
* ```typescript
|
|
285
|
-
* import {
|
|
286
|
-
*
|
|
287
|
-
* await
|
|
564
|
+
* import { remove, BaseDirectory } from '@tauri-apps/plugin-fs';
|
|
565
|
+
* await remove('users/file.txt', { dir: BaseDirectory.App });
|
|
566
|
+
* await remove('users', { dir: BaseDirectory.App });
|
|
288
567
|
* ```
|
|
289
568
|
*
|
|
290
|
-
* @returns A promise indicating the success or failure of the operation.
|
|
291
|
-
*
|
|
292
569
|
* @since 2.0.0
|
|
293
570
|
*/
|
|
294
|
-
declare function
|
|
571
|
+
declare function remove(path: string | URL, options?: RemoveOptions): Promise<void>;
|
|
295
572
|
/**
|
|
296
|
-
*
|
|
297
|
-
|
|
573
|
+
* @since 2.0.0
|
|
574
|
+
*/
|
|
575
|
+
interface RenameOptions {
|
|
576
|
+
/** Base directory for `oldPath`. */
|
|
577
|
+
oldPathBaseDir?: BaseDirectory;
|
|
578
|
+
/** Base directory for `newPath`. */
|
|
579
|
+
newPathBaseDir?: BaseDirectory;
|
|
580
|
+
}
|
|
581
|
+
/**
|
|
582
|
+
* Renames (moves) oldpath to newpath. Paths may be files or directories.
|
|
583
|
+
* If newpath already exists and is not a directory, rename() replaces it.
|
|
584
|
+
* OS-specific restrictions may apply when oldpath and newpath are in different directories.
|
|
585
|
+
*
|
|
586
|
+
* On Unix, this operation does not follow symlinks at either path.
|
|
587
|
+
*
|
|
298
588
|
* @example
|
|
299
589
|
* ```typescript
|
|
300
|
-
* import {
|
|
301
|
-
*
|
|
302
|
-
* await removeDir('users', { dir: BaseDirectory.AppData });
|
|
590
|
+
* import { rename, BaseDirectory } from '@tauri-apps/plugin-fs';
|
|
591
|
+
* await rename('avatar.png', 'deleted.png', { dir: BaseDirectory.App });
|
|
303
592
|
* ```
|
|
304
593
|
*
|
|
305
|
-
* @returns A promise indicating the success or failure of the operation.
|
|
306
|
-
*
|
|
307
594
|
* @since 2.0.0
|
|
308
595
|
*/
|
|
309
|
-
declare function
|
|
596
|
+
declare function rename(oldPath: string | URL, newPath: string | URL, options: RenameOptions): Promise<void>;
|
|
597
|
+
/**
|
|
598
|
+
* @since 2.0.0
|
|
599
|
+
*/
|
|
600
|
+
interface StatOptions {
|
|
601
|
+
/** Base directory for `path`. */
|
|
602
|
+
baseDir?: BaseDirectory;
|
|
603
|
+
}
|
|
310
604
|
/**
|
|
311
|
-
*
|
|
605
|
+
* Resolves to a {@linkcode FileInfo} for the specified `path`. Will always
|
|
606
|
+
* follow symlinks but will reject if the symlink points to a path outside of the scope.
|
|
607
|
+
*
|
|
312
608
|
* @example
|
|
313
609
|
* ```typescript
|
|
314
|
-
* import {
|
|
315
|
-
*
|
|
316
|
-
*
|
|
610
|
+
* import { stat, BaseDirectory } from '@tauri-apps/plugin-fs';
|
|
611
|
+
* const fileInfo = await stat("hello.txt", { dir: BaseDirectory.App });
|
|
612
|
+
* console.log(fileInfo.isFile); // true
|
|
317
613
|
* ```
|
|
318
614
|
*
|
|
319
|
-
* @returns A promise indicating the success or failure of the operation.
|
|
320
|
-
*
|
|
321
615
|
* @since 2.0.0
|
|
322
616
|
*/
|
|
323
|
-
declare function
|
|
617
|
+
declare function stat(path: string | URL, options?: StatOptions): Promise<FileInfo>;
|
|
324
618
|
/**
|
|
325
|
-
*
|
|
619
|
+
* Resolves to a {@linkcode FileInfo} for the specified `path`. If `path` is a
|
|
620
|
+
* symlink, information for the symlink will be returned instead of what it
|
|
621
|
+
* points to.
|
|
622
|
+
*
|
|
326
623
|
* @example
|
|
327
624
|
* ```typescript
|
|
328
|
-
* import {
|
|
329
|
-
*
|
|
330
|
-
*
|
|
625
|
+
* import { lstat, BaseDirectory } from '@tauri-apps/plugin-fs';
|
|
626
|
+
* const fileInfo = await lstat("hello.txt", { dir: BaseDirectory.App });
|
|
627
|
+
* console.log(fileInfo.isFile); // true
|
|
331
628
|
* ```
|
|
332
629
|
*
|
|
333
|
-
* @returns A promise indicating the success or failure of the operation.
|
|
334
|
-
*
|
|
335
630
|
* @since 2.0.0
|
|
336
631
|
*/
|
|
337
|
-
declare function
|
|
632
|
+
declare function lstat(path: string | URL, options?: StatOptions): Promise<FileInfo>;
|
|
633
|
+
/**
|
|
634
|
+
* @since 2.0.0
|
|
635
|
+
*/
|
|
636
|
+
interface TruncateOptions {
|
|
637
|
+
/** Base directory for `path`. */
|
|
638
|
+
baseDir?: BaseDirectory;
|
|
639
|
+
}
|
|
338
640
|
/**
|
|
339
|
-
*
|
|
641
|
+
* Truncates or extends the specified file, to reach the specified `len`.
|
|
642
|
+
* If `len` is `0` or not specified, then the entire file contents are truncated.
|
|
643
|
+
*
|
|
340
644
|
* @example
|
|
341
645
|
* ```typescript
|
|
342
|
-
* import {
|
|
343
|
-
* //
|
|
344
|
-
* await
|
|
646
|
+
* import { truncate, readFile, writeFile, BaseDirectory } from '@tauri-apps/plugin-fs';
|
|
647
|
+
* // truncate the entire file
|
|
648
|
+
* await truncate("my_file.txt", 0, { dir: BaseDirectory.App });
|
|
649
|
+
*
|
|
650
|
+
* // truncate part of the file
|
|
651
|
+
* let file = "file.txt";
|
|
652
|
+
* await writeFile(file, new TextEncoder().encode("Hello World"), { dir: BaseDirectory.App });
|
|
653
|
+
* await truncate(file, 7);
|
|
654
|
+
* const data = await readFile(file, { dir: BaseDirectory.App });
|
|
655
|
+
* console.log(new TextDecoder().decode(data)); // "Hello W"
|
|
345
656
|
* ```
|
|
346
657
|
*
|
|
347
|
-
* @
|
|
658
|
+
* @since 2.0.0
|
|
659
|
+
*/
|
|
660
|
+
declare function truncate(path: string | URL, len?: number, options?: TruncateOptions): Promise<void>;
|
|
661
|
+
/**
|
|
662
|
+
* @since 2.0.0
|
|
663
|
+
*/
|
|
664
|
+
interface WriteFileOptions {
|
|
665
|
+
/** Defaults to `false`. If set to `true`, will append to a file instead of overwriting previous contents. */
|
|
666
|
+
append?: boolean;
|
|
667
|
+
/** Sets the option to allow creating a new file, if one doesn't already exist at the specified path (defaults to `true`). */
|
|
668
|
+
create?: boolean;
|
|
669
|
+
/** Sets the option to create a new file, failing if it already exists. */
|
|
670
|
+
createNew?: boolean;
|
|
671
|
+
/** File permissions. Ignored on Windows. */
|
|
672
|
+
mode?: number;
|
|
673
|
+
/** Base directory for `path` */
|
|
674
|
+
baseDir?: BaseDirectory;
|
|
675
|
+
}
|
|
676
|
+
/**
|
|
677
|
+
* Write `data` to the given `path`, by default creating a new file if needed, else overwriting.
|
|
678
|
+
* @example
|
|
679
|
+
* ```typescript
|
|
680
|
+
* import { writeFile, BaseDirectory } from '@tauri-apps/plugin-fs';
|
|
681
|
+
*
|
|
682
|
+
* let encoder = new TextEncoder();
|
|
683
|
+
* let data = encoder.encode("Hello World");
|
|
684
|
+
* await writeFile('file.txt', data, { dir: BaseDirectory.App });
|
|
685
|
+
* ```
|
|
348
686
|
*
|
|
349
687
|
* @since 2.0.0
|
|
350
688
|
*/
|
|
351
|
-
declare function
|
|
689
|
+
declare function writeFile(path: string | URL, data: Uint8Array, options?: WriteFileOptions): Promise<void>;
|
|
690
|
+
/**
|
|
691
|
+
* Writes UTF-8 string `data` to the given `path`, by default creating a new file if needed, else overwriting.
|
|
692
|
+
@example
|
|
693
|
+
* ```typescript
|
|
694
|
+
* import { writeTextFile, BaseDirectory } from '@tauri-apps/plugin-fs';
|
|
695
|
+
*
|
|
696
|
+
* await writeTextFile('file.txt', "Hello world", { dir: BaseDirectory.App });
|
|
697
|
+
* ```
|
|
698
|
+
*
|
|
699
|
+
* @since 2.0.0
|
|
700
|
+
*/
|
|
701
|
+
declare function writeTextFile(path: string | URL, data: string, options?: WriteFileOptions): Promise<void>;
|
|
702
|
+
/**
|
|
703
|
+
* @since 2.0.0
|
|
704
|
+
*/
|
|
705
|
+
interface ExistsOptions {
|
|
706
|
+
/** Base directory for `path`. */
|
|
707
|
+
baseDir?: BaseDirectory;
|
|
708
|
+
}
|
|
352
709
|
/**
|
|
353
710
|
* Check if a path exists.
|
|
354
711
|
* @example
|
|
@@ -360,12 +717,68 @@ declare function renameFile(oldPath: string, newPath: string, options?: FsOption
|
|
|
360
717
|
*
|
|
361
718
|
* @since 2.0.0
|
|
362
719
|
*/
|
|
363
|
-
declare function exists(path: string, options?:
|
|
720
|
+
declare function exists(path: string | URL, options?: ExistsOptions): Promise<boolean>;
|
|
721
|
+
/**
|
|
722
|
+
* @since 2.0.0
|
|
723
|
+
*/
|
|
724
|
+
interface WatchOptions {
|
|
725
|
+
/** Watch a directory recursively */
|
|
726
|
+
recursive?: boolean;
|
|
727
|
+
/** Base directory for `path` */
|
|
728
|
+
baseDir?: BaseDirectory;
|
|
729
|
+
}
|
|
730
|
+
/**
|
|
731
|
+
* @since 2.0.0
|
|
732
|
+
*/
|
|
733
|
+
interface DebouncedWatchOptions extends WatchOptions {
|
|
734
|
+
/** Debounce delay */
|
|
735
|
+
delayMs?: number;
|
|
736
|
+
}
|
|
737
|
+
/**
|
|
738
|
+
* @since 2.0.0
|
|
739
|
+
*/
|
|
740
|
+
type RawEvent = {
|
|
741
|
+
type: RawEventKind;
|
|
742
|
+
paths: string[];
|
|
743
|
+
attrs: unknown;
|
|
744
|
+
};
|
|
745
|
+
/**
|
|
746
|
+
* @since 2.0.0
|
|
747
|
+
*/
|
|
748
|
+
type RawEventKind = "any " | {
|
|
749
|
+
access?: unknown;
|
|
750
|
+
} | {
|
|
751
|
+
create?: unknown;
|
|
752
|
+
} | {
|
|
753
|
+
modify?: unknown;
|
|
754
|
+
} | {
|
|
755
|
+
remove?: unknown;
|
|
756
|
+
} | "other";
|
|
757
|
+
/**
|
|
758
|
+
* @since 2.0.0
|
|
759
|
+
*/
|
|
760
|
+
type DebouncedEvent = {
|
|
761
|
+
kind: "Any";
|
|
762
|
+
path: string;
|
|
763
|
+
}[] | {
|
|
764
|
+
kind: "AnyContinuous";
|
|
765
|
+
path: string;
|
|
766
|
+
}[];
|
|
767
|
+
/**
|
|
768
|
+
* @since 2.0.0
|
|
769
|
+
*/
|
|
770
|
+
type UnwatchFn = () => void;
|
|
771
|
+
/**
|
|
772
|
+
* Watch changes (after a delay) on files or directories.
|
|
773
|
+
*
|
|
774
|
+
* @since 2.0.0
|
|
775
|
+
*/
|
|
776
|
+
declare function watch(paths: string | string[] | URL | URL[], cb: (event: DebouncedEvent) => void, options?: DebouncedWatchOptions): Promise<UnwatchFn>;
|
|
364
777
|
/**
|
|
365
|
-
*
|
|
778
|
+
* Watch changes on files or directories.
|
|
366
779
|
*
|
|
367
780
|
* @since 2.0.0
|
|
368
781
|
*/
|
|
369
|
-
declare function
|
|
370
|
-
export type {
|
|
371
|
-
export { BaseDirectory,
|
|
782
|
+
declare function watchImmediate(paths: string | string[] | URL | URL[], cb: (event: RawEvent) => void, options?: WatchOptions): Promise<UnwatchFn>;
|
|
783
|
+
export type { CreateOptions, OpenOptions, CopyFileOptions, MkdirOptions, DirEntry, ReadDirOptions, ReadFileOptions, RemoveOptions, RenameOptions, StatOptions, TruncateOptions, WriteFileOptions, ExistsOptions, FileInfo, WatchOptions, DebouncedWatchOptions, DebouncedEvent, RawEvent, UnwatchFn, };
|
|
784
|
+
export { BaseDirectory, FileHandle, create, open, copyFile, mkdir, readDir, readFile, readTextFile, readTextFileLines, remove, rename, SeekMode, stat, lstat, truncate, writeFile, writeTextFile, exists, watch, watchImmediate, };
|