@tauri-apps/plugin-fs 2.2.1 → 2.3.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 +2 -2
- package/dist-js/index.cjs +20 -34
- package/dist-js/index.js +20 -34
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -68,9 +68,9 @@ fn main() {
|
|
|
68
68
|
Afterwards all the plugin's APIs are available through the JavaScript guest bindings:
|
|
69
69
|
|
|
70
70
|
```javascript
|
|
71
|
-
import {
|
|
71
|
+
import { stat } from '@tauri-apps/plugin-fs'
|
|
72
72
|
|
|
73
|
-
await
|
|
73
|
+
await stat('/path/to/file')
|
|
74
74
|
```
|
|
75
75
|
|
|
76
76
|
## Contributing
|
package/dist-js/index.cjs
CHANGED
|
@@ -708,20 +708,9 @@ async function exists(path, options) {
|
|
|
708
708
|
options
|
|
709
709
|
});
|
|
710
710
|
}
|
|
711
|
-
|
|
712
|
-
await core.invoke('plugin:fs|unwatch', { rid });
|
|
711
|
+
class Watcher extends core.Resource {
|
|
713
712
|
}
|
|
714
|
-
|
|
715
|
-
* Watch changes (after a delay) on files or directories.
|
|
716
|
-
*
|
|
717
|
-
* @since 2.0.0
|
|
718
|
-
*/
|
|
719
|
-
async function watch(paths, cb, options) {
|
|
720
|
-
const opts = {
|
|
721
|
-
recursive: false,
|
|
722
|
-
delayMs: 2000,
|
|
723
|
-
...options
|
|
724
|
-
};
|
|
713
|
+
async function watchInternal(paths, cb, options) {
|
|
725
714
|
const watchPaths = Array.isArray(paths) ? paths : [paths];
|
|
726
715
|
for (const path of watchPaths) {
|
|
727
716
|
if (path instanceof URL && path.protocol !== 'file:') {
|
|
@@ -732,40 +721,37 @@ async function watch(paths, cb, options) {
|
|
|
732
721
|
onEvent.onmessage = cb;
|
|
733
722
|
const rid = await core.invoke('plugin:fs|watch', {
|
|
734
723
|
paths: watchPaths.map((p) => (p instanceof URL ? p.toString() : p)),
|
|
735
|
-
options
|
|
724
|
+
options,
|
|
736
725
|
onEvent
|
|
737
726
|
});
|
|
727
|
+
const watcher = new Watcher(rid);
|
|
738
728
|
return () => {
|
|
739
|
-
void
|
|
729
|
+
void watcher.close();
|
|
740
730
|
};
|
|
741
731
|
}
|
|
732
|
+
// TODO: Return `Watcher` instead in v3
|
|
733
|
+
/**
|
|
734
|
+
* Watch changes (after a delay) on files or directories.
|
|
735
|
+
*
|
|
736
|
+
* @since 2.0.0
|
|
737
|
+
*/
|
|
738
|
+
async function watch(paths, cb, options) {
|
|
739
|
+
return await watchInternal(paths, cb, {
|
|
740
|
+
delayMs: 2000,
|
|
741
|
+
...options
|
|
742
|
+
});
|
|
743
|
+
}
|
|
744
|
+
// TODO: Return `Watcher` instead in v3
|
|
742
745
|
/**
|
|
743
746
|
* Watch changes on files or directories.
|
|
744
747
|
*
|
|
745
748
|
* @since 2.0.0
|
|
746
749
|
*/
|
|
747
750
|
async function watchImmediate(paths, cb, options) {
|
|
748
|
-
|
|
749
|
-
recursive: false,
|
|
751
|
+
return await watchInternal(paths, cb, {
|
|
750
752
|
...options,
|
|
751
|
-
delayMs:
|
|
752
|
-
};
|
|
753
|
-
const watchPaths = Array.isArray(paths) ? paths : [paths];
|
|
754
|
-
for (const path of watchPaths) {
|
|
755
|
-
if (path instanceof URL && path.protocol !== 'file:') {
|
|
756
|
-
throw new TypeError('Must be a file URL.');
|
|
757
|
-
}
|
|
758
|
-
}
|
|
759
|
-
const onEvent = new core.Channel();
|
|
760
|
-
onEvent.onmessage = cb;
|
|
761
|
-
const rid = await core.invoke('plugin:fs|watch', {
|
|
762
|
-
paths: watchPaths.map((p) => (p instanceof URL ? p.toString() : p)),
|
|
763
|
-
options: opts,
|
|
764
|
-
onEvent
|
|
753
|
+
delayMs: undefined
|
|
765
754
|
});
|
|
766
|
-
return () => {
|
|
767
|
-
void unwatch(rid);
|
|
768
|
-
};
|
|
769
755
|
}
|
|
770
756
|
/**
|
|
771
757
|
* Get the size of a file or directory. For files, the `stat` functions can be used as well.
|
package/dist-js/index.js
CHANGED
|
@@ -706,20 +706,9 @@ async function exists(path, options) {
|
|
|
706
706
|
options
|
|
707
707
|
});
|
|
708
708
|
}
|
|
709
|
-
|
|
710
|
-
await invoke('plugin:fs|unwatch', { rid });
|
|
709
|
+
class Watcher extends Resource {
|
|
711
710
|
}
|
|
712
|
-
|
|
713
|
-
* Watch changes (after a delay) on files or directories.
|
|
714
|
-
*
|
|
715
|
-
* @since 2.0.0
|
|
716
|
-
*/
|
|
717
|
-
async function watch(paths, cb, options) {
|
|
718
|
-
const opts = {
|
|
719
|
-
recursive: false,
|
|
720
|
-
delayMs: 2000,
|
|
721
|
-
...options
|
|
722
|
-
};
|
|
711
|
+
async function watchInternal(paths, cb, options) {
|
|
723
712
|
const watchPaths = Array.isArray(paths) ? paths : [paths];
|
|
724
713
|
for (const path of watchPaths) {
|
|
725
714
|
if (path instanceof URL && path.protocol !== 'file:') {
|
|
@@ -730,40 +719,37 @@ async function watch(paths, cb, options) {
|
|
|
730
719
|
onEvent.onmessage = cb;
|
|
731
720
|
const rid = await invoke('plugin:fs|watch', {
|
|
732
721
|
paths: watchPaths.map((p) => (p instanceof URL ? p.toString() : p)),
|
|
733
|
-
options
|
|
722
|
+
options,
|
|
734
723
|
onEvent
|
|
735
724
|
});
|
|
725
|
+
const watcher = new Watcher(rid);
|
|
736
726
|
return () => {
|
|
737
|
-
void
|
|
727
|
+
void watcher.close();
|
|
738
728
|
};
|
|
739
729
|
}
|
|
730
|
+
// TODO: Return `Watcher` instead in v3
|
|
731
|
+
/**
|
|
732
|
+
* Watch changes (after a delay) on files or directories.
|
|
733
|
+
*
|
|
734
|
+
* @since 2.0.0
|
|
735
|
+
*/
|
|
736
|
+
async function watch(paths, cb, options) {
|
|
737
|
+
return await watchInternal(paths, cb, {
|
|
738
|
+
delayMs: 2000,
|
|
739
|
+
...options
|
|
740
|
+
});
|
|
741
|
+
}
|
|
742
|
+
// TODO: Return `Watcher` instead in v3
|
|
740
743
|
/**
|
|
741
744
|
* Watch changes on files or directories.
|
|
742
745
|
*
|
|
743
746
|
* @since 2.0.0
|
|
744
747
|
*/
|
|
745
748
|
async function watchImmediate(paths, cb, options) {
|
|
746
|
-
|
|
747
|
-
recursive: false,
|
|
749
|
+
return await watchInternal(paths, cb, {
|
|
748
750
|
...options,
|
|
749
|
-
delayMs:
|
|
750
|
-
};
|
|
751
|
-
const watchPaths = Array.isArray(paths) ? paths : [paths];
|
|
752
|
-
for (const path of watchPaths) {
|
|
753
|
-
if (path instanceof URL && path.protocol !== 'file:') {
|
|
754
|
-
throw new TypeError('Must be a file URL.');
|
|
755
|
-
}
|
|
756
|
-
}
|
|
757
|
-
const onEvent = new Channel();
|
|
758
|
-
onEvent.onmessage = cb;
|
|
759
|
-
const rid = await invoke('plugin:fs|watch', {
|
|
760
|
-
paths: watchPaths.map((p) => (p instanceof URL ? p.toString() : p)),
|
|
761
|
-
options: opts,
|
|
762
|
-
onEvent
|
|
751
|
+
delayMs: undefined
|
|
763
752
|
});
|
|
764
|
-
return () => {
|
|
765
|
-
void unwatch(rid);
|
|
766
|
-
};
|
|
767
753
|
}
|
|
768
754
|
/**
|
|
769
755
|
* Get the size of a file or directory. For files, the `stat` functions can be used as well.
|