@tauri-apps/plugin-fs 2.0.0-alpha.0 → 2.0.0-alpha.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/README.md +1 -1
- package/dist-js/index.min.js +49 -5
- package/dist-js/index.mjs +45 -1
- package/package.json +2 -2
package/README.md
CHANGED
package/dist-js/index.min.js
CHANGED
|
@@ -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
|
+
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=(a,b,c)=>{if(!b.has(a))throw TypeError("Cannot "+c)};var h$2=(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
|
|
3
|
+
var h$1={};g$1(h$1,{Channel:()=>o,PluginListener:()=>a$1,addPluginListener:()=>m$1,convertFileSrc:()=>y$1,invoke:()=>u$1,transformCallback:()=>s$1});function f$1(){return window.crypto.getRandomValues(new Uint32Array(1))[0]}function s$1(n,e=!1){let t=f$1(),r=`_${t}`;return Object.defineProperty(window,r,{value:c=>(e&&Reflect.deleteProperty(window,r),n?.(c)),writable:!1,configurable:!0}),t}var i,o=class{constructor(){this.__TAURI_CHANNEL_MARKER__=!0;i$1(this,i,()=>{});this.id=s$1(e=>{h$2(this,i).call(this,e);});}set onmessage(e){j$1(this,i,e);}get onmessage(){return h$2(this,i)}toJSON(){return `__CHANNEL__:${this.id}`}};i=new WeakMap;var a$1=class a{constructor(e,t,r){this.plugin=e,this.event=t,this.channelId=r;}async unregister(){return u$1(`plugin:${this.plugin}|remove_listener`,{event:this.event,channelId:this.channelId})}};async function m$1(n,e,t){let r=new o;return r.onmessage=t,u$1(`plugin:${n}|register_listener`,{event:e,handler:r}).then(()=>new a$1(n,e,r.id))}async function u$1(n,e={},t){return new Promise((r,c)=>{let g=s$1(d=>{r(d),Reflect.deleteProperty(window,`_${_}`);},!0),_=s$1(d=>{c(d),Reflect.deleteProperty(window,`_${g}`);},!0);window.__TAURI_IPC__({cmd:n,callback:g,error:_,payload:e,options:t});})}function y$1(n,e="asset"){return window.__TAURI__.convertFileSrc(n,e)}
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var q={};g$1(q,{BaseDirectory:()=>t,appCacheDir:()=>p,appConfigDir:()=>s,appDataDir:()=>u,appLocalDataDir:()=>c,appLogDir:()=>x,audioDir:()=>a,basename:()=>U,cacheDir:()=>l,configDir:()=>g,dataDir:()=>d,delimiter:()=>j,desktopDir:()=>m,dirname:()=>H,documentDir:()=>y,downloadDir:()=>h,executableDir:()=>f,extname:()=>I,fontDir:()=>_,homeDir:()=>P,isAbsolute:()=>V,join:()=>F,localDataDir:()=>v,normalize:()=>E,pictureDir:()=>D,publicDir:()=>A,resolve:()=>z,resolveResource:()=>C,resourceDir:()=>b,runtimeDir:()=>L,sep:()=>k,tempDir:()=>T,templateDir:()=>R,videoDir:()=>w});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 _(){return u$1("plugin:path|resolve_directory",{directory:20})}async function P(){return u$1("plugin:path|resolve_directory",{directory:21})}async function v(){return u$1("plugin:path|resolve_directory",{directory:5})}async function D(){return u$1("plugin:path|resolve_directory",{directory:8})}async function A(){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 w(){return u$1("plugin:path|resolve_directory",{directory:10})}async function x(){return u$1("plugin:path|resolve_directory",{directory:17})}async function T(i){return u$1("plugin:path|resolve_directory",{directory:12})}function k(){return window.__TAURI__.path.__sep}function j(){return window.__TAURI__.path.__delimiter}async function z(...i){return u$1("plugin:path|resolve",{paths:i})}async function E(i){return u$1("plugin:path|normalize",{path:i})}async function F(...i){return u$1("plugin:path|join",{paths:i})}async function H(i){return u$1("plugin:path|dirname",{path:i})}async function I(i){return u$1("plugin:path|extname",{path:i})}async function U(i,e){return u$1("plugin:path|basename",{path:i,ext:e})}async function V(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
|
|
@@ -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|
|
|
152
|
+
return await window.__TAURI_INVOKE__("plugin:fs|write_file", {
|
|
109
153
|
path: file.path,
|
|
110
154
|
contents: Array.from(file.contents instanceof ArrayBuffer
|
|
111
155
|
? new Uint8Array(file.contents)
|
|
@@ -274,5 +318,5 @@ async function metadata(path) {
|
|
|
274
318
|
});
|
|
275
319
|
}
|
|
276
320
|
|
|
277
|
-
export {
|
|
321
|
+
export { t as BaseDirectory, t as Dir, copyFile, createDir, exists, metadata, readBinaryFile, readDir, readTextFile, removeDir, removeFile, renameFile, writeBinaryFile, writeTextFile as writeFile, writeTextFile };
|
|
278
322
|
//# sourceMappingURL=index.min.js.map
|
package/dist-js/index.mjs
CHANGED
|
@@ -1,6 +1,50 @@
|
|
|
1
1
|
export { BaseDirectory, BaseDirectory as Dir } from '@tauri-apps/api/path';
|
|
2
2
|
|
|
3
3
|
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
|
4
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
// SPDX-License-Identifier: MIT
|
|
6
|
+
/**
|
|
7
|
+
* Access the file system.
|
|
8
|
+
*
|
|
9
|
+
* ## Security
|
|
10
|
+
*
|
|
11
|
+
* This module prevents path traversal, not allowing absolute paths or parent dir components
|
|
12
|
+
* (i.e. "/usr/path/to/file" or "../path/to/file" paths are not allowed).
|
|
13
|
+
* Paths accessed with this API must be relative to one of the {@link BaseDirectory | base directories}
|
|
14
|
+
* so if you need access to arbitrary filesystem paths, you must write such logic on the core layer instead.
|
|
15
|
+
*
|
|
16
|
+
* The API has a scope configuration that forces you to restrict the paths that can be accessed using glob patterns.
|
|
17
|
+
*
|
|
18
|
+
* The scope configuration is an array of glob patterns describing folder paths that are allowed.
|
|
19
|
+
* For instance, this scope configuration only allows accessing files on the
|
|
20
|
+
* *databases* folder of the {@link path.appDataDir | $APPDATA directory}:
|
|
21
|
+
* ```json
|
|
22
|
+
* {
|
|
23
|
+
* "plugins": {
|
|
24
|
+
* "fs": {
|
|
25
|
+
* "scope": ["$APPDATA/databases/*"]
|
|
26
|
+
* }
|
|
27
|
+
* }
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* Notice the use of the `$APPDATA` variable. The value is injected at runtime, resolving to the {@link path.appDataDir | app data directory}.
|
|
32
|
+
* The available variables are:
|
|
33
|
+
* {@link path.appConfigDir | `$APPCONFIG`}, {@link path.appDataDir | `$APPDATA`}, {@link path.appLocalDataDir | `$APPLOCALDATA`},
|
|
34
|
+
* {@link path.appCacheDir | `$APPCACHE`}, {@link path.appLogDir | `$APPLOG`},
|
|
35
|
+
* {@link path.audioDir | `$AUDIO`}, {@link path.cacheDir | `$CACHE`}, {@link path.configDir | `$CONFIG`}, {@link path.dataDir | `$DATA`},
|
|
36
|
+
* {@link path.localDataDir | `$LOCALDATA`}, {@link path.desktopDir | `$DESKTOP`}, {@link path.documentDir | `$DOCUMENT`},
|
|
37
|
+
* {@link path.downloadDir | `$DOWNLOAD`}, {@link path.executableDir | `$EXE`}, {@link path.fontDir | `$FONT`}, {@link path.homeDir | `$HOME`},
|
|
38
|
+
* {@link path.pictureDir | `$PICTURE`}, {@link path.publicDir | `$PUBLIC`}, {@link path.runtimeDir | `$RUNTIME`},
|
|
39
|
+
* {@link path.templateDir | `$TEMPLATE`}, {@link path.videoDir | `$VIDEO`}, {@link path.resourceDir | `$RESOURCE`},
|
|
40
|
+
* {@link os.tempdir | `$TEMP`}.
|
|
41
|
+
*
|
|
42
|
+
* Trying to execute any API with a URL not configured on the scope results in a promise rejection due to denied access.
|
|
43
|
+
*
|
|
44
|
+
* Note that this scope applies to **all** APIs on this module.
|
|
45
|
+
*
|
|
46
|
+
* @module
|
|
47
|
+
*/
|
|
4
48
|
/**
|
|
5
49
|
* Reads a file as an UTF-8 encoded string.
|
|
6
50
|
* @example
|
|
@@ -101,7 +145,7 @@ async function writeBinaryFile(path, contents, options) {
|
|
|
101
145
|
// @ts-expect-error in this case `contents` is always a BinaryFileContents
|
|
102
146
|
file.contents = contents !== null && contents !== void 0 ? contents : [];
|
|
103
147
|
}
|
|
104
|
-
return await window.__TAURI_INVOKE__("plugin:fs|
|
|
148
|
+
return await window.__TAURI_INVOKE__("plugin:fs|write_file", {
|
|
105
149
|
path: file.path,
|
|
106
150
|
contents: Array.from(file.contents instanceof ArrayBuffer
|
|
107
151
|
? new Uint8Array(file.contents)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tauri-apps/plugin-fs",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.1",
|
|
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.
|
|
28
|
+
"@tauri-apps/api": "2.0.0-alpha.6"
|
|
29
29
|
},
|
|
30
30
|
"scripts": {
|
|
31
31
|
"build": "rollup -c"
|