@tauri-apps/plugin-fs 2.2.0 → 2.2.1
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 +17 -8
- package/dist-js/index.d.ts +1 -1
- package/dist-js/index.js +17 -8
- package/package.json +1 -1
package/dist-js/index.cjs
CHANGED
|
@@ -14,7 +14,7 @@ var core = require('@tauri-apps/api/core');
|
|
|
14
14
|
* This module prevents path traversal, not allowing parent directory accessors to be used
|
|
15
15
|
* (i.e. "/usr/path/to/../file" or "../path/to/file" paths are not allowed).
|
|
16
16
|
* Paths accessed with this API must be either relative to one of the {@link BaseDirectory | base directories}
|
|
17
|
-
* or created with the {@link https://v2.tauri.app/reference/javascript/api/namespacepath | path API}.
|
|
17
|
+
* or created with the {@link https://v2.tauri.app/reference/javascript/api/namespacepath/ | path API}.
|
|
18
18
|
*
|
|
19
19
|
* The API has a scope configuration that forces you to restrict the paths that can be accessed using glob patterns.
|
|
20
20
|
*
|
|
@@ -349,8 +349,8 @@ async function open(path, options) {
|
|
|
349
349
|
* @since 2.0.0
|
|
350
350
|
*/
|
|
351
351
|
async function copyFile(fromPath, toPath, options) {
|
|
352
|
-
if ((fromPath instanceof URL && fromPath.protocol !== 'file:')
|
|
353
|
-
(toPath instanceof URL && toPath.protocol !== 'file:')) {
|
|
352
|
+
if ((fromPath instanceof URL && fromPath.protocol !== 'file:')
|
|
353
|
+
|| (toPath instanceof URL && toPath.protocol !== 'file:')) {
|
|
354
354
|
throw new TypeError('Must be a file URL.');
|
|
355
355
|
}
|
|
356
356
|
await core.invoke('plugin:fs|copy_file', {
|
|
@@ -542,8 +542,8 @@ async function remove(path, options) {
|
|
|
542
542
|
* @since 2.0.0
|
|
543
543
|
*/
|
|
544
544
|
async function rename(oldPath, newPath, options) {
|
|
545
|
-
if ((oldPath instanceof URL && oldPath.protocol !== 'file:')
|
|
546
|
-
(newPath instanceof URL && newPath.protocol !== 'file:')) {
|
|
545
|
+
if ((oldPath instanceof URL && oldPath.protocol !== 'file:')
|
|
546
|
+
|| (newPath instanceof URL && newPath.protocol !== 'file:')) {
|
|
547
547
|
throw new TypeError('Must be a file URL.');
|
|
548
548
|
}
|
|
549
549
|
await core.invoke('plugin:fs|rename', {
|
|
@@ -642,10 +642,19 @@ async function writeFile(path, data, options) {
|
|
|
642
642
|
}
|
|
643
643
|
if (data instanceof ReadableStream) {
|
|
644
644
|
const file = await open(path, options);
|
|
645
|
-
|
|
646
|
-
|
|
645
|
+
const reader = data.getReader();
|
|
646
|
+
try {
|
|
647
|
+
while (true) {
|
|
648
|
+
const { done, value } = await reader.read();
|
|
649
|
+
if (done)
|
|
650
|
+
break;
|
|
651
|
+
await file.write(value);
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
finally {
|
|
655
|
+
reader.releaseLock();
|
|
656
|
+
await file.close();
|
|
647
657
|
}
|
|
648
|
-
await file.close();
|
|
649
658
|
}
|
|
650
659
|
else {
|
|
651
660
|
await core.invoke('plugin:fs|write_file', data, {
|
package/dist-js/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* This module prevents path traversal, not allowing parent directory accessors to be used
|
|
7
7
|
* (i.e. "/usr/path/to/../file" or "../path/to/file" paths are not allowed).
|
|
8
8
|
* Paths accessed with this API must be either relative to one of the {@link BaseDirectory | base directories}
|
|
9
|
-
* or created with the {@link https://v2.tauri.app/reference/javascript/api/namespacepath | path API}.
|
|
9
|
+
* or created with the {@link https://v2.tauri.app/reference/javascript/api/namespacepath/ | path API}.
|
|
10
10
|
*
|
|
11
11
|
* The API has a scope configuration that forces you to restrict the paths that can be accessed using glob patterns.
|
|
12
12
|
*
|
package/dist-js/index.js
CHANGED
|
@@ -12,7 +12,7 @@ import { Resource, invoke, Channel } from '@tauri-apps/api/core';
|
|
|
12
12
|
* This module prevents path traversal, not allowing parent directory accessors to be used
|
|
13
13
|
* (i.e. "/usr/path/to/../file" or "../path/to/file" paths are not allowed).
|
|
14
14
|
* Paths accessed with this API must be either relative to one of the {@link BaseDirectory | base directories}
|
|
15
|
-
* or created with the {@link https://v2.tauri.app/reference/javascript/api/namespacepath | path API}.
|
|
15
|
+
* or created with the {@link https://v2.tauri.app/reference/javascript/api/namespacepath/ | path API}.
|
|
16
16
|
*
|
|
17
17
|
* The API has a scope configuration that forces you to restrict the paths that can be accessed using glob patterns.
|
|
18
18
|
*
|
|
@@ -347,8 +347,8 @@ async function open(path, options) {
|
|
|
347
347
|
* @since 2.0.0
|
|
348
348
|
*/
|
|
349
349
|
async function copyFile(fromPath, toPath, options) {
|
|
350
|
-
if ((fromPath instanceof URL && fromPath.protocol !== 'file:')
|
|
351
|
-
(toPath instanceof URL && toPath.protocol !== 'file:')) {
|
|
350
|
+
if ((fromPath instanceof URL && fromPath.protocol !== 'file:')
|
|
351
|
+
|| (toPath instanceof URL && toPath.protocol !== 'file:')) {
|
|
352
352
|
throw new TypeError('Must be a file URL.');
|
|
353
353
|
}
|
|
354
354
|
await invoke('plugin:fs|copy_file', {
|
|
@@ -540,8 +540,8 @@ async function remove(path, options) {
|
|
|
540
540
|
* @since 2.0.0
|
|
541
541
|
*/
|
|
542
542
|
async function rename(oldPath, newPath, options) {
|
|
543
|
-
if ((oldPath instanceof URL && oldPath.protocol !== 'file:')
|
|
544
|
-
(newPath instanceof URL && newPath.protocol !== 'file:')) {
|
|
543
|
+
if ((oldPath instanceof URL && oldPath.protocol !== 'file:')
|
|
544
|
+
|| (newPath instanceof URL && newPath.protocol !== 'file:')) {
|
|
545
545
|
throw new TypeError('Must be a file URL.');
|
|
546
546
|
}
|
|
547
547
|
await invoke('plugin:fs|rename', {
|
|
@@ -640,10 +640,19 @@ async function writeFile(path, data, options) {
|
|
|
640
640
|
}
|
|
641
641
|
if (data instanceof ReadableStream) {
|
|
642
642
|
const file = await open(path, options);
|
|
643
|
-
|
|
644
|
-
|
|
643
|
+
const reader = data.getReader();
|
|
644
|
+
try {
|
|
645
|
+
while (true) {
|
|
646
|
+
const { done, value } = await reader.read();
|
|
647
|
+
if (done)
|
|
648
|
+
break;
|
|
649
|
+
await file.write(value);
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
finally {
|
|
653
|
+
reader.releaseLock();
|
|
654
|
+
await file.close();
|
|
645
655
|
}
|
|
646
|
-
await file.close();
|
|
647
656
|
}
|
|
648
657
|
else {
|
|
649
658
|
await invoke('plugin:fs|write_file', data, {
|