@tauri-apps/plugin-fs 2.0.0-alpha.0 → 2.0.0-alpha.2

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 CHANGED
@@ -1,10 +1,10 @@
1
- # File System
1
+ ![plugin-fs](https://github.com/tauri-apps/plugins-workspace/raw/v2/plugins/fs/banner.png)
2
2
 
3
3
  Access the file system.
4
4
 
5
5
  ## Install
6
6
 
7
- _This plugin requires a Rust version of at least **1.65**_
7
+ _This plugin requires a Rust version of at least **1.70**_
8
8
 
9
9
  There are three general methods of installation that we can recommend.
10
10
 
@@ -41,11 +41,6 @@
41
41
  * @module
42
42
  */
43
43
  import { BaseDirectory } from "@tauri-apps/api/path";
44
- declare global {
45
- interface Window {
46
- __TAURI_INVOKE__: <T>(cmd: string, args?: unknown) => Promise<T>;
47
- }
48
- }
49
44
  interface Permissions {
50
45
  /**
51
46
  * `true` if these permissions describe a readonly (unwritable) file.
@@ -1,10 +1,54 @@
1
- var f$2=Object.defineProperty;var g$1=(a,b)=>{for(var c in b)f$2(a,c,{get:b[c],enumerable:!0});};var e$1=(a,b,c)=>{if(!b.has(a))throw TypeError("Cannot "+c)};var h$2=(a,b,c)=>(e$1(a,b,"read from private field"),c?c.call(a):b.get(a)),i=(a,b,c)=>{if(b.has(a))throw TypeError("Cannot add the same private member more than once");b instanceof WeakSet?b.add(a):b.set(a,c);},j$1=(a,b,c,d)=>(e$1(a,b,"write to private field"),d?d.call(a,c):b.set(a,c),c);
1
+ var f$1=Object.defineProperty;var g$1=(a,b)=>{for(var c in b)f$1(a,c,{get:b[c],enumerable:!0});};var e=(a,b,c)=>{if(!b.has(a))throw TypeError("Cannot "+c)};var h$1=(a,b,c)=>(e(a,b,"read from private field"),c?c.call(a):b.get(a)),i$1=(a,b,c)=>{if(b.has(a))throw TypeError("Cannot add the same private member more than once");b instanceof WeakSet?b.add(a):b.set(a,c);},j$1=(a,b,c,d)=>(e(a,b,"write to private field"),d?d.call(a,c):b.set(a,c),c);
2
2
 
3
- var f$1={};g$1(f$1,{Channel:()=>a$1,PluginListener:()=>c$1,addPluginListener:()=>v$1,convertFileSrc:()=>m$1,invoke:()=>u$1,transformCallback:()=>o});function h$1(){return window.crypto.getRandomValues(new Uint32Array(1))[0]}function o(t,e=!1){let n=h$1(),r=`_${n}`;return Object.defineProperty(window,r,{value:i=>(e&&Reflect.deleteProperty(window,r),t?.(i)),writable:!1,configurable:!0}),n}var s,a$1=class a{constructor(){this.__TAURI_CHANNEL_MARKER__=!0;i(this,s,()=>{});this.id=o(e=>{h$2(this,s).call(this,e);});}set onmessage(e){j$1(this,s,e);}get onmessage(){return h$2(this,s)}toJSON(){return `__CHANNEL__:${this.id}`}};s=new WeakMap;var c$1=class c{constructor(e,n,r){this.plugin=e,this.event=n,this.channelId=r;}async unregister(){return u$1(`plugin:${this.plugin}|remove_listener`,{event:this.event,channelId:this.channelId})}};async function v$1(t,e,n){let r=new a$1;return r.onmessage=n,u$1(`plugin:${t}|register_listener`,{event:e,handler:r}).then(()=>new c$1(t,e,r.id))}async function u$1(t,e={}){return new Promise((n,r)=>{let i=o(d=>{n(d),Reflect.deleteProperty(window,`_${g}`);},!0),g=o(d=>{r(d),Reflect.deleteProperty(window,`_${i}`);},!0);window.__TAURI_IPC__({cmd:t,callback:i,error:g,...e});})}function m$1(t,e="asset"){let n=encodeURIComponent(t);return navigator.userAgent.includes("Windows")?`https://${e}.localhost/${n}`:`${e}://localhost/${n}`}
3
+ var T$1={};g$1(T$1,{Channel:()=>i,PluginListener:()=>o,addPluginListener:()=>l$1,convertFileSrc:()=>v$1,invoke:()=>u$1,transformCallback:()=>_$1});function _$1(e,n=!1){return window.__TAURI_INTERNALS__.transformCallback(e,n)}var r,i=class{constructor(){this.__TAURI_CHANNEL_MARKER__=!0;i$1(this,r,()=>{});this.id=_$1(n=>{h$1(this,r).call(this,n);});}set onmessage(n){j$1(this,r,n);}get onmessage(){return h$1(this,r)}toJSON(){return `__CHANNEL__:${this.id}`}};r=new WeakMap;var o=class{constructor(n,s,t){this.plugin=n,this.event=s,this.channelId=t;}async unregister(){return u$1(`plugin:${this.plugin}|remove_listener`,{event:this.event,channelId:this.channelId})}};async function l$1(e,n,s){let t=new i;return t.onmessage=s,u$1(`plugin:${e}|register_listener`,{event:n,handler:t}).then(()=>new o(e,n,t.id))}async function u$1(e,n={},s){return window.__TAURI_INTERNALS__.invoke(e,n,s)}function v$1(e,n="asset"){return window.__TAURI_INTERNALS__.convertFileSrc(e,n)}
4
4
 
5
- var O={};g$1(O,{BaseDirectory:()=>e,appCacheDir:()=>p,appConfigDir:()=>u,appDataDir:()=>c,appLocalDataDir:()=>a,appLogDir:()=>V,audioDir:()=>l,basename:()=>H,cacheDir:()=>g,configDir:()=>d,dataDir:()=>m,delimiter:()=>T,desktopDir:()=>y,dirname:()=>E,documentDir:()=>f,downloadDir:()=>h,executableDir:()=>P,extname:()=>F,fontDir:()=>v,homeDir:()=>_,isAbsolute:()=>M,join:()=>z,localDataDir:()=>D,normalize:()=>j,pictureDir:()=>b,publicDir:()=>A,resolve:()=>W,resolveResource:()=>L,resourceDir:()=>C,runtimeDir:()=>x,sep:()=>k,templateDir:()=>R,videoDir:()=>w});function t(){return navigator.appVersion.includes("Win")}var e=(r=>(r[r.Audio=1]="Audio",r[r.Cache=2]="Cache",r[r.Config=3]="Config",r[r.Data=4]="Data",r[r.LocalData=5]="LocalData",r[r.Document=6]="Document",r[r.Download=7]="Download",r[r.Picture=8]="Picture",r[r.Public=9]="Public",r[r.Video=10]="Video",r[r.Resource=11]="Resource",r[r.Temp=12]="Temp",r[r.AppConfig=13]="AppConfig",r[r.AppData=14]="AppData",r[r.AppLocalData=15]="AppLocalData",r[r.AppCache=16]="AppCache",r[r.AppLog=17]="AppLog",r[r.Desktop=18]="Desktop",r[r.Executable=19]="Executable",r[r.Font=20]="Font",r[r.Home=21]="Home",r[r.Runtime=22]="Runtime",r[r.Template=23]="Template",r))(e||{});async function u(){return u$1("plugin:path|resolve_directory",{directory:13})}async function c(){return u$1("plugin:path|resolve_directory",{directory:14})}async function a(){return u$1("plugin:path|resolve_directory",{directory:15})}async function p(){return u$1("plugin:path|resolve_directory",{directory:16})}async function l(){return u$1("plugin:path|resolve_directory",{directory:1})}async function g(){return u$1("plugin:path|resolve_directory",{directory:2})}async function d(){return u$1("plugin:path|resolve_directory",{directory:3})}async function m(){return u$1("plugin:path|resolve_directory",{directory:4})}async function y(){return u$1("plugin:path|resolve_directory",{directory:18})}async function f(){return u$1("plugin:path|resolve_directory",{directory:6})}async function h(){return u$1("plugin:path|resolve_directory",{directory:7})}async function P(){return u$1("plugin:path|resolve_directory",{directory:19})}async function v(){return u$1("plugin:path|resolve_directory",{directory:20})}async function _(){return u$1("plugin:path|resolve_directory",{directory:21})}async function D(){return u$1("plugin:path|resolve_directory",{directory:5})}async function b(){return u$1("plugin:path|resolve_directory",{directory:8})}async function A(){return u$1("plugin:path|resolve_directory",{directory:9})}async function C(){return u$1("plugin:path|resolve_directory",{directory:11})}async function L(i){return u$1("plugin:path|resolve_directory",{directory:11,path:i})}async function x(){return u$1("plugin:path|resolve_directory",{directory:22})}async function R(){return u$1("plugin:path|resolve_directory",{directory:23})}async function w(){return u$1("plugin:path|resolve_directory",{directory:10})}async function V(){return u$1("plugin:path|resolve_directory",{directory:17})}var k=t()?"\\":"/",T=t()?";":":";async function W(...i){return u$1("plugin:path|resolve",{paths:i})}async function j(i){return u$1("plugin:path|normalize",{path:i})}async function z(...i){return u$1("plugin:path|join",{paths:i})}async function E(i){return u$1("plugin:path|dirname",{path:i})}async function F(i){return u$1("plugin:path|extname",{path:i})}async function H(i,o){return u$1("plugin:path|basename",{path:i,ext:o})}async function M(i){return u$1("plugin:path|isAbsolute",{path:i})}
5
+ var U={};g$1(U,{BaseDirectory:()=>t,appCacheDir:()=>p,appConfigDir:()=>s,appDataDir:()=>u,appLocalDataDir:()=>c,appLogDir:()=>w,audioDir:()=>a,basename:()=>H,cacheDir:()=>l,configDir:()=>g,dataDir:()=>d,delimiter:()=>E,desktopDir:()=>m,dirname:()=>z,documentDir:()=>y,downloadDir:()=>h,executableDir:()=>f,extname:()=>F,fontDir:()=>P,homeDir:()=>_,isAbsolute:()=>S,join:()=>j,localDataDir:()=>v,normalize:()=>N,pictureDir:()=>A,publicDir:()=>D,resolve:()=>I,resolveResource:()=>C,resourceDir:()=>b,runtimeDir:()=>L,sep:()=>k,tempDir:()=>x,templateDir:()=>R,videoDir:()=>T});var t=(r=>(r[r.Audio=1]="Audio",r[r.Cache=2]="Cache",r[r.Config=3]="Config",r[r.Data=4]="Data",r[r.LocalData=5]="LocalData",r[r.Document=6]="Document",r[r.Download=7]="Download",r[r.Picture=8]="Picture",r[r.Public=9]="Public",r[r.Video=10]="Video",r[r.Resource=11]="Resource",r[r.Temp=12]="Temp",r[r.AppConfig=13]="AppConfig",r[r.AppData=14]="AppData",r[r.AppLocalData=15]="AppLocalData",r[r.AppCache=16]="AppCache",r[r.AppLog=17]="AppLog",r[r.Desktop=18]="Desktop",r[r.Executable=19]="Executable",r[r.Font=20]="Font",r[r.Home=21]="Home",r[r.Runtime=22]="Runtime",r[r.Template=23]="Template",r))(t||{});async function s(){return u$1("plugin:path|resolve_directory",{directory:13})}async function u(){return u$1("plugin:path|resolve_directory",{directory:14})}async function c(){return u$1("plugin:path|resolve_directory",{directory:15})}async function p(){return u$1("plugin:path|resolve_directory",{directory:16})}async function a(){return u$1("plugin:path|resolve_directory",{directory:1})}async function l(){return u$1("plugin:path|resolve_directory",{directory:2})}async function g(){return u$1("plugin:path|resolve_directory",{directory:3})}async function d(){return u$1("plugin:path|resolve_directory",{directory:4})}async function m(){return u$1("plugin:path|resolve_directory",{directory:18})}async function y(){return u$1("plugin:path|resolve_directory",{directory:6})}async function h(){return u$1("plugin:path|resolve_directory",{directory:7})}async function f(){return u$1("plugin:path|resolve_directory",{directory:19})}async function P(){return u$1("plugin:path|resolve_directory",{directory:20})}async function _(){return u$1("plugin:path|resolve_directory",{directory:21})}async function v(){return u$1("plugin:path|resolve_directory",{directory:5})}async function A(){return u$1("plugin:path|resolve_directory",{directory:8})}async function D(){return u$1("plugin:path|resolve_directory",{directory:9})}async function b(){return u$1("plugin:path|resolve_directory",{directory:11})}async function C(i){return u$1("plugin:path|resolve_directory",{directory:11,path:i})}async function L(){return u$1("plugin:path|resolve_directory",{directory:22})}async function R(){return u$1("plugin:path|resolve_directory",{directory:23})}async function T(){return u$1("plugin:path|resolve_directory",{directory:10})}async function w(){return u$1("plugin:path|resolve_directory",{directory:17})}async function x(i){return u$1("plugin:path|resolve_directory",{directory:12})}function k(){return window.__TAURI_INTERNALS__.plugins.path.sep}function E(){return window.__TAURI_INTERNALS__.plugins.path.delimiter}async function I(...i){return u$1("plugin:path|resolve",{paths:i})}async function N(i){return u$1("plugin:path|normalize",{path:i})}async function j(...i){return u$1("plugin:path|join",{paths:i})}async function z(i){return u$1("plugin:path|dirname",{path:i})}async function F(i){return u$1("plugin:path|extname",{path:i})}async function H(i,e){return u$1("plugin:path|basename",{path:i,ext:e})}async function S(i){return u$1("plugin:path|isAbsolute",{path:i})}
6
6
 
7
7
  // Copyright 2019-2023 Tauri Programme within The Commons Conservancy
8
+ // SPDX-License-Identifier: Apache-2.0
9
+ // SPDX-License-Identifier: MIT
10
+ /**
11
+ * Access the file system.
12
+ *
13
+ * ## Security
14
+ *
15
+ * This module prevents path traversal, not allowing absolute paths or parent dir components
16
+ * (i.e. "/usr/path/to/file" or "../path/to/file" paths are not allowed).
17
+ * Paths accessed with this API must be relative to one of the {@link BaseDirectory | base directories}
18
+ * so if you need access to arbitrary filesystem paths, you must write such logic on the core layer instead.
19
+ *
20
+ * The API has a scope configuration that forces you to restrict the paths that can be accessed using glob patterns.
21
+ *
22
+ * The scope configuration is an array of glob patterns describing folder paths that are allowed.
23
+ * For instance, this scope configuration only allows accessing files on the
24
+ * *databases* folder of the {@link path.appDataDir | $APPDATA directory}:
25
+ * ```json
26
+ * {
27
+ * "plugins": {
28
+ * "fs": {
29
+ * "scope": ["$APPDATA/databases/*"]
30
+ * }
31
+ * }
32
+ * }
33
+ * ```
34
+ *
35
+ * Notice the use of the `$APPDATA` variable. The value is injected at runtime, resolving to the {@link path.appDataDir | app data directory}.
36
+ * The available variables are:
37
+ * {@link path.appConfigDir | `$APPCONFIG`}, {@link path.appDataDir | `$APPDATA`}, {@link path.appLocalDataDir | `$APPLOCALDATA`},
38
+ * {@link path.appCacheDir | `$APPCACHE`}, {@link path.appLogDir | `$APPLOG`},
39
+ * {@link path.audioDir | `$AUDIO`}, {@link path.cacheDir | `$CACHE`}, {@link path.configDir | `$CONFIG`}, {@link path.dataDir | `$DATA`},
40
+ * {@link path.localDataDir | `$LOCALDATA`}, {@link path.desktopDir | `$DESKTOP`}, {@link path.documentDir | `$DOCUMENT`},
41
+ * {@link path.downloadDir | `$DOWNLOAD`}, {@link path.executableDir | `$EXE`}, {@link path.fontDir | `$FONT`}, {@link path.homeDir | `$HOME`},
42
+ * {@link path.pictureDir | `$PICTURE`}, {@link path.publicDir | `$PUBLIC`}, {@link path.runtimeDir | `$RUNTIME`},
43
+ * {@link path.templateDir | `$TEMPLATE`}, {@link path.videoDir | `$VIDEO`}, {@link path.resourceDir | `$RESOURCE`},
44
+ * {@link os.tempdir | `$TEMP`}.
45
+ *
46
+ * Trying to execute any API with a URL not configured on the scope results in a promise rejection due to denied access.
47
+ *
48
+ * Note that this scope applies to **all** APIs on this module.
49
+ *
50
+ * @module
51
+ */
8
52
  /**
9
53
  * Reads a file as an UTF-8 encoded string.
10
54
  * @example
@@ -17,7 +61,7 @@ var O={};g$1(O,{BaseDirectory:()=>e,appCacheDir:()=>p,appConfigDir:()=>u,appData
17
61
  * @since 2.0.0
18
62
  */
19
63
  async function readTextFile(filePath, options = {}) {
20
- return await window.__TAURI_INVOKE__("plugin:fs|read_text_file", {
64
+ return await u$1("plugin:fs|read_text_file", {
21
65
  path: filePath,
22
66
  options,
23
67
  });
@@ -34,7 +78,7 @@ async function readTextFile(filePath, options = {}) {
34
78
  * @since 2.0.0
35
79
  */
36
80
  async function readBinaryFile(filePath, options = {}) {
37
- const arr = await window.__TAURI_INVOKE__("plugin:fs|read_file", {
81
+ const arr = await u$1("plugin:fs|read_file", {
38
82
  path: filePath,
39
83
  options,
40
84
  });
@@ -69,7 +113,7 @@ async function writeTextFile(path, contents, options) {
69
113
  else {
70
114
  fileOptions = contents;
71
115
  }
72
- return await window.__TAURI_INVOKE__("plugin:fs|write_file", {
116
+ return await u$1("plugin:fs|write_file", {
73
117
  path: file.path,
74
118
  contents: Array.from(new TextEncoder().encode(file.contents)),
75
119
  options: fileOptions,
@@ -105,7 +149,7 @@ async function writeBinaryFile(path, contents, options) {
105
149
  // @ts-expect-error in this case `contents` is always a BinaryFileContents
106
150
  file.contents = contents !== null && contents !== void 0 ? contents : [];
107
151
  }
108
- return await window.__TAURI_INVOKE__("plugin:fs|write_binary_file", {
152
+ return await u$1("plugin:fs|write_file", {
109
153
  path: file.path,
110
154
  contents: Array.from(file.contents instanceof ArrayBuffer
111
155
  ? new Uint8Array(file.contents)
@@ -134,7 +178,7 @@ async function writeBinaryFile(path, contents, options) {
134
178
  * @since 2.0.0
135
179
  */
136
180
  async function readDir(dir, options = {}) {
137
- return await window.__TAURI_INVOKE__("plugin:fs|read_dir", {
181
+ return await u$1("plugin:fs|read_dir", {
138
182
  path: dir,
139
183
  options,
140
184
  });
@@ -155,7 +199,7 @@ async function readDir(dir, options = {}) {
155
199
  * @since 2.0.0
156
200
  */
157
201
  async function createDir(dir, options = {}) {
158
- return await window.__TAURI_INVOKE__("plugin:fs|create_dir", {
202
+ return await u$1("plugin:fs|create_dir", {
159
203
  path: dir,
160
204
  options,
161
205
  });
@@ -175,7 +219,7 @@ async function createDir(dir, options = {}) {
175
219
  * @since 2.0.0
176
220
  */
177
221
  async function removeDir(dir, options = {}) {
178
- return await window.__TAURI_INVOKE__("plugin:fs|remove_dir", {
222
+ return await u$1("plugin:fs|remove_dir", {
179
223
  path: dir,
180
224
  options,
181
225
  });
@@ -194,7 +238,7 @@ async function removeDir(dir, options = {}) {
194
238
  * @since 2.0.0
195
239
  */
196
240
  async function copyFile(source, destination, options = {}) {
197
- return await window.__TAURI_INVOKE__("plugin:fs|copy_file", {
241
+ return await u$1("plugin:fs|copy_file", {
198
242
  source,
199
243
  destination,
200
244
  options,
@@ -214,7 +258,7 @@ async function copyFile(source, destination, options = {}) {
214
258
  * @since 2.0.0
215
259
  */
216
260
  async function removeFile(file, options = {}) {
217
- return await window.__TAURI_INVOKE__("plugin:fs|remove_file", {
261
+ return await u$1("plugin:fs|remove_file", {
218
262
  path: file,
219
263
  options,
220
264
  });
@@ -233,7 +277,7 @@ async function removeFile(file, options = {}) {
233
277
  * @since 2.0.0
234
278
  */
235
279
  async function renameFile(oldPath, newPath, options = {}) {
236
- return await window.__TAURI_INVOKE__("plugin:fs|rename_file", {
280
+ return await u$1("plugin:fs|rename_file", {
237
281
  oldPath,
238
282
  newPath,
239
283
  options,
@@ -251,7 +295,7 @@ async function renameFile(oldPath, newPath, options = {}) {
251
295
  * @since 2.0.0
252
296
  */
253
297
  async function exists(path) {
254
- return await window.__TAURI_INVOKE__("plugin:fs|exists", { path });
298
+ return await u$1("plugin:fs|exists", { path });
255
299
  }
256
300
  /**
257
301
  * Returns the metadata for the given path.
@@ -259,11 +303,9 @@ async function exists(path) {
259
303
  * @since 2.0.0
260
304
  */
261
305
  async function metadata(path) {
262
- return await window
263
- .__TAURI_INVOKE__("plugin:fs|metadata", {
306
+ return await u$1("plugin:fs|metadata", {
264
307
  path,
265
- })
266
- .then((metadata) => {
308
+ }).then((metadata) => {
267
309
  const { accessedAtMs, createdAtMs, modifiedAtMs, ...data } = metadata;
268
310
  return {
269
311
  accessedAt: new Date(accessedAtMs),
@@ -274,5 +316,5 @@ async function metadata(path) {
274
316
  });
275
317
  }
276
318
 
277
- export { e as BaseDirectory, e as Dir, copyFile, createDir, exists, metadata, readBinaryFile, readDir, readTextFile, removeDir, removeFile, renameFile, writeBinaryFile, writeTextFile as writeFile, writeTextFile };
319
+ export { t as BaseDirectory, t as Dir, copyFile, createDir, exists, metadata, readBinaryFile, readDir, readTextFile, removeDir, removeFile, renameFile, writeBinaryFile, writeTextFile as writeFile, writeTextFile };
278
320
  //# sourceMappingURL=index.min.js.map
package/dist-js/index.mjs CHANGED
@@ -1,6 +1,51 @@
1
1
  export { BaseDirectory, BaseDirectory as Dir } from '@tauri-apps/api/path';
2
+ import { invoke } from '@tauri-apps/api/primitives';
2
3
 
3
4
  // Copyright 2019-2023 Tauri Programme within The Commons Conservancy
5
+ // SPDX-License-Identifier: Apache-2.0
6
+ // SPDX-License-Identifier: MIT
7
+ /**
8
+ * Access the file system.
9
+ *
10
+ * ## Security
11
+ *
12
+ * This module prevents path traversal, not allowing absolute paths or parent dir components
13
+ * (i.e. "/usr/path/to/file" or "../path/to/file" paths are not allowed).
14
+ * Paths accessed with this API must be relative to one of the {@link BaseDirectory | base directories}
15
+ * so if you need access to arbitrary filesystem paths, you must write such logic on the core layer instead.
16
+ *
17
+ * The API has a scope configuration that forces you to restrict the paths that can be accessed using glob patterns.
18
+ *
19
+ * The scope configuration is an array of glob patterns describing folder paths that are allowed.
20
+ * For instance, this scope configuration only allows accessing files on the
21
+ * *databases* folder of the {@link path.appDataDir | $APPDATA directory}:
22
+ * ```json
23
+ * {
24
+ * "plugins": {
25
+ * "fs": {
26
+ * "scope": ["$APPDATA/databases/*"]
27
+ * }
28
+ * }
29
+ * }
30
+ * ```
31
+ *
32
+ * Notice the use of the `$APPDATA` variable. The value is injected at runtime, resolving to the {@link path.appDataDir | app data directory}.
33
+ * The available variables are:
34
+ * {@link path.appConfigDir | `$APPCONFIG`}, {@link path.appDataDir | `$APPDATA`}, {@link path.appLocalDataDir | `$APPLOCALDATA`},
35
+ * {@link path.appCacheDir | `$APPCACHE`}, {@link path.appLogDir | `$APPLOG`},
36
+ * {@link path.audioDir | `$AUDIO`}, {@link path.cacheDir | `$CACHE`}, {@link path.configDir | `$CONFIG`}, {@link path.dataDir | `$DATA`},
37
+ * {@link path.localDataDir | `$LOCALDATA`}, {@link path.desktopDir | `$DESKTOP`}, {@link path.documentDir | `$DOCUMENT`},
38
+ * {@link path.downloadDir | `$DOWNLOAD`}, {@link path.executableDir | `$EXE`}, {@link path.fontDir | `$FONT`}, {@link path.homeDir | `$HOME`},
39
+ * {@link path.pictureDir | `$PICTURE`}, {@link path.publicDir | `$PUBLIC`}, {@link path.runtimeDir | `$RUNTIME`},
40
+ * {@link path.templateDir | `$TEMPLATE`}, {@link path.videoDir | `$VIDEO`}, {@link path.resourceDir | `$RESOURCE`},
41
+ * {@link os.tempdir | `$TEMP`}.
42
+ *
43
+ * Trying to execute any API with a URL not configured on the scope results in a promise rejection due to denied access.
44
+ *
45
+ * Note that this scope applies to **all** APIs on this module.
46
+ *
47
+ * @module
48
+ */
4
49
  /**
5
50
  * Reads a file as an UTF-8 encoded string.
6
51
  * @example
@@ -13,7 +58,7 @@ export { BaseDirectory, BaseDirectory as Dir } from '@tauri-apps/api/path';
13
58
  * @since 2.0.0
14
59
  */
15
60
  async function readTextFile(filePath, options = {}) {
16
- return await window.__TAURI_INVOKE__("plugin:fs|read_text_file", {
61
+ return await invoke("plugin:fs|read_text_file", {
17
62
  path: filePath,
18
63
  options,
19
64
  });
@@ -30,7 +75,7 @@ async function readTextFile(filePath, options = {}) {
30
75
  * @since 2.0.0
31
76
  */
32
77
  async function readBinaryFile(filePath, options = {}) {
33
- const arr = await window.__TAURI_INVOKE__("plugin:fs|read_file", {
78
+ const arr = await invoke("plugin:fs|read_file", {
34
79
  path: filePath,
35
80
  options,
36
81
  });
@@ -65,7 +110,7 @@ async function writeTextFile(path, contents, options) {
65
110
  else {
66
111
  fileOptions = contents;
67
112
  }
68
- return await window.__TAURI_INVOKE__("plugin:fs|write_file", {
113
+ return await invoke("plugin:fs|write_file", {
69
114
  path: file.path,
70
115
  contents: Array.from(new TextEncoder().encode(file.contents)),
71
116
  options: fileOptions,
@@ -101,7 +146,7 @@ async function writeBinaryFile(path, contents, options) {
101
146
  // @ts-expect-error in this case `contents` is always a BinaryFileContents
102
147
  file.contents = contents !== null && contents !== void 0 ? contents : [];
103
148
  }
104
- return await window.__TAURI_INVOKE__("plugin:fs|write_binary_file", {
149
+ return await invoke("plugin:fs|write_file", {
105
150
  path: file.path,
106
151
  contents: Array.from(file.contents instanceof ArrayBuffer
107
152
  ? new Uint8Array(file.contents)
@@ -130,7 +175,7 @@ async function writeBinaryFile(path, contents, options) {
130
175
  * @since 2.0.0
131
176
  */
132
177
  async function readDir(dir, options = {}) {
133
- return await window.__TAURI_INVOKE__("plugin:fs|read_dir", {
178
+ return await invoke("plugin:fs|read_dir", {
134
179
  path: dir,
135
180
  options,
136
181
  });
@@ -151,7 +196,7 @@ async function readDir(dir, options = {}) {
151
196
  * @since 2.0.0
152
197
  */
153
198
  async function createDir(dir, options = {}) {
154
- return await window.__TAURI_INVOKE__("plugin:fs|create_dir", {
199
+ return await invoke("plugin:fs|create_dir", {
155
200
  path: dir,
156
201
  options,
157
202
  });
@@ -171,7 +216,7 @@ async function createDir(dir, options = {}) {
171
216
  * @since 2.0.0
172
217
  */
173
218
  async function removeDir(dir, options = {}) {
174
- return await window.__TAURI_INVOKE__("plugin:fs|remove_dir", {
219
+ return await invoke("plugin:fs|remove_dir", {
175
220
  path: dir,
176
221
  options,
177
222
  });
@@ -190,7 +235,7 @@ async function removeDir(dir, options = {}) {
190
235
  * @since 2.0.0
191
236
  */
192
237
  async function copyFile(source, destination, options = {}) {
193
- return await window.__TAURI_INVOKE__("plugin:fs|copy_file", {
238
+ return await invoke("plugin:fs|copy_file", {
194
239
  source,
195
240
  destination,
196
241
  options,
@@ -210,7 +255,7 @@ async function copyFile(source, destination, options = {}) {
210
255
  * @since 2.0.0
211
256
  */
212
257
  async function removeFile(file, options = {}) {
213
- return await window.__TAURI_INVOKE__("plugin:fs|remove_file", {
258
+ return await invoke("plugin:fs|remove_file", {
214
259
  path: file,
215
260
  options,
216
261
  });
@@ -229,7 +274,7 @@ async function removeFile(file, options = {}) {
229
274
  * @since 2.0.0
230
275
  */
231
276
  async function renameFile(oldPath, newPath, options = {}) {
232
- return await window.__TAURI_INVOKE__("plugin:fs|rename_file", {
277
+ return await invoke("plugin:fs|rename_file", {
233
278
  oldPath,
234
279
  newPath,
235
280
  options,
@@ -247,7 +292,7 @@ async function renameFile(oldPath, newPath, options = {}) {
247
292
  * @since 2.0.0
248
293
  */
249
294
  async function exists(path) {
250
- return await window.__TAURI_INVOKE__("plugin:fs|exists", { path });
295
+ return await invoke("plugin:fs|exists", { path });
251
296
  }
252
297
  /**
253
298
  * Returns the metadata for the given path.
@@ -255,11 +300,9 @@ async function exists(path) {
255
300
  * @since 2.0.0
256
301
  */
257
302
  async function metadata(path) {
258
- return await window
259
- .__TAURI_INVOKE__("plugin:fs|metadata", {
303
+ return await invoke("plugin:fs|metadata", {
260
304
  path,
261
- })
262
- .then((metadata) => {
305
+ }).then((metadata) => {
263
306
  const { accessedAtMs, createdAtMs, modifiedAtMs, ...data } = metadata;
264
307
  return {
265
308
  accessedAt: new Date(accessedAtMs),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tauri-apps/plugin-fs",
3
- "version": "2.0.0-alpha.0",
3
+ "version": "2.0.0-alpha.2",
4
4
  "description": "Access the file system.",
5
5
  "license": "MIT or APACHE-2.0",
6
6
  "authors": [
@@ -25,7 +25,7 @@
25
25
  "tslib": "^2.4.1"
26
26
  },
27
27
  "dependencies": {
28
- "@tauri-apps/api": "2.0.0-alpha.4"
28
+ "@tauri-apps/api": "2.0.0-alpha.9"
29
29
  },
30
30
  "scripts": {
31
31
  "build": "rollup -c"