@tauri-apps/plugin-fs 2.0.0-beta.2 → 2.0.0-beta.4
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 +26 -25
- package/dist-js/index.d.ts +2 -3
- package/dist-js/index.js +26 -25
- package/package.json +2 -2
package/dist-js/index.cjs
CHANGED
|
@@ -76,9 +76,9 @@ function parseFileInfo(r) {
|
|
|
76
76
|
isDirectory: r.isDirectory,
|
|
77
77
|
isSymlink: r.isSymlink,
|
|
78
78
|
size: r.size,
|
|
79
|
-
mtime: r.mtime
|
|
80
|
-
atime: r.atime
|
|
81
|
-
birthtime: r.birthtime
|
|
79
|
+
mtime: r.mtime !== null ? new Date(r.mtime) : null,
|
|
80
|
+
atime: r.atime !== null ? new Date(r.atime) : null,
|
|
81
|
+
birthtime: r.birthtime !== null ? new Date(r.birthtime) : null,
|
|
82
82
|
readonly: r.readonly,
|
|
83
83
|
fileAttributes: r.fileAttributes,
|
|
84
84
|
dev: r.dev,
|
|
@@ -98,9 +98,6 @@ function parseFileInfo(r) {
|
|
|
98
98
|
* @since 2.0.0
|
|
99
99
|
*/
|
|
100
100
|
class FileHandle extends core.Resource {
|
|
101
|
-
constructor(rid) {
|
|
102
|
-
super(rid);
|
|
103
|
-
}
|
|
104
101
|
/**
|
|
105
102
|
* Reads up to `p.byteLength` bytes into `p`. It resolves to the number of
|
|
106
103
|
* bytes read (`0` < `n` <= `p.byteLength`) and rejects if any error
|
|
@@ -174,7 +171,7 @@ class FileHandle extends core.Resource {
|
|
|
174
171
|
* @since 2.0.0
|
|
175
172
|
*/
|
|
176
173
|
async seek(offset, whence) {
|
|
177
|
-
return core.invoke("plugin:fs|seek", {
|
|
174
|
+
return await core.invoke("plugin:fs|seek", {
|
|
178
175
|
rid: this.rid,
|
|
179
176
|
offset,
|
|
180
177
|
whence,
|
|
@@ -223,7 +220,7 @@ class FileHandle extends core.Resource {
|
|
|
223
220
|
* @since 2.0.0
|
|
224
221
|
*/
|
|
225
222
|
async truncate(len) {
|
|
226
|
-
|
|
223
|
+
await core.invoke("plugin:fs|ftruncate", {
|
|
227
224
|
rid: this.rid,
|
|
228
225
|
len,
|
|
229
226
|
});
|
|
@@ -249,7 +246,7 @@ class FileHandle extends core.Resource {
|
|
|
249
246
|
* @since 2.0.0
|
|
250
247
|
*/
|
|
251
248
|
async write(data) {
|
|
252
|
-
return core.invoke("plugin:fs|write", {
|
|
249
|
+
return await core.invoke("plugin:fs|write", {
|
|
253
250
|
rid: this.rid,
|
|
254
251
|
data: Array.from(data),
|
|
255
252
|
});
|
|
@@ -318,7 +315,7 @@ async function copyFile(fromPath, toPath, options) {
|
|
|
318
315
|
(toPath instanceof URL && toPath.protocol !== "file:")) {
|
|
319
316
|
throw new TypeError("Must be a file URL.");
|
|
320
317
|
}
|
|
321
|
-
|
|
318
|
+
await core.invoke("plugin:fs|copy_file", {
|
|
322
319
|
fromPath: fromPath instanceof URL ? fromPath.toString() : fromPath,
|
|
323
320
|
toPath: toPath instanceof URL ? toPath.toString() : toPath,
|
|
324
321
|
options,
|
|
@@ -338,7 +335,7 @@ async function mkdir(path, options) {
|
|
|
338
335
|
if (path instanceof URL && path.protocol !== "file:") {
|
|
339
336
|
throw new TypeError("Must be a file URL.");
|
|
340
337
|
}
|
|
341
|
-
|
|
338
|
+
await core.invoke("plugin:fs|mkdir", {
|
|
342
339
|
path: path instanceof URL ? path.toString() : path,
|
|
343
340
|
options,
|
|
344
341
|
});
|
|
@@ -368,7 +365,7 @@ async function readDir(path, options) {
|
|
|
368
365
|
if (path instanceof URL && path.protocol !== "file:") {
|
|
369
366
|
throw new TypeError("Must be a file URL.");
|
|
370
367
|
}
|
|
371
|
-
return core.invoke("plugin:fs|read_dir", {
|
|
368
|
+
return await core.invoke("plugin:fs|read_dir", {
|
|
372
369
|
path: path instanceof URL ? path.toString() : path,
|
|
373
370
|
options,
|
|
374
371
|
});
|
|
@@ -392,7 +389,9 @@ async function readFile(path, options) {
|
|
|
392
389
|
path: path instanceof URL ? path.toString() : path,
|
|
393
390
|
options,
|
|
394
391
|
});
|
|
395
|
-
return
|
|
392
|
+
return arr instanceof ArrayBuffer
|
|
393
|
+
? new Uint8Array(arr)
|
|
394
|
+
: Uint8Array.from(arr);
|
|
396
395
|
}
|
|
397
396
|
/**
|
|
398
397
|
* Reads and returns the entire contents of a file as UTF-8 string.
|
|
@@ -408,7 +407,7 @@ async function readTextFile(path, options) {
|
|
|
408
407
|
if (path instanceof URL && path.protocol !== "file:") {
|
|
409
408
|
throw new TypeError("Must be a file URL.");
|
|
410
409
|
}
|
|
411
|
-
return core.invoke("plugin:fs|read_text_file", {
|
|
410
|
+
return await core.invoke("plugin:fs|read_text_file", {
|
|
412
411
|
path: path instanceof URL ? path.toString() : path,
|
|
413
412
|
options,
|
|
414
413
|
});
|
|
@@ -433,11 +432,11 @@ async function readTextFileLines(path, options) {
|
|
|
433
432
|
throw new TypeError("Must be a file URL.");
|
|
434
433
|
}
|
|
435
434
|
const pathStr = path instanceof URL ? path.toString() : path;
|
|
436
|
-
return Promise.resolve({
|
|
435
|
+
return await Promise.resolve({
|
|
437
436
|
path: pathStr,
|
|
438
437
|
rid: null,
|
|
439
438
|
async next() {
|
|
440
|
-
if (
|
|
439
|
+
if (this.rid === null) {
|
|
441
440
|
this.rid = await core.invoke("plugin:fs|read_text_file_lines", {
|
|
442
441
|
path: pathStr,
|
|
443
442
|
options,
|
|
@@ -448,6 +447,7 @@ async function readTextFileLines(path, options) {
|
|
|
448
447
|
if (done)
|
|
449
448
|
this.rid = null;
|
|
450
449
|
return {
|
|
450
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
451
451
|
value: done ? "" : line,
|
|
452
452
|
done,
|
|
453
453
|
};
|
|
@@ -473,7 +473,7 @@ async function remove(path, options) {
|
|
|
473
473
|
if (path instanceof URL && path.protocol !== "file:") {
|
|
474
474
|
throw new TypeError("Must be a file URL.");
|
|
475
475
|
}
|
|
476
|
-
|
|
476
|
+
await core.invoke("plugin:fs|remove", {
|
|
477
477
|
path: path instanceof URL ? path.toString() : path,
|
|
478
478
|
options,
|
|
479
479
|
});
|
|
@@ -498,7 +498,7 @@ async function rename(oldPath, newPath, options) {
|
|
|
498
498
|
(newPath instanceof URL && newPath.protocol !== "file:")) {
|
|
499
499
|
throw new TypeError("Must be a file URL.");
|
|
500
500
|
}
|
|
501
|
-
|
|
501
|
+
await core.invoke("plugin:fs|rename", {
|
|
502
502
|
oldPath: oldPath instanceof URL ? oldPath.toString() : oldPath,
|
|
503
503
|
newPath: newPath instanceof URL ? newPath.toString() : newPath,
|
|
504
504
|
options,
|
|
@@ -569,7 +569,7 @@ async function truncate(path, len, options) {
|
|
|
569
569
|
if (path instanceof URL && path.protocol !== "file:") {
|
|
570
570
|
throw new TypeError("Must be a file URL.");
|
|
571
571
|
}
|
|
572
|
-
|
|
572
|
+
await core.invoke("plugin:fs|truncate", {
|
|
573
573
|
path: path instanceof URL ? path.toString() : path,
|
|
574
574
|
len,
|
|
575
575
|
options,
|
|
@@ -592,10 +592,11 @@ async function writeFile(path, data, options) {
|
|
|
592
592
|
if (path instanceof URL && path.protocol !== "file:") {
|
|
593
593
|
throw new TypeError("Must be a file URL.");
|
|
594
594
|
}
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
595
|
+
await core.invoke("plugin:fs|write_file", data, {
|
|
596
|
+
headers: {
|
|
597
|
+
path: path instanceof URL ? path.toString() : path,
|
|
598
|
+
options: JSON.stringify(options),
|
|
599
|
+
},
|
|
599
600
|
});
|
|
600
601
|
}
|
|
601
602
|
/**
|
|
@@ -613,7 +614,7 @@ async function writeTextFile(path, data, options) {
|
|
|
613
614
|
if (path instanceof URL && path.protocol !== "file:") {
|
|
614
615
|
throw new TypeError("Must be a file URL.");
|
|
615
616
|
}
|
|
616
|
-
|
|
617
|
+
await core.invoke("plugin:fs|write_text_file", {
|
|
617
618
|
path: path instanceof URL ? path.toString() : path,
|
|
618
619
|
data,
|
|
619
620
|
options,
|
|
@@ -634,7 +635,7 @@ async function exists(path, options) {
|
|
|
634
635
|
if (path instanceof URL && path.protocol !== "file:") {
|
|
635
636
|
throw new TypeError("Must be a file URL.");
|
|
636
637
|
}
|
|
637
|
-
return core.invoke("plugin:fs|exists", {
|
|
638
|
+
return await core.invoke("plugin:fs|exists", {
|
|
638
639
|
path: path instanceof URL ? path.toString() : path,
|
|
639
640
|
options,
|
|
640
641
|
});
|
package/dist-js/index.d.ts
CHANGED
|
@@ -198,7 +198,6 @@ interface FileInfo {
|
|
|
198
198
|
* @since 2.0.0
|
|
199
199
|
*/
|
|
200
200
|
declare class FileHandle extends Resource {
|
|
201
|
-
constructor(rid: number);
|
|
202
201
|
/**
|
|
203
202
|
* Reads up to `p.byteLength` bytes into `p`. It resolves to the number of
|
|
204
203
|
* bytes read (`0` < `n` <= `p.byteLength`) and rejects if any error
|
|
@@ -737,11 +736,11 @@ interface DebouncedWatchOptions extends WatchOptions {
|
|
|
737
736
|
/**
|
|
738
737
|
* @since 2.0.0
|
|
739
738
|
*/
|
|
740
|
-
|
|
739
|
+
interface WatchEvent {
|
|
741
740
|
type: WatchEventKind;
|
|
742
741
|
paths: string[];
|
|
743
742
|
attrs: unknown;
|
|
744
|
-
}
|
|
743
|
+
}
|
|
745
744
|
/**
|
|
746
745
|
* @since 2.0.0
|
|
747
746
|
*/
|
package/dist-js/index.js
CHANGED
|
@@ -74,9 +74,9 @@ function parseFileInfo(r) {
|
|
|
74
74
|
isDirectory: r.isDirectory,
|
|
75
75
|
isSymlink: r.isSymlink,
|
|
76
76
|
size: r.size,
|
|
77
|
-
mtime: r.mtime
|
|
78
|
-
atime: r.atime
|
|
79
|
-
birthtime: r.birthtime
|
|
77
|
+
mtime: r.mtime !== null ? new Date(r.mtime) : null,
|
|
78
|
+
atime: r.atime !== null ? new Date(r.atime) : null,
|
|
79
|
+
birthtime: r.birthtime !== null ? new Date(r.birthtime) : null,
|
|
80
80
|
readonly: r.readonly,
|
|
81
81
|
fileAttributes: r.fileAttributes,
|
|
82
82
|
dev: r.dev,
|
|
@@ -96,9 +96,6 @@ function parseFileInfo(r) {
|
|
|
96
96
|
* @since 2.0.0
|
|
97
97
|
*/
|
|
98
98
|
class FileHandle extends Resource {
|
|
99
|
-
constructor(rid) {
|
|
100
|
-
super(rid);
|
|
101
|
-
}
|
|
102
99
|
/**
|
|
103
100
|
* Reads up to `p.byteLength` bytes into `p`. It resolves to the number of
|
|
104
101
|
* bytes read (`0` < `n` <= `p.byteLength`) and rejects if any error
|
|
@@ -172,7 +169,7 @@ class FileHandle extends Resource {
|
|
|
172
169
|
* @since 2.0.0
|
|
173
170
|
*/
|
|
174
171
|
async seek(offset, whence) {
|
|
175
|
-
return invoke("plugin:fs|seek", {
|
|
172
|
+
return await invoke("plugin:fs|seek", {
|
|
176
173
|
rid: this.rid,
|
|
177
174
|
offset,
|
|
178
175
|
whence,
|
|
@@ -221,7 +218,7 @@ class FileHandle extends Resource {
|
|
|
221
218
|
* @since 2.0.0
|
|
222
219
|
*/
|
|
223
220
|
async truncate(len) {
|
|
224
|
-
|
|
221
|
+
await invoke("plugin:fs|ftruncate", {
|
|
225
222
|
rid: this.rid,
|
|
226
223
|
len,
|
|
227
224
|
});
|
|
@@ -247,7 +244,7 @@ class FileHandle extends Resource {
|
|
|
247
244
|
* @since 2.0.0
|
|
248
245
|
*/
|
|
249
246
|
async write(data) {
|
|
250
|
-
return invoke("plugin:fs|write", {
|
|
247
|
+
return await invoke("plugin:fs|write", {
|
|
251
248
|
rid: this.rid,
|
|
252
249
|
data: Array.from(data),
|
|
253
250
|
});
|
|
@@ -316,7 +313,7 @@ async function copyFile(fromPath, toPath, options) {
|
|
|
316
313
|
(toPath instanceof URL && toPath.protocol !== "file:")) {
|
|
317
314
|
throw new TypeError("Must be a file URL.");
|
|
318
315
|
}
|
|
319
|
-
|
|
316
|
+
await invoke("plugin:fs|copy_file", {
|
|
320
317
|
fromPath: fromPath instanceof URL ? fromPath.toString() : fromPath,
|
|
321
318
|
toPath: toPath instanceof URL ? toPath.toString() : toPath,
|
|
322
319
|
options,
|
|
@@ -336,7 +333,7 @@ async function mkdir(path, options) {
|
|
|
336
333
|
if (path instanceof URL && path.protocol !== "file:") {
|
|
337
334
|
throw new TypeError("Must be a file URL.");
|
|
338
335
|
}
|
|
339
|
-
|
|
336
|
+
await invoke("plugin:fs|mkdir", {
|
|
340
337
|
path: path instanceof URL ? path.toString() : path,
|
|
341
338
|
options,
|
|
342
339
|
});
|
|
@@ -366,7 +363,7 @@ async function readDir(path, options) {
|
|
|
366
363
|
if (path instanceof URL && path.protocol !== "file:") {
|
|
367
364
|
throw new TypeError("Must be a file URL.");
|
|
368
365
|
}
|
|
369
|
-
return invoke("plugin:fs|read_dir", {
|
|
366
|
+
return await invoke("plugin:fs|read_dir", {
|
|
370
367
|
path: path instanceof URL ? path.toString() : path,
|
|
371
368
|
options,
|
|
372
369
|
});
|
|
@@ -390,7 +387,9 @@ async function readFile(path, options) {
|
|
|
390
387
|
path: path instanceof URL ? path.toString() : path,
|
|
391
388
|
options,
|
|
392
389
|
});
|
|
393
|
-
return
|
|
390
|
+
return arr instanceof ArrayBuffer
|
|
391
|
+
? new Uint8Array(arr)
|
|
392
|
+
: Uint8Array.from(arr);
|
|
394
393
|
}
|
|
395
394
|
/**
|
|
396
395
|
* Reads and returns the entire contents of a file as UTF-8 string.
|
|
@@ -406,7 +405,7 @@ async function readTextFile(path, options) {
|
|
|
406
405
|
if (path instanceof URL && path.protocol !== "file:") {
|
|
407
406
|
throw new TypeError("Must be a file URL.");
|
|
408
407
|
}
|
|
409
|
-
return invoke("plugin:fs|read_text_file", {
|
|
408
|
+
return await invoke("plugin:fs|read_text_file", {
|
|
410
409
|
path: path instanceof URL ? path.toString() : path,
|
|
411
410
|
options,
|
|
412
411
|
});
|
|
@@ -431,11 +430,11 @@ async function readTextFileLines(path, options) {
|
|
|
431
430
|
throw new TypeError("Must be a file URL.");
|
|
432
431
|
}
|
|
433
432
|
const pathStr = path instanceof URL ? path.toString() : path;
|
|
434
|
-
return Promise.resolve({
|
|
433
|
+
return await Promise.resolve({
|
|
435
434
|
path: pathStr,
|
|
436
435
|
rid: null,
|
|
437
436
|
async next() {
|
|
438
|
-
if (
|
|
437
|
+
if (this.rid === null) {
|
|
439
438
|
this.rid = await invoke("plugin:fs|read_text_file_lines", {
|
|
440
439
|
path: pathStr,
|
|
441
440
|
options,
|
|
@@ -446,6 +445,7 @@ async function readTextFileLines(path, options) {
|
|
|
446
445
|
if (done)
|
|
447
446
|
this.rid = null;
|
|
448
447
|
return {
|
|
448
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
449
449
|
value: done ? "" : line,
|
|
450
450
|
done,
|
|
451
451
|
};
|
|
@@ -471,7 +471,7 @@ async function remove(path, options) {
|
|
|
471
471
|
if (path instanceof URL && path.protocol !== "file:") {
|
|
472
472
|
throw new TypeError("Must be a file URL.");
|
|
473
473
|
}
|
|
474
|
-
|
|
474
|
+
await invoke("plugin:fs|remove", {
|
|
475
475
|
path: path instanceof URL ? path.toString() : path,
|
|
476
476
|
options,
|
|
477
477
|
});
|
|
@@ -496,7 +496,7 @@ async function rename(oldPath, newPath, options) {
|
|
|
496
496
|
(newPath instanceof URL && newPath.protocol !== "file:")) {
|
|
497
497
|
throw new TypeError("Must be a file URL.");
|
|
498
498
|
}
|
|
499
|
-
|
|
499
|
+
await invoke("plugin:fs|rename", {
|
|
500
500
|
oldPath: oldPath instanceof URL ? oldPath.toString() : oldPath,
|
|
501
501
|
newPath: newPath instanceof URL ? newPath.toString() : newPath,
|
|
502
502
|
options,
|
|
@@ -567,7 +567,7 @@ async function truncate(path, len, options) {
|
|
|
567
567
|
if (path instanceof URL && path.protocol !== "file:") {
|
|
568
568
|
throw new TypeError("Must be a file URL.");
|
|
569
569
|
}
|
|
570
|
-
|
|
570
|
+
await invoke("plugin:fs|truncate", {
|
|
571
571
|
path: path instanceof URL ? path.toString() : path,
|
|
572
572
|
len,
|
|
573
573
|
options,
|
|
@@ -590,10 +590,11 @@ async function writeFile(path, data, options) {
|
|
|
590
590
|
if (path instanceof URL && path.protocol !== "file:") {
|
|
591
591
|
throw new TypeError("Must be a file URL.");
|
|
592
592
|
}
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
593
|
+
await invoke("plugin:fs|write_file", data, {
|
|
594
|
+
headers: {
|
|
595
|
+
path: path instanceof URL ? path.toString() : path,
|
|
596
|
+
options: JSON.stringify(options),
|
|
597
|
+
},
|
|
597
598
|
});
|
|
598
599
|
}
|
|
599
600
|
/**
|
|
@@ -611,7 +612,7 @@ async function writeTextFile(path, data, options) {
|
|
|
611
612
|
if (path instanceof URL && path.protocol !== "file:") {
|
|
612
613
|
throw new TypeError("Must be a file URL.");
|
|
613
614
|
}
|
|
614
|
-
|
|
615
|
+
await invoke("plugin:fs|write_text_file", {
|
|
615
616
|
path: path instanceof URL ? path.toString() : path,
|
|
616
617
|
data,
|
|
617
618
|
options,
|
|
@@ -632,7 +633,7 @@ async function exists(path, options) {
|
|
|
632
633
|
if (path instanceof URL && path.protocol !== "file:") {
|
|
633
634
|
throw new TypeError("Must be a file URL.");
|
|
634
635
|
}
|
|
635
|
-
return invoke("plugin:fs|exists", {
|
|
636
|
+
return await invoke("plugin:fs|exists", {
|
|
636
637
|
path: path instanceof URL ? path.toString() : path,
|
|
637
638
|
options,
|
|
638
639
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tauri-apps/plugin-fs",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.4",
|
|
4
4
|
"description": "Access the file system.",
|
|
5
5
|
"license": "MIT or APACHE-2.0",
|
|
6
6
|
"authors": [
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"LICENSE"
|
|
22
22
|
],
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@tauri-apps/api": "2.0.0-beta.
|
|
24
|
+
"@tauri-apps/api": "2.0.0-beta.12"
|
|
25
25
|
},
|
|
26
26
|
"scripts": {
|
|
27
27
|
"build": "rollup -c"
|