@tauri-apps/plugin-fs 2.0.0-rc.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -4
- package/dist-js/index.cjs +92 -94
- package/dist-js/index.d.ts +29 -29
- package/dist-js/index.js +92 -94
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -2,9 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
Access the file system.
|
|
4
4
|
|
|
5
|
+
| Platform | Supported |
|
|
6
|
+
| -------- | --------- |
|
|
7
|
+
| Linux | ✓ |
|
|
8
|
+
| Windows | ✓ |
|
|
9
|
+
| macOS | ✓ |
|
|
10
|
+
| Android | ✓ |
|
|
11
|
+
| iOS | ✓ |
|
|
12
|
+
|
|
5
13
|
## Install
|
|
6
14
|
|
|
7
|
-
_This plugin requires a Rust version of at least **1.
|
|
15
|
+
_This plugin requires a Rust version of at least **1.78**_
|
|
8
16
|
|
|
9
17
|
There are three general methods of installation that we can recommend.
|
|
10
18
|
|
|
@@ -18,7 +26,7 @@ Install the Core plugin by adding the following to your `Cargo.toml` file:
|
|
|
18
26
|
|
|
19
27
|
```toml
|
|
20
28
|
[dependencies]
|
|
21
|
-
tauri-plugin-fs = "2.0.0
|
|
29
|
+
tauri-plugin-fs = "2.0.0"
|
|
22
30
|
# alternatively with Git:
|
|
23
31
|
tauri-plugin-fs = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }
|
|
24
32
|
```
|
|
@@ -60,9 +68,9 @@ fn main() {
|
|
|
60
68
|
Afterwards all the plugin's APIs are available through the JavaScript guest bindings:
|
|
61
69
|
|
|
62
70
|
```javascript
|
|
63
|
-
import { metadata } from
|
|
71
|
+
import { metadata } from '@tauri-apps/plugin-fs'
|
|
64
72
|
|
|
65
|
-
await metadata(
|
|
73
|
+
await metadata('/path/to/file')
|
|
66
74
|
```
|
|
67
75
|
|
|
68
76
|
## Contributing
|
package/dist-js/index.cjs
CHANGED
|
@@ -89,7 +89,7 @@ function parseFileInfo(r) {
|
|
|
89
89
|
gid: r.gid,
|
|
90
90
|
rdev: r.rdev,
|
|
91
91
|
blksize: r.blksize,
|
|
92
|
-
blocks: r.blocks
|
|
92
|
+
blocks: r.blocks
|
|
93
93
|
};
|
|
94
94
|
}
|
|
95
95
|
/**
|
|
@@ -119,7 +119,7 @@ class FileHandle extends core.Resource {
|
|
|
119
119
|
* @example
|
|
120
120
|
* ```typescript
|
|
121
121
|
* import { open, BaseDirectory } from "@tauri-apps/plugin-fs"
|
|
122
|
-
* // if "$
|
|
122
|
+
* // if "$APPCONFIG/foo/bar.txt" contains the text "hello world":
|
|
123
123
|
* const file = await open("foo/bar.txt", { baseDir: BaseDirectory.AppConfig });
|
|
124
124
|
* const buf = new Uint8Array(100);
|
|
125
125
|
* const numberOfBytesRead = await file.read(buf); // 11 bytes
|
|
@@ -133,9 +133,9 @@ class FileHandle extends core.Resource {
|
|
|
133
133
|
if (buffer.byteLength === 0) {
|
|
134
134
|
return 0;
|
|
135
135
|
}
|
|
136
|
-
const [data, nread] = await core.invoke(
|
|
136
|
+
const [data, nread] = await core.invoke('plugin:fs|read', {
|
|
137
137
|
rid: this.rid,
|
|
138
|
-
len: buffer.byteLength
|
|
138
|
+
len: buffer.byteLength
|
|
139
139
|
});
|
|
140
140
|
buffer.set(data);
|
|
141
141
|
return nread === 0 ? null : nread;
|
|
@@ -173,10 +173,10 @@ class FileHandle extends core.Resource {
|
|
|
173
173
|
* @since 2.0.0
|
|
174
174
|
*/
|
|
175
175
|
async seek(offset, whence) {
|
|
176
|
-
return await core.invoke(
|
|
176
|
+
return await core.invoke('plugin:fs|seek', {
|
|
177
177
|
rid: this.rid,
|
|
178
178
|
offset,
|
|
179
|
-
whence
|
|
179
|
+
whence
|
|
180
180
|
});
|
|
181
181
|
}
|
|
182
182
|
/**
|
|
@@ -194,8 +194,8 @@ class FileHandle extends core.Resource {
|
|
|
194
194
|
* @since 2.0.0
|
|
195
195
|
*/
|
|
196
196
|
async stat() {
|
|
197
|
-
const res = await core.invoke(
|
|
198
|
-
rid: this.rid
|
|
197
|
+
const res = await core.invoke('plugin:fs|fstat', {
|
|
198
|
+
rid: this.rid
|
|
199
199
|
});
|
|
200
200
|
return parseFileInfo(res);
|
|
201
201
|
}
|
|
@@ -224,9 +224,9 @@ class FileHandle extends core.Resource {
|
|
|
224
224
|
* @since 2.0.0
|
|
225
225
|
*/
|
|
226
226
|
async truncate(len) {
|
|
227
|
-
await core.invoke(
|
|
227
|
+
await core.invoke('plugin:fs|ftruncate', {
|
|
228
228
|
rid: this.rid,
|
|
229
|
-
len
|
|
229
|
+
len
|
|
230
230
|
});
|
|
231
231
|
}
|
|
232
232
|
/**
|
|
@@ -250,9 +250,9 @@ class FileHandle extends core.Resource {
|
|
|
250
250
|
* @since 2.0.0
|
|
251
251
|
*/
|
|
252
252
|
async write(data) {
|
|
253
|
-
return await core.invoke(
|
|
253
|
+
return await core.invoke('plugin:fs|write', {
|
|
254
254
|
rid: this.rid,
|
|
255
|
-
data
|
|
255
|
+
data
|
|
256
256
|
});
|
|
257
257
|
}
|
|
258
258
|
}
|
|
@@ -271,12 +271,12 @@ class FileHandle extends core.Resource {
|
|
|
271
271
|
* @since 2.0.0
|
|
272
272
|
*/
|
|
273
273
|
async function create(path, options) {
|
|
274
|
-
if (path instanceof URL && path.protocol !==
|
|
275
|
-
throw new TypeError(
|
|
274
|
+
if (path instanceof URL && path.protocol !== 'file:') {
|
|
275
|
+
throw new TypeError('Must be a file URL.');
|
|
276
276
|
}
|
|
277
|
-
const rid = await core.invoke(
|
|
277
|
+
const rid = await core.invoke('plugin:fs|create', {
|
|
278
278
|
path: path instanceof URL ? path.toString() : path,
|
|
279
|
-
options
|
|
279
|
+
options
|
|
280
280
|
});
|
|
281
281
|
return new FileHandle(rid);
|
|
282
282
|
}
|
|
@@ -297,12 +297,12 @@ async function create(path, options) {
|
|
|
297
297
|
* @since 2.0.0
|
|
298
298
|
*/
|
|
299
299
|
async function open(path, options) {
|
|
300
|
-
if (path instanceof URL && path.protocol !==
|
|
301
|
-
throw new TypeError(
|
|
300
|
+
if (path instanceof URL && path.protocol !== 'file:') {
|
|
301
|
+
throw new TypeError('Must be a file URL.');
|
|
302
302
|
}
|
|
303
|
-
const rid = await core.invoke(
|
|
303
|
+
const rid = await core.invoke('plugin:fs|open', {
|
|
304
304
|
path: path instanceof URL ? path.toString() : path,
|
|
305
|
-
options
|
|
305
|
+
options
|
|
306
306
|
});
|
|
307
307
|
return new FileHandle(rid);
|
|
308
308
|
}
|
|
@@ -317,14 +317,14 @@ async function open(path, options) {
|
|
|
317
317
|
* @since 2.0.0
|
|
318
318
|
*/
|
|
319
319
|
async function copyFile(fromPath, toPath, options) {
|
|
320
|
-
if ((fromPath instanceof URL && fromPath.protocol !==
|
|
321
|
-
(toPath instanceof URL && toPath.protocol !==
|
|
322
|
-
throw new TypeError(
|
|
320
|
+
if ((fromPath instanceof URL && fromPath.protocol !== 'file:') ||
|
|
321
|
+
(toPath instanceof URL && toPath.protocol !== 'file:')) {
|
|
322
|
+
throw new TypeError('Must be a file URL.');
|
|
323
323
|
}
|
|
324
|
-
await core.invoke(
|
|
324
|
+
await core.invoke('plugin:fs|copy_file', {
|
|
325
325
|
fromPath: fromPath instanceof URL ? fromPath.toString() : fromPath,
|
|
326
326
|
toPath: toPath instanceof URL ? toPath.toString() : toPath,
|
|
327
|
-
options
|
|
327
|
+
options
|
|
328
328
|
});
|
|
329
329
|
}
|
|
330
330
|
/**
|
|
@@ -338,12 +338,12 @@ async function copyFile(fromPath, toPath, options) {
|
|
|
338
338
|
* @since 2.0.0
|
|
339
339
|
*/
|
|
340
340
|
async function mkdir(path, options) {
|
|
341
|
-
if (path instanceof URL && path.protocol !==
|
|
342
|
-
throw new TypeError(
|
|
341
|
+
if (path instanceof URL && path.protocol !== 'file:') {
|
|
342
|
+
throw new TypeError('Must be a file URL.');
|
|
343
343
|
}
|
|
344
|
-
await core.invoke(
|
|
344
|
+
await core.invoke('plugin:fs|mkdir', {
|
|
345
345
|
path: path instanceof URL ? path.toString() : path,
|
|
346
|
-
options
|
|
346
|
+
options
|
|
347
347
|
});
|
|
348
348
|
}
|
|
349
349
|
/**
|
|
@@ -369,12 +369,12 @@ async function mkdir(path, options) {
|
|
|
369
369
|
* @since 2.0.0
|
|
370
370
|
*/
|
|
371
371
|
async function readDir(path, options) {
|
|
372
|
-
if (path instanceof URL && path.protocol !==
|
|
373
|
-
throw new TypeError(
|
|
372
|
+
if (path instanceof URL && path.protocol !== 'file:') {
|
|
373
|
+
throw new TypeError('Must be a file URL.');
|
|
374
374
|
}
|
|
375
|
-
return await core.invoke(
|
|
375
|
+
return await core.invoke('plugin:fs|read_dir', {
|
|
376
376
|
path: path instanceof URL ? path.toString() : path,
|
|
377
|
-
options
|
|
377
|
+
options
|
|
378
378
|
});
|
|
379
379
|
}
|
|
380
380
|
/**
|
|
@@ -389,16 +389,14 @@ async function readDir(path, options) {
|
|
|
389
389
|
* @since 2.0.0
|
|
390
390
|
*/
|
|
391
391
|
async function readFile(path, options) {
|
|
392
|
-
if (path instanceof URL && path.protocol !==
|
|
393
|
-
throw new TypeError(
|
|
392
|
+
if (path instanceof URL && path.protocol !== 'file:') {
|
|
393
|
+
throw new TypeError('Must be a file URL.');
|
|
394
394
|
}
|
|
395
|
-
const arr = await core.invoke(
|
|
395
|
+
const arr = await core.invoke('plugin:fs|read_file', {
|
|
396
396
|
path: path instanceof URL ? path.toString() : path,
|
|
397
|
-
options
|
|
397
|
+
options
|
|
398
398
|
});
|
|
399
|
-
return arr instanceof ArrayBuffer
|
|
400
|
-
? new Uint8Array(arr)
|
|
401
|
-
: Uint8Array.from(arr);
|
|
399
|
+
return arr instanceof ArrayBuffer ? new Uint8Array(arr) : Uint8Array.from(arr);
|
|
402
400
|
}
|
|
403
401
|
/**
|
|
404
402
|
* Reads and returns the entire contents of a file as UTF-8 string.
|
|
@@ -411,12 +409,12 @@ async function readFile(path, options) {
|
|
|
411
409
|
* @since 2.0.0
|
|
412
410
|
*/
|
|
413
411
|
async function readTextFile(path, options) {
|
|
414
|
-
if (path instanceof URL && path.protocol !==
|
|
415
|
-
throw new TypeError(
|
|
412
|
+
if (path instanceof URL && path.protocol !== 'file:') {
|
|
413
|
+
throw new TypeError('Must be a file URL.');
|
|
416
414
|
}
|
|
417
|
-
return await core.invoke(
|
|
415
|
+
return await core.invoke('plugin:fs|read_text_file', {
|
|
418
416
|
path: path instanceof URL ? path.toString() : path,
|
|
419
|
-
options
|
|
417
|
+
options
|
|
420
418
|
});
|
|
421
419
|
}
|
|
422
420
|
/**
|
|
@@ -435,8 +433,8 @@ async function readTextFile(path, options) {
|
|
|
435
433
|
* @since 2.0.0
|
|
436
434
|
*/
|
|
437
435
|
async function readTextFileLines(path, options) {
|
|
438
|
-
if (path instanceof URL && path.protocol !==
|
|
439
|
-
throw new TypeError(
|
|
436
|
+
if (path instanceof URL && path.protocol !== 'file:') {
|
|
437
|
+
throw new TypeError('Must be a file URL.');
|
|
440
438
|
}
|
|
441
439
|
const pathStr = path instanceof URL ? path.toString() : path;
|
|
442
440
|
return await Promise.resolve({
|
|
@@ -444,23 +442,23 @@ async function readTextFileLines(path, options) {
|
|
|
444
442
|
rid: null,
|
|
445
443
|
async next() {
|
|
446
444
|
if (this.rid === null) {
|
|
447
|
-
this.rid = await core.invoke(
|
|
445
|
+
this.rid = await core.invoke('plugin:fs|read_text_file_lines', {
|
|
448
446
|
path: pathStr,
|
|
449
|
-
options
|
|
447
|
+
options
|
|
450
448
|
});
|
|
451
449
|
}
|
|
452
|
-
const [line, done] = await core.invoke(
|
|
450
|
+
const [line, done] = await core.invoke('plugin:fs|read_text_file_lines_next', { rid: this.rid });
|
|
453
451
|
// an iteration is over, reset rid for next iteration
|
|
454
452
|
if (done)
|
|
455
453
|
this.rid = null;
|
|
456
454
|
return {
|
|
457
|
-
value: done ?
|
|
458
|
-
done
|
|
455
|
+
value: done ? '' : line,
|
|
456
|
+
done
|
|
459
457
|
};
|
|
460
458
|
},
|
|
461
459
|
[Symbol.asyncIterator]() {
|
|
462
460
|
return this;
|
|
463
|
-
}
|
|
461
|
+
}
|
|
464
462
|
});
|
|
465
463
|
}
|
|
466
464
|
/**
|
|
@@ -476,12 +474,12 @@ async function readTextFileLines(path, options) {
|
|
|
476
474
|
* @since 2.0.0
|
|
477
475
|
*/
|
|
478
476
|
async function remove(path, options) {
|
|
479
|
-
if (path instanceof URL && path.protocol !==
|
|
480
|
-
throw new TypeError(
|
|
477
|
+
if (path instanceof URL && path.protocol !== 'file:') {
|
|
478
|
+
throw new TypeError('Must be a file URL.');
|
|
481
479
|
}
|
|
482
|
-
await core.invoke(
|
|
480
|
+
await core.invoke('plugin:fs|remove', {
|
|
483
481
|
path: path instanceof URL ? path.toString() : path,
|
|
484
|
-
options
|
|
482
|
+
options
|
|
485
483
|
});
|
|
486
484
|
}
|
|
487
485
|
/**
|
|
@@ -500,14 +498,14 @@ async function remove(path, options) {
|
|
|
500
498
|
* @since 2.0.0
|
|
501
499
|
*/
|
|
502
500
|
async function rename(oldPath, newPath, options) {
|
|
503
|
-
if ((oldPath instanceof URL && oldPath.protocol !==
|
|
504
|
-
(newPath instanceof URL && newPath.protocol !==
|
|
505
|
-
throw new TypeError(
|
|
501
|
+
if ((oldPath instanceof URL && oldPath.protocol !== 'file:') ||
|
|
502
|
+
(newPath instanceof URL && newPath.protocol !== 'file:')) {
|
|
503
|
+
throw new TypeError('Must be a file URL.');
|
|
506
504
|
}
|
|
507
|
-
await core.invoke(
|
|
505
|
+
await core.invoke('plugin:fs|rename', {
|
|
508
506
|
oldPath: oldPath instanceof URL ? oldPath.toString() : oldPath,
|
|
509
507
|
newPath: newPath instanceof URL ? newPath.toString() : newPath,
|
|
510
|
-
options
|
|
508
|
+
options
|
|
511
509
|
});
|
|
512
510
|
}
|
|
513
511
|
/**
|
|
@@ -524,9 +522,9 @@ async function rename(oldPath, newPath, options) {
|
|
|
524
522
|
* @since 2.0.0
|
|
525
523
|
*/
|
|
526
524
|
async function stat(path, options) {
|
|
527
|
-
const res = await core.invoke(
|
|
525
|
+
const res = await core.invoke('plugin:fs|stat', {
|
|
528
526
|
path: path instanceof URL ? path.toString() : path,
|
|
529
|
-
options
|
|
527
|
+
options
|
|
530
528
|
});
|
|
531
529
|
return parseFileInfo(res);
|
|
532
530
|
}
|
|
@@ -545,9 +543,9 @@ async function stat(path, options) {
|
|
|
545
543
|
* @since 2.0.0
|
|
546
544
|
*/
|
|
547
545
|
async function lstat(path, options) {
|
|
548
|
-
const res = await core.invoke(
|
|
546
|
+
const res = await core.invoke('plugin:fs|lstat', {
|
|
549
547
|
path: path instanceof URL ? path.toString() : path,
|
|
550
|
-
options
|
|
548
|
+
options
|
|
551
549
|
});
|
|
552
550
|
return parseFileInfo(res);
|
|
553
551
|
}
|
|
@@ -572,13 +570,13 @@ async function lstat(path, options) {
|
|
|
572
570
|
* @since 2.0.0
|
|
573
571
|
*/
|
|
574
572
|
async function truncate(path, len, options) {
|
|
575
|
-
if (path instanceof URL && path.protocol !==
|
|
576
|
-
throw new TypeError(
|
|
573
|
+
if (path instanceof URL && path.protocol !== 'file:') {
|
|
574
|
+
throw new TypeError('Must be a file URL.');
|
|
577
575
|
}
|
|
578
|
-
await core.invoke(
|
|
576
|
+
await core.invoke('plugin:fs|truncate', {
|
|
579
577
|
path: path instanceof URL ? path.toString() : path,
|
|
580
578
|
len,
|
|
581
|
-
options
|
|
579
|
+
options
|
|
582
580
|
});
|
|
583
581
|
}
|
|
584
582
|
/**
|
|
@@ -595,14 +593,14 @@ async function truncate(path, len, options) {
|
|
|
595
593
|
* @since 2.0.0
|
|
596
594
|
*/
|
|
597
595
|
async function writeFile(path, data, options) {
|
|
598
|
-
if (path instanceof URL && path.protocol !==
|
|
599
|
-
throw new TypeError(
|
|
596
|
+
if (path instanceof URL && path.protocol !== 'file:') {
|
|
597
|
+
throw new TypeError('Must be a file URL.');
|
|
600
598
|
}
|
|
601
|
-
await core.invoke(
|
|
599
|
+
await core.invoke('plugin:fs|write_file', data, {
|
|
602
600
|
headers: {
|
|
603
|
-
path: path instanceof URL ? path.toString() : path,
|
|
604
|
-
options: JSON.stringify(options)
|
|
605
|
-
}
|
|
601
|
+
path: encodeURIComponent(path instanceof URL ? path.toString() : path),
|
|
602
|
+
options: JSON.stringify(options)
|
|
603
|
+
}
|
|
606
604
|
});
|
|
607
605
|
}
|
|
608
606
|
/**
|
|
@@ -617,13 +615,13 @@ async function writeFile(path, data, options) {
|
|
|
617
615
|
* @since 2.0.0
|
|
618
616
|
*/
|
|
619
617
|
async function writeTextFile(path, data, options) {
|
|
620
|
-
if (path instanceof URL && path.protocol !==
|
|
621
|
-
throw new TypeError(
|
|
618
|
+
if (path instanceof URL && path.protocol !== 'file:') {
|
|
619
|
+
throw new TypeError('Must be a file URL.');
|
|
622
620
|
}
|
|
623
|
-
await core.invoke(
|
|
621
|
+
await core.invoke('plugin:fs|write_text_file', {
|
|
624
622
|
path: path instanceof URL ? path.toString() : path,
|
|
625
623
|
data,
|
|
626
|
-
options
|
|
624
|
+
options
|
|
627
625
|
});
|
|
628
626
|
}
|
|
629
627
|
/**
|
|
@@ -638,16 +636,16 @@ async function writeTextFile(path, data, options) {
|
|
|
638
636
|
* @since 2.0.0
|
|
639
637
|
*/
|
|
640
638
|
async function exists(path, options) {
|
|
641
|
-
if (path instanceof URL && path.protocol !==
|
|
642
|
-
throw new TypeError(
|
|
639
|
+
if (path instanceof URL && path.protocol !== 'file:') {
|
|
640
|
+
throw new TypeError('Must be a file URL.');
|
|
643
641
|
}
|
|
644
|
-
return await core.invoke(
|
|
642
|
+
return await core.invoke('plugin:fs|exists', {
|
|
645
643
|
path: path instanceof URL ? path.toString() : path,
|
|
646
|
-
options
|
|
644
|
+
options
|
|
647
645
|
});
|
|
648
646
|
}
|
|
649
647
|
async function unwatch(rid) {
|
|
650
|
-
await core.invoke(
|
|
648
|
+
await core.invoke('plugin:fs|unwatch', { rid });
|
|
651
649
|
}
|
|
652
650
|
/**
|
|
653
651
|
* Watch changes (after a delay) on files or directories.
|
|
@@ -658,20 +656,20 @@ async function watch(paths, cb, options) {
|
|
|
658
656
|
const opts = {
|
|
659
657
|
recursive: false,
|
|
660
658
|
delayMs: 2000,
|
|
661
|
-
...options
|
|
659
|
+
...options
|
|
662
660
|
};
|
|
663
661
|
const watchPaths = Array.isArray(paths) ? paths : [paths];
|
|
664
662
|
for (const path of watchPaths) {
|
|
665
|
-
if (path instanceof URL && path.protocol !==
|
|
666
|
-
throw new TypeError(
|
|
663
|
+
if (path instanceof URL && path.protocol !== 'file:') {
|
|
664
|
+
throw new TypeError('Must be a file URL.');
|
|
667
665
|
}
|
|
668
666
|
}
|
|
669
667
|
const onEvent = new core.Channel();
|
|
670
668
|
onEvent.onmessage = cb;
|
|
671
|
-
const rid = await core.invoke(
|
|
669
|
+
const rid = await core.invoke('plugin:fs|watch', {
|
|
672
670
|
paths: watchPaths.map((p) => (p instanceof URL ? p.toString() : p)),
|
|
673
671
|
options: opts,
|
|
674
|
-
onEvent
|
|
672
|
+
onEvent
|
|
675
673
|
});
|
|
676
674
|
return () => {
|
|
677
675
|
void unwatch(rid);
|
|
@@ -686,20 +684,20 @@ async function watchImmediate(paths, cb, options) {
|
|
|
686
684
|
const opts = {
|
|
687
685
|
recursive: false,
|
|
688
686
|
...options,
|
|
689
|
-
delayMs: null
|
|
687
|
+
delayMs: null
|
|
690
688
|
};
|
|
691
689
|
const watchPaths = Array.isArray(paths) ? paths : [paths];
|
|
692
690
|
for (const path of watchPaths) {
|
|
693
|
-
if (path instanceof URL && path.protocol !==
|
|
694
|
-
throw new TypeError(
|
|
691
|
+
if (path instanceof URL && path.protocol !== 'file:') {
|
|
692
|
+
throw new TypeError('Must be a file URL.');
|
|
695
693
|
}
|
|
696
694
|
}
|
|
697
695
|
const onEvent = new core.Channel();
|
|
698
696
|
onEvent.onmessage = cb;
|
|
699
|
-
const rid = await core.invoke(
|
|
697
|
+
const rid = await core.invoke('plugin:fs|watch', {
|
|
700
698
|
paths: watchPaths.map((p) => (p instanceof URL ? p.toString() : p)),
|
|
701
699
|
options: opts,
|
|
702
|
-
onEvent
|
|
700
|
+
onEvent
|
|
703
701
|
});
|
|
704
702
|
return () => {
|
|
705
703
|
void unwatch(rid);
|
package/dist-js/index.d.ts
CHANGED
|
@@ -56,8 +56,8 @@
|
|
|
56
56
|
*
|
|
57
57
|
* @module
|
|
58
58
|
*/
|
|
59
|
-
import { BaseDirectory } from
|
|
60
|
-
import { Resource } from
|
|
59
|
+
import { BaseDirectory } from '@tauri-apps/api/path';
|
|
60
|
+
import { Resource } from '@tauri-apps/api/core';
|
|
61
61
|
declare enum SeekMode {
|
|
62
62
|
Start = 0,
|
|
63
63
|
Current = 1,
|
|
@@ -219,7 +219,7 @@ declare class FileHandle extends Resource {
|
|
|
219
219
|
* @example
|
|
220
220
|
* ```typescript
|
|
221
221
|
* import { open, BaseDirectory } from "@tauri-apps/plugin-fs"
|
|
222
|
-
* // if "$
|
|
222
|
+
* // if "$APPCONFIG/foo/bar.txt" contains the text "hello world":
|
|
223
223
|
* const file = await open("foo/bar.txt", { baseDir: BaseDirectory.AppConfig });
|
|
224
224
|
* const buf = new Uint8Array(100);
|
|
225
225
|
* const numberOfBytesRead = await file.read(buf); // 11 bytes
|
|
@@ -751,7 +751,7 @@ interface WatchEvent {
|
|
|
751
751
|
/**
|
|
752
752
|
* @since 2.0.0
|
|
753
753
|
*/
|
|
754
|
-
type WatchEventKind =
|
|
754
|
+
type WatchEventKind = 'any' | {
|
|
755
755
|
access: WatchEventKindAccess;
|
|
756
756
|
} | {
|
|
757
757
|
create: WatchEventKindCreate;
|
|
@@ -759,61 +759,61 @@ type WatchEventKind = "any" | {
|
|
|
759
759
|
modify: WatchEventKindModify;
|
|
760
760
|
} | {
|
|
761
761
|
remove: WatchEventKindRemove;
|
|
762
|
-
} |
|
|
762
|
+
} | 'other';
|
|
763
763
|
/**
|
|
764
764
|
* @since 2.0.0
|
|
765
765
|
*/
|
|
766
766
|
type WatchEventKindAccess = {
|
|
767
|
-
kind:
|
|
767
|
+
kind: 'any';
|
|
768
768
|
} | {
|
|
769
|
-
kind:
|
|
770
|
-
mode:
|
|
769
|
+
kind: 'close';
|
|
770
|
+
mode: 'any' | 'execute' | 'read' | 'write' | 'other';
|
|
771
771
|
} | {
|
|
772
|
-
kind:
|
|
773
|
-
mode:
|
|
772
|
+
kind: 'open';
|
|
773
|
+
mode: 'any' | 'execute' | 'read' | 'write' | 'other';
|
|
774
774
|
} | {
|
|
775
|
-
kind:
|
|
775
|
+
kind: 'other';
|
|
776
776
|
};
|
|
777
777
|
/**
|
|
778
778
|
* @since 2.0.0
|
|
779
779
|
*/
|
|
780
780
|
type WatchEventKindCreate = {
|
|
781
|
-
kind:
|
|
781
|
+
kind: 'any';
|
|
782
782
|
} | {
|
|
783
|
-
kind:
|
|
783
|
+
kind: 'file';
|
|
784
784
|
} | {
|
|
785
|
-
kind:
|
|
785
|
+
kind: 'folder';
|
|
786
786
|
} | {
|
|
787
|
-
kind:
|
|
787
|
+
kind: 'other';
|
|
788
788
|
};
|
|
789
789
|
/**
|
|
790
790
|
* @since 2.0.0
|
|
791
791
|
*/
|
|
792
792
|
type WatchEventKindModify = {
|
|
793
|
-
kind:
|
|
793
|
+
kind: 'any';
|
|
794
794
|
} | {
|
|
795
|
-
kind:
|
|
796
|
-
mode:
|
|
795
|
+
kind: 'data';
|
|
796
|
+
mode: 'any' | 'size' | 'content' | 'other';
|
|
797
797
|
} | {
|
|
798
|
-
kind:
|
|
799
|
-
mode:
|
|
798
|
+
kind: 'metadata';
|
|
799
|
+
mode: 'any' | 'access-time' | 'write-time' | 'permissions' | 'ownership' | 'extended' | 'other';
|
|
800
800
|
} | {
|
|
801
|
-
kind:
|
|
802
|
-
mode:
|
|
801
|
+
kind: 'rename';
|
|
802
|
+
mode: 'any' | 'to' | 'from' | 'both' | 'other';
|
|
803
803
|
} | {
|
|
804
|
-
kind:
|
|
804
|
+
kind: 'other';
|
|
805
805
|
};
|
|
806
806
|
/**
|
|
807
807
|
* @since 2.0.0
|
|
808
808
|
*/
|
|
809
809
|
type WatchEventKindRemove = {
|
|
810
|
-
kind:
|
|
810
|
+
kind: 'any';
|
|
811
811
|
} | {
|
|
812
|
-
kind:
|
|
812
|
+
kind: 'file';
|
|
813
813
|
} | {
|
|
814
|
-
kind:
|
|
814
|
+
kind: 'folder';
|
|
815
815
|
} | {
|
|
816
|
-
kind:
|
|
816
|
+
kind: 'other';
|
|
817
817
|
};
|
|
818
818
|
/**
|
|
819
819
|
* @since 2.0.0
|
|
@@ -831,5 +831,5 @@ declare function watch(paths: string | string[] | URL | URL[], cb: (event: Watch
|
|
|
831
831
|
* @since 2.0.0
|
|
832
832
|
*/
|
|
833
833
|
declare function watchImmediate(paths: string | string[] | URL | URL[], cb: (event: WatchEvent) => void, options?: WatchOptions): Promise<UnwatchFn>;
|
|
834
|
-
export type { CreateOptions, OpenOptions, CopyFileOptions, MkdirOptions, DirEntry, ReadDirOptions, ReadFileOptions, RemoveOptions, RenameOptions, StatOptions, TruncateOptions, WriteFileOptions, ExistsOptions, FileInfo, WatchOptions, DebouncedWatchOptions, WatchEvent, WatchEventKind, WatchEventKindAccess, WatchEventKindCreate, WatchEventKindModify, WatchEventKindRemove, UnwatchFn
|
|
835
|
-
export { BaseDirectory, FileHandle, create, open, copyFile, mkdir, readDir, readFile, readTextFile, readTextFileLines, remove, rename, SeekMode, stat, lstat, truncate, writeFile, writeTextFile, exists, watch, watchImmediate
|
|
834
|
+
export type { CreateOptions, OpenOptions, CopyFileOptions, MkdirOptions, DirEntry, ReadDirOptions, ReadFileOptions, RemoveOptions, RenameOptions, StatOptions, TruncateOptions, WriteFileOptions, ExistsOptions, FileInfo, WatchOptions, DebouncedWatchOptions, WatchEvent, WatchEventKind, WatchEventKindAccess, WatchEventKindCreate, WatchEventKindModify, WatchEventKindRemove, UnwatchFn };
|
|
835
|
+
export { BaseDirectory, FileHandle, create, open, copyFile, mkdir, readDir, readFile, readTextFile, readTextFileLines, remove, rename, SeekMode, stat, lstat, truncate, writeFile, writeTextFile, exists, watch, watchImmediate };
|
package/dist-js/index.js
CHANGED
|
@@ -87,7 +87,7 @@ function parseFileInfo(r) {
|
|
|
87
87
|
gid: r.gid,
|
|
88
88
|
rdev: r.rdev,
|
|
89
89
|
blksize: r.blksize,
|
|
90
|
-
blocks: r.blocks
|
|
90
|
+
blocks: r.blocks
|
|
91
91
|
};
|
|
92
92
|
}
|
|
93
93
|
/**
|
|
@@ -117,7 +117,7 @@ class FileHandle extends Resource {
|
|
|
117
117
|
* @example
|
|
118
118
|
* ```typescript
|
|
119
119
|
* import { open, BaseDirectory } from "@tauri-apps/plugin-fs"
|
|
120
|
-
* // if "$
|
|
120
|
+
* // if "$APPCONFIG/foo/bar.txt" contains the text "hello world":
|
|
121
121
|
* const file = await open("foo/bar.txt", { baseDir: BaseDirectory.AppConfig });
|
|
122
122
|
* const buf = new Uint8Array(100);
|
|
123
123
|
* const numberOfBytesRead = await file.read(buf); // 11 bytes
|
|
@@ -131,9 +131,9 @@ class FileHandle extends Resource {
|
|
|
131
131
|
if (buffer.byteLength === 0) {
|
|
132
132
|
return 0;
|
|
133
133
|
}
|
|
134
|
-
const [data, nread] = await invoke(
|
|
134
|
+
const [data, nread] = await invoke('plugin:fs|read', {
|
|
135
135
|
rid: this.rid,
|
|
136
|
-
len: buffer.byteLength
|
|
136
|
+
len: buffer.byteLength
|
|
137
137
|
});
|
|
138
138
|
buffer.set(data);
|
|
139
139
|
return nread === 0 ? null : nread;
|
|
@@ -171,10 +171,10 @@ class FileHandle extends Resource {
|
|
|
171
171
|
* @since 2.0.0
|
|
172
172
|
*/
|
|
173
173
|
async seek(offset, whence) {
|
|
174
|
-
return await invoke(
|
|
174
|
+
return await invoke('plugin:fs|seek', {
|
|
175
175
|
rid: this.rid,
|
|
176
176
|
offset,
|
|
177
|
-
whence
|
|
177
|
+
whence
|
|
178
178
|
});
|
|
179
179
|
}
|
|
180
180
|
/**
|
|
@@ -192,8 +192,8 @@ class FileHandle extends Resource {
|
|
|
192
192
|
* @since 2.0.0
|
|
193
193
|
*/
|
|
194
194
|
async stat() {
|
|
195
|
-
const res = await invoke(
|
|
196
|
-
rid: this.rid
|
|
195
|
+
const res = await invoke('plugin:fs|fstat', {
|
|
196
|
+
rid: this.rid
|
|
197
197
|
});
|
|
198
198
|
return parseFileInfo(res);
|
|
199
199
|
}
|
|
@@ -222,9 +222,9 @@ class FileHandle extends Resource {
|
|
|
222
222
|
* @since 2.0.0
|
|
223
223
|
*/
|
|
224
224
|
async truncate(len) {
|
|
225
|
-
await invoke(
|
|
225
|
+
await invoke('plugin:fs|ftruncate', {
|
|
226
226
|
rid: this.rid,
|
|
227
|
-
len
|
|
227
|
+
len
|
|
228
228
|
});
|
|
229
229
|
}
|
|
230
230
|
/**
|
|
@@ -248,9 +248,9 @@ class FileHandle extends Resource {
|
|
|
248
248
|
* @since 2.0.0
|
|
249
249
|
*/
|
|
250
250
|
async write(data) {
|
|
251
|
-
return await invoke(
|
|
251
|
+
return await invoke('plugin:fs|write', {
|
|
252
252
|
rid: this.rid,
|
|
253
|
-
data
|
|
253
|
+
data
|
|
254
254
|
});
|
|
255
255
|
}
|
|
256
256
|
}
|
|
@@ -269,12 +269,12 @@ class FileHandle extends Resource {
|
|
|
269
269
|
* @since 2.0.0
|
|
270
270
|
*/
|
|
271
271
|
async function create(path, options) {
|
|
272
|
-
if (path instanceof URL && path.protocol !==
|
|
273
|
-
throw new TypeError(
|
|
272
|
+
if (path instanceof URL && path.protocol !== 'file:') {
|
|
273
|
+
throw new TypeError('Must be a file URL.');
|
|
274
274
|
}
|
|
275
|
-
const rid = await invoke(
|
|
275
|
+
const rid = await invoke('plugin:fs|create', {
|
|
276
276
|
path: path instanceof URL ? path.toString() : path,
|
|
277
|
-
options
|
|
277
|
+
options
|
|
278
278
|
});
|
|
279
279
|
return new FileHandle(rid);
|
|
280
280
|
}
|
|
@@ -295,12 +295,12 @@ async function create(path, options) {
|
|
|
295
295
|
* @since 2.0.0
|
|
296
296
|
*/
|
|
297
297
|
async function open(path, options) {
|
|
298
|
-
if (path instanceof URL && path.protocol !==
|
|
299
|
-
throw new TypeError(
|
|
298
|
+
if (path instanceof URL && path.protocol !== 'file:') {
|
|
299
|
+
throw new TypeError('Must be a file URL.');
|
|
300
300
|
}
|
|
301
|
-
const rid = await invoke(
|
|
301
|
+
const rid = await invoke('plugin:fs|open', {
|
|
302
302
|
path: path instanceof URL ? path.toString() : path,
|
|
303
|
-
options
|
|
303
|
+
options
|
|
304
304
|
});
|
|
305
305
|
return new FileHandle(rid);
|
|
306
306
|
}
|
|
@@ -315,14 +315,14 @@ async function open(path, options) {
|
|
|
315
315
|
* @since 2.0.0
|
|
316
316
|
*/
|
|
317
317
|
async function copyFile(fromPath, toPath, options) {
|
|
318
|
-
if ((fromPath instanceof URL && fromPath.protocol !==
|
|
319
|
-
(toPath instanceof URL && toPath.protocol !==
|
|
320
|
-
throw new TypeError(
|
|
318
|
+
if ((fromPath instanceof URL && fromPath.protocol !== 'file:') ||
|
|
319
|
+
(toPath instanceof URL && toPath.protocol !== 'file:')) {
|
|
320
|
+
throw new TypeError('Must be a file URL.');
|
|
321
321
|
}
|
|
322
|
-
await invoke(
|
|
322
|
+
await invoke('plugin:fs|copy_file', {
|
|
323
323
|
fromPath: fromPath instanceof URL ? fromPath.toString() : fromPath,
|
|
324
324
|
toPath: toPath instanceof URL ? toPath.toString() : toPath,
|
|
325
|
-
options
|
|
325
|
+
options
|
|
326
326
|
});
|
|
327
327
|
}
|
|
328
328
|
/**
|
|
@@ -336,12 +336,12 @@ async function copyFile(fromPath, toPath, options) {
|
|
|
336
336
|
* @since 2.0.0
|
|
337
337
|
*/
|
|
338
338
|
async function mkdir(path, options) {
|
|
339
|
-
if (path instanceof URL && path.protocol !==
|
|
340
|
-
throw new TypeError(
|
|
339
|
+
if (path instanceof URL && path.protocol !== 'file:') {
|
|
340
|
+
throw new TypeError('Must be a file URL.');
|
|
341
341
|
}
|
|
342
|
-
await invoke(
|
|
342
|
+
await invoke('plugin:fs|mkdir', {
|
|
343
343
|
path: path instanceof URL ? path.toString() : path,
|
|
344
|
-
options
|
|
344
|
+
options
|
|
345
345
|
});
|
|
346
346
|
}
|
|
347
347
|
/**
|
|
@@ -367,12 +367,12 @@ async function mkdir(path, options) {
|
|
|
367
367
|
* @since 2.0.0
|
|
368
368
|
*/
|
|
369
369
|
async function readDir(path, options) {
|
|
370
|
-
if (path instanceof URL && path.protocol !==
|
|
371
|
-
throw new TypeError(
|
|
370
|
+
if (path instanceof URL && path.protocol !== 'file:') {
|
|
371
|
+
throw new TypeError('Must be a file URL.');
|
|
372
372
|
}
|
|
373
|
-
return await invoke(
|
|
373
|
+
return await invoke('plugin:fs|read_dir', {
|
|
374
374
|
path: path instanceof URL ? path.toString() : path,
|
|
375
|
-
options
|
|
375
|
+
options
|
|
376
376
|
});
|
|
377
377
|
}
|
|
378
378
|
/**
|
|
@@ -387,16 +387,14 @@ async function readDir(path, options) {
|
|
|
387
387
|
* @since 2.0.0
|
|
388
388
|
*/
|
|
389
389
|
async function readFile(path, options) {
|
|
390
|
-
if (path instanceof URL && path.protocol !==
|
|
391
|
-
throw new TypeError(
|
|
390
|
+
if (path instanceof URL && path.protocol !== 'file:') {
|
|
391
|
+
throw new TypeError('Must be a file URL.');
|
|
392
392
|
}
|
|
393
|
-
const arr = await invoke(
|
|
393
|
+
const arr = await invoke('plugin:fs|read_file', {
|
|
394
394
|
path: path instanceof URL ? path.toString() : path,
|
|
395
|
-
options
|
|
395
|
+
options
|
|
396
396
|
});
|
|
397
|
-
return arr instanceof ArrayBuffer
|
|
398
|
-
? new Uint8Array(arr)
|
|
399
|
-
: Uint8Array.from(arr);
|
|
397
|
+
return arr instanceof ArrayBuffer ? new Uint8Array(arr) : Uint8Array.from(arr);
|
|
400
398
|
}
|
|
401
399
|
/**
|
|
402
400
|
* Reads and returns the entire contents of a file as UTF-8 string.
|
|
@@ -409,12 +407,12 @@ async function readFile(path, options) {
|
|
|
409
407
|
* @since 2.0.0
|
|
410
408
|
*/
|
|
411
409
|
async function readTextFile(path, options) {
|
|
412
|
-
if (path instanceof URL && path.protocol !==
|
|
413
|
-
throw new TypeError(
|
|
410
|
+
if (path instanceof URL && path.protocol !== 'file:') {
|
|
411
|
+
throw new TypeError('Must be a file URL.');
|
|
414
412
|
}
|
|
415
|
-
return await invoke(
|
|
413
|
+
return await invoke('plugin:fs|read_text_file', {
|
|
416
414
|
path: path instanceof URL ? path.toString() : path,
|
|
417
|
-
options
|
|
415
|
+
options
|
|
418
416
|
});
|
|
419
417
|
}
|
|
420
418
|
/**
|
|
@@ -433,8 +431,8 @@ async function readTextFile(path, options) {
|
|
|
433
431
|
* @since 2.0.0
|
|
434
432
|
*/
|
|
435
433
|
async function readTextFileLines(path, options) {
|
|
436
|
-
if (path instanceof URL && path.protocol !==
|
|
437
|
-
throw new TypeError(
|
|
434
|
+
if (path instanceof URL && path.protocol !== 'file:') {
|
|
435
|
+
throw new TypeError('Must be a file URL.');
|
|
438
436
|
}
|
|
439
437
|
const pathStr = path instanceof URL ? path.toString() : path;
|
|
440
438
|
return await Promise.resolve({
|
|
@@ -442,23 +440,23 @@ async function readTextFileLines(path, options) {
|
|
|
442
440
|
rid: null,
|
|
443
441
|
async next() {
|
|
444
442
|
if (this.rid === null) {
|
|
445
|
-
this.rid = await invoke(
|
|
443
|
+
this.rid = await invoke('plugin:fs|read_text_file_lines', {
|
|
446
444
|
path: pathStr,
|
|
447
|
-
options
|
|
445
|
+
options
|
|
448
446
|
});
|
|
449
447
|
}
|
|
450
|
-
const [line, done] = await invoke(
|
|
448
|
+
const [line, done] = await invoke('plugin:fs|read_text_file_lines_next', { rid: this.rid });
|
|
451
449
|
// an iteration is over, reset rid for next iteration
|
|
452
450
|
if (done)
|
|
453
451
|
this.rid = null;
|
|
454
452
|
return {
|
|
455
|
-
value: done ?
|
|
456
|
-
done
|
|
453
|
+
value: done ? '' : line,
|
|
454
|
+
done
|
|
457
455
|
};
|
|
458
456
|
},
|
|
459
457
|
[Symbol.asyncIterator]() {
|
|
460
458
|
return this;
|
|
461
|
-
}
|
|
459
|
+
}
|
|
462
460
|
});
|
|
463
461
|
}
|
|
464
462
|
/**
|
|
@@ -474,12 +472,12 @@ async function readTextFileLines(path, options) {
|
|
|
474
472
|
* @since 2.0.0
|
|
475
473
|
*/
|
|
476
474
|
async function remove(path, options) {
|
|
477
|
-
if (path instanceof URL && path.protocol !==
|
|
478
|
-
throw new TypeError(
|
|
475
|
+
if (path instanceof URL && path.protocol !== 'file:') {
|
|
476
|
+
throw new TypeError('Must be a file URL.');
|
|
479
477
|
}
|
|
480
|
-
await invoke(
|
|
478
|
+
await invoke('plugin:fs|remove', {
|
|
481
479
|
path: path instanceof URL ? path.toString() : path,
|
|
482
|
-
options
|
|
480
|
+
options
|
|
483
481
|
});
|
|
484
482
|
}
|
|
485
483
|
/**
|
|
@@ -498,14 +496,14 @@ async function remove(path, options) {
|
|
|
498
496
|
* @since 2.0.0
|
|
499
497
|
*/
|
|
500
498
|
async function rename(oldPath, newPath, options) {
|
|
501
|
-
if ((oldPath instanceof URL && oldPath.protocol !==
|
|
502
|
-
(newPath instanceof URL && newPath.protocol !==
|
|
503
|
-
throw new TypeError(
|
|
499
|
+
if ((oldPath instanceof URL && oldPath.protocol !== 'file:') ||
|
|
500
|
+
(newPath instanceof URL && newPath.protocol !== 'file:')) {
|
|
501
|
+
throw new TypeError('Must be a file URL.');
|
|
504
502
|
}
|
|
505
|
-
await invoke(
|
|
503
|
+
await invoke('plugin:fs|rename', {
|
|
506
504
|
oldPath: oldPath instanceof URL ? oldPath.toString() : oldPath,
|
|
507
505
|
newPath: newPath instanceof URL ? newPath.toString() : newPath,
|
|
508
|
-
options
|
|
506
|
+
options
|
|
509
507
|
});
|
|
510
508
|
}
|
|
511
509
|
/**
|
|
@@ -522,9 +520,9 @@ async function rename(oldPath, newPath, options) {
|
|
|
522
520
|
* @since 2.0.0
|
|
523
521
|
*/
|
|
524
522
|
async function stat(path, options) {
|
|
525
|
-
const res = await invoke(
|
|
523
|
+
const res = await invoke('plugin:fs|stat', {
|
|
526
524
|
path: path instanceof URL ? path.toString() : path,
|
|
527
|
-
options
|
|
525
|
+
options
|
|
528
526
|
});
|
|
529
527
|
return parseFileInfo(res);
|
|
530
528
|
}
|
|
@@ -543,9 +541,9 @@ async function stat(path, options) {
|
|
|
543
541
|
* @since 2.0.0
|
|
544
542
|
*/
|
|
545
543
|
async function lstat(path, options) {
|
|
546
|
-
const res = await invoke(
|
|
544
|
+
const res = await invoke('plugin:fs|lstat', {
|
|
547
545
|
path: path instanceof URL ? path.toString() : path,
|
|
548
|
-
options
|
|
546
|
+
options
|
|
549
547
|
});
|
|
550
548
|
return parseFileInfo(res);
|
|
551
549
|
}
|
|
@@ -570,13 +568,13 @@ async function lstat(path, options) {
|
|
|
570
568
|
* @since 2.0.0
|
|
571
569
|
*/
|
|
572
570
|
async function truncate(path, len, options) {
|
|
573
|
-
if (path instanceof URL && path.protocol !==
|
|
574
|
-
throw new TypeError(
|
|
571
|
+
if (path instanceof URL && path.protocol !== 'file:') {
|
|
572
|
+
throw new TypeError('Must be a file URL.');
|
|
575
573
|
}
|
|
576
|
-
await invoke(
|
|
574
|
+
await invoke('plugin:fs|truncate', {
|
|
577
575
|
path: path instanceof URL ? path.toString() : path,
|
|
578
576
|
len,
|
|
579
|
-
options
|
|
577
|
+
options
|
|
580
578
|
});
|
|
581
579
|
}
|
|
582
580
|
/**
|
|
@@ -593,14 +591,14 @@ async function truncate(path, len, options) {
|
|
|
593
591
|
* @since 2.0.0
|
|
594
592
|
*/
|
|
595
593
|
async function writeFile(path, data, options) {
|
|
596
|
-
if (path instanceof URL && path.protocol !==
|
|
597
|
-
throw new TypeError(
|
|
594
|
+
if (path instanceof URL && path.protocol !== 'file:') {
|
|
595
|
+
throw new TypeError('Must be a file URL.');
|
|
598
596
|
}
|
|
599
|
-
await invoke(
|
|
597
|
+
await invoke('plugin:fs|write_file', data, {
|
|
600
598
|
headers: {
|
|
601
|
-
path: path instanceof URL ? path.toString() : path,
|
|
602
|
-
options: JSON.stringify(options)
|
|
603
|
-
}
|
|
599
|
+
path: encodeURIComponent(path instanceof URL ? path.toString() : path),
|
|
600
|
+
options: JSON.stringify(options)
|
|
601
|
+
}
|
|
604
602
|
});
|
|
605
603
|
}
|
|
606
604
|
/**
|
|
@@ -615,13 +613,13 @@ async function writeFile(path, data, options) {
|
|
|
615
613
|
* @since 2.0.0
|
|
616
614
|
*/
|
|
617
615
|
async function writeTextFile(path, data, options) {
|
|
618
|
-
if (path instanceof URL && path.protocol !==
|
|
619
|
-
throw new TypeError(
|
|
616
|
+
if (path instanceof URL && path.protocol !== 'file:') {
|
|
617
|
+
throw new TypeError('Must be a file URL.');
|
|
620
618
|
}
|
|
621
|
-
await invoke(
|
|
619
|
+
await invoke('plugin:fs|write_text_file', {
|
|
622
620
|
path: path instanceof URL ? path.toString() : path,
|
|
623
621
|
data,
|
|
624
|
-
options
|
|
622
|
+
options
|
|
625
623
|
});
|
|
626
624
|
}
|
|
627
625
|
/**
|
|
@@ -636,16 +634,16 @@ async function writeTextFile(path, data, options) {
|
|
|
636
634
|
* @since 2.0.0
|
|
637
635
|
*/
|
|
638
636
|
async function exists(path, options) {
|
|
639
|
-
if (path instanceof URL && path.protocol !==
|
|
640
|
-
throw new TypeError(
|
|
637
|
+
if (path instanceof URL && path.protocol !== 'file:') {
|
|
638
|
+
throw new TypeError('Must be a file URL.');
|
|
641
639
|
}
|
|
642
|
-
return await invoke(
|
|
640
|
+
return await invoke('plugin:fs|exists', {
|
|
643
641
|
path: path instanceof URL ? path.toString() : path,
|
|
644
|
-
options
|
|
642
|
+
options
|
|
645
643
|
});
|
|
646
644
|
}
|
|
647
645
|
async function unwatch(rid) {
|
|
648
|
-
await invoke(
|
|
646
|
+
await invoke('plugin:fs|unwatch', { rid });
|
|
649
647
|
}
|
|
650
648
|
/**
|
|
651
649
|
* Watch changes (after a delay) on files or directories.
|
|
@@ -656,20 +654,20 @@ async function watch(paths, cb, options) {
|
|
|
656
654
|
const opts = {
|
|
657
655
|
recursive: false,
|
|
658
656
|
delayMs: 2000,
|
|
659
|
-
...options
|
|
657
|
+
...options
|
|
660
658
|
};
|
|
661
659
|
const watchPaths = Array.isArray(paths) ? paths : [paths];
|
|
662
660
|
for (const path of watchPaths) {
|
|
663
|
-
if (path instanceof URL && path.protocol !==
|
|
664
|
-
throw new TypeError(
|
|
661
|
+
if (path instanceof URL && path.protocol !== 'file:') {
|
|
662
|
+
throw new TypeError('Must be a file URL.');
|
|
665
663
|
}
|
|
666
664
|
}
|
|
667
665
|
const onEvent = new Channel();
|
|
668
666
|
onEvent.onmessage = cb;
|
|
669
|
-
const rid = await invoke(
|
|
667
|
+
const rid = await invoke('plugin:fs|watch', {
|
|
670
668
|
paths: watchPaths.map((p) => (p instanceof URL ? p.toString() : p)),
|
|
671
669
|
options: opts,
|
|
672
|
-
onEvent
|
|
670
|
+
onEvent
|
|
673
671
|
});
|
|
674
672
|
return () => {
|
|
675
673
|
void unwatch(rid);
|
|
@@ -684,20 +682,20 @@ async function watchImmediate(paths, cb, options) {
|
|
|
684
682
|
const opts = {
|
|
685
683
|
recursive: false,
|
|
686
684
|
...options,
|
|
687
|
-
delayMs: null
|
|
685
|
+
delayMs: null
|
|
688
686
|
};
|
|
689
687
|
const watchPaths = Array.isArray(paths) ? paths : [paths];
|
|
690
688
|
for (const path of watchPaths) {
|
|
691
|
-
if (path instanceof URL && path.protocol !==
|
|
692
|
-
throw new TypeError(
|
|
689
|
+
if (path instanceof URL && path.protocol !== 'file:') {
|
|
690
|
+
throw new TypeError('Must be a file URL.');
|
|
693
691
|
}
|
|
694
692
|
}
|
|
695
693
|
const onEvent = new Channel();
|
|
696
694
|
onEvent.onmessage = cb;
|
|
697
|
-
const rid = await invoke(
|
|
695
|
+
const rid = await invoke('plugin:fs|watch', {
|
|
698
696
|
paths: watchPaths.map((p) => (p instanceof URL ? p.toString() : p)),
|
|
699
697
|
options: opts,
|
|
700
|
-
onEvent
|
|
698
|
+
onEvent
|
|
701
699
|
});
|
|
702
700
|
return () => {
|
|
703
701
|
void unwatch(rid);
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tauri-apps/plugin-fs",
|
|
3
|
-
"version": "2.0.0
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Access the file system.",
|
|
5
|
-
"license": "MIT
|
|
5
|
+
"license": "MIT OR Apache-2.0",
|
|
6
6
|
"authors": [
|
|
7
7
|
"Tauri Programme within The Commons Conservancy"
|
|
8
8
|
],
|
|
@@ -25,6 +25,6 @@
|
|
|
25
25
|
"LICENSE"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@tauri-apps/api": "^2.0.0
|
|
28
|
+
"@tauri-apps/api": "^2.0.0"
|
|
29
29
|
}
|
|
30
30
|
}
|