@simplysm/capacitor-plugin-file-system 13.0.75 → 13.0.77
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 +46 -53
- package/android/src/main/java/kr/co/simplysm/capacitor/filesystem/FileSystemPlugin.java +5 -5
- package/dist/FileSystem.d.ts +9 -12
- package/dist/FileSystem.d.ts.map +1 -1
- package/dist/FileSystem.js +24 -29
- package/dist/FileSystem.js.map +1 -1
- package/dist/{IFileSystemPlugin.d.ts → FileSystemPlugin.d.ts} +9 -9
- package/dist/FileSystemPlugin.d.ts.map +1 -0
- package/dist/FileSystemPlugin.js +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/web/FileSystemWeb.d.ts +7 -7
- package/dist/web/FileSystemWeb.d.ts.map +1 -1
- package/dist/web/FileSystemWeb.js +9 -35
- package/dist/web/FileSystemWeb.js.map +1 -1
- package/dist/web/VirtualFileSystem.d.ts +10 -10
- package/dist/web/VirtualFileSystem.d.ts.map +1 -1
- package/dist/web/VirtualFileSystem.js +8 -67
- package/dist/web/VirtualFileSystem.js.map +1 -1
- package/package.json +3 -2
- package/src/FileSystem.ts +30 -31
- package/src/{IFileSystemPlugin.ts → FileSystemPlugin.ts} +8 -8
- package/src/index.ts +1 -1
- package/src/web/FileSystemWeb.ts +13 -39
- package/src/web/VirtualFileSystem.ts +13 -77
- package/dist/IFileSystemPlugin.d.ts.map +0 -1
- package/dist/IFileSystemPlugin.js +0 -1
- package/dist/web/IndexedDbStore.d.ts +0 -16
- package/dist/web/IndexedDbStore.d.ts.map +0 -1
- package/dist/web/IndexedDbStore.js +0 -76
- package/dist/web/IndexedDbStore.js.map +0 -6
- package/src/web/IndexedDbStore.ts +0 -88
- /package/dist/{IFileSystemPlugin.js.map → FileSystemPlugin.js.map} +0 -0
package/README.md
CHANGED
|
@@ -22,22 +22,22 @@ An abstract class that provides static methods for file system access via the Ca
|
|
|
22
22
|
import { FileSystem } from "@simplysm/capacitor-plugin-file-system";
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
-
#### `FileSystem.
|
|
25
|
+
#### `FileSystem.checkPermissions()`
|
|
26
26
|
|
|
27
27
|
Checks whether the required file system permission has been granted.
|
|
28
28
|
|
|
29
29
|
```typescript
|
|
30
|
-
static async
|
|
30
|
+
static async checkPermissions(): Promise<boolean>
|
|
31
31
|
```
|
|
32
32
|
|
|
33
33
|
```typescript
|
|
34
|
-
const granted = await FileSystem.
|
|
34
|
+
const granted = await FileSystem.checkPermissions();
|
|
35
35
|
if (!granted) {
|
|
36
|
-
await FileSystem.
|
|
36
|
+
await FileSystem.requestPermissions();
|
|
37
37
|
}
|
|
38
38
|
```
|
|
39
39
|
|
|
40
|
-
#### `FileSystem.
|
|
40
|
+
#### `FileSystem.requestPermissions()`
|
|
41
41
|
|
|
42
42
|
Requests the required file system permission.
|
|
43
43
|
|
|
@@ -45,19 +45,19 @@ Requests the required file system permission.
|
|
|
45
45
|
- Android 10 and below: Shows the OS permission dialog.
|
|
46
46
|
|
|
47
47
|
```typescript
|
|
48
|
-
static async
|
|
48
|
+
static async requestPermissions(): Promise<void>
|
|
49
49
|
```
|
|
50
50
|
|
|
51
51
|
```typescript
|
|
52
|
-
await FileSystem.
|
|
52
|
+
await FileSystem.requestPermissions();
|
|
53
53
|
```
|
|
54
54
|
|
|
55
55
|
#### `FileSystem.readdir(dirPath)`
|
|
56
56
|
|
|
57
|
-
Reads the contents of a directory and returns an array of `
|
|
57
|
+
Reads the contents of a directory and returns an array of `FileInfo` objects.
|
|
58
58
|
|
|
59
59
|
```typescript
|
|
60
|
-
static async readdir(dirPath: string): Promise<
|
|
60
|
+
static async readdir(dirPath: string): Promise<FileInfo[]>
|
|
61
61
|
```
|
|
62
62
|
|
|
63
63
|
```typescript
|
|
@@ -72,34 +72,34 @@ for (const entry of entries) {
|
|
|
72
72
|
Returns the absolute path for the given storage type.
|
|
73
73
|
|
|
74
74
|
```typescript
|
|
75
|
-
static async getStoragePath(type:
|
|
75
|
+
static async getStoragePath(type: StorageType): Promise<string>
|
|
76
76
|
```
|
|
77
77
|
|
|
78
|
-
| `type` value
|
|
79
|
-
|
|
80
|
-
| `"external"`
|
|
81
|
-
| `"externalFiles"
|
|
82
|
-
| `"externalCache"
|
|
83
|
-
| `"externalMedia"
|
|
84
|
-
| `"appData"`
|
|
85
|
-
| `"appFiles"`
|
|
86
|
-
| `"appCache"`
|
|
78
|
+
| `type` value | Description |
|
|
79
|
+
|-------------------|--------------------------------------------------------------------|
|
|
80
|
+
| `"external"` | External storage root (`Environment.getExternalStorageDirectory`) |
|
|
81
|
+
| `"externalFiles"` | App-specific external files directory |
|
|
82
|
+
| `"externalCache"` | App-specific external cache directory |
|
|
83
|
+
| `"externalMedia"` | App-specific external media directory |
|
|
84
|
+
| `"appData"` | App data directory |
|
|
85
|
+
| `"appFiles"` | App files directory |
|
|
86
|
+
| `"appCache"` | App cache directory |
|
|
87
87
|
|
|
88
88
|
```typescript
|
|
89
89
|
const path = await FileSystem.getStoragePath("external");
|
|
90
90
|
console.log(path); // e.g. "/storage/emulated/0"
|
|
91
91
|
```
|
|
92
92
|
|
|
93
|
-
#### `FileSystem.
|
|
93
|
+
#### `FileSystem.getUri(filePath)`
|
|
94
94
|
|
|
95
95
|
Returns a `FileProvider` URI for the given file path. Required for sharing files with other apps on Android.
|
|
96
96
|
|
|
97
97
|
```typescript
|
|
98
|
-
static async
|
|
98
|
+
static async getUri(filePath: string): Promise<string>
|
|
99
99
|
```
|
|
100
100
|
|
|
101
101
|
```typescript
|
|
102
|
-
const uri = await FileSystem.
|
|
102
|
+
const uri = await FileSystem.getUri("/storage/emulated/0/Download/report.pdf");
|
|
103
103
|
console.log(uri); // content://...
|
|
104
104
|
```
|
|
105
105
|
|
|
@@ -120,30 +120,23 @@ const bytes: Uint8Array = new Uint8Array([0x89, 0x50, 0x4e, 0x47]);
|
|
|
120
120
|
await FileSystem.writeFile("/storage/emulated/0/Download/image.png", bytes);
|
|
121
121
|
```
|
|
122
122
|
|
|
123
|
-
#### `FileSystem.
|
|
123
|
+
#### `FileSystem.readFile(filePath)`
|
|
124
124
|
|
|
125
|
-
Reads a file
|
|
125
|
+
Reads a file. When called without an encoding argument, returns a `Bytes` (`Uint8Array`) value. When called with `"utf8"`, returns a UTF-8 string.
|
|
126
126
|
|
|
127
127
|
```typescript
|
|
128
|
-
static async
|
|
128
|
+
static async readFile(filePath: string): Promise<Bytes>
|
|
129
|
+
static async readFile(filePath: string, encoding: "utf8"): Promise<string>
|
|
129
130
|
```
|
|
130
131
|
|
|
131
132
|
```typescript
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
#### `FileSystem.readFileBytes(filePath)`
|
|
137
|
-
|
|
138
|
-
Reads a file as a `Bytes` (`Uint8Array`) value.
|
|
139
|
-
|
|
140
|
-
```typescript
|
|
141
|
-
static async readFileBytes(filePath: string): Promise<Bytes>
|
|
142
|
-
```
|
|
143
|
-
|
|
144
|
-
```typescript
|
|
145
|
-
const bytes = await FileSystem.readFileBytes("/storage/emulated/0/Download/image.png");
|
|
133
|
+
// Read as bytes
|
|
134
|
+
const bytes = await FileSystem.readFile("/storage/emulated/0/Download/image.png");
|
|
146
135
|
console.log(bytes.length);
|
|
136
|
+
|
|
137
|
+
// Read as string
|
|
138
|
+
const text = await FileSystem.readFile("/storage/emulated/0/Download/hello.txt", "utf8");
|
|
139
|
+
console.log(text);
|
|
147
140
|
```
|
|
148
141
|
|
|
149
142
|
#### `FileSystem.remove(targetPath)`
|
|
@@ -185,14 +178,14 @@ console.log(exists); // true or false
|
|
|
185
178
|
|
|
186
179
|
## Types
|
|
187
180
|
|
|
188
|
-
### `
|
|
181
|
+
### `StorageType`
|
|
189
182
|
|
|
190
183
|
Union type representing supported storage location identifiers used with `FileSystem.getStoragePath()`.
|
|
191
184
|
|
|
192
185
|
```typescript
|
|
193
|
-
import { type
|
|
186
|
+
import { type StorageType } from "@simplysm/capacitor-plugin-file-system";
|
|
194
187
|
|
|
195
|
-
type
|
|
188
|
+
type StorageType =
|
|
196
189
|
| "external"
|
|
197
190
|
| "externalFiles"
|
|
198
191
|
| "externalCache"
|
|
@@ -202,32 +195,32 @@ type TStorage =
|
|
|
202
195
|
| "appCache";
|
|
203
196
|
```
|
|
204
197
|
|
|
205
|
-
### `
|
|
198
|
+
### `FileInfo`
|
|
206
199
|
|
|
207
200
|
Represents a single entry returned by `FileSystem.readdir()`.
|
|
208
201
|
|
|
209
202
|
```typescript
|
|
210
|
-
import { type
|
|
203
|
+
import { type FileInfo } from "@simplysm/capacitor-plugin-file-system";
|
|
211
204
|
|
|
212
|
-
interface
|
|
205
|
+
interface FileInfo {
|
|
213
206
|
name: string; // File or directory name
|
|
214
207
|
isDirectory: boolean; // true if the entry is a directory
|
|
215
208
|
}
|
|
216
209
|
```
|
|
217
210
|
|
|
218
|
-
### `
|
|
211
|
+
### `FileSystemPlugin`
|
|
219
212
|
|
|
220
213
|
The low-level plugin interface registered with Capacitor. Used internally by `FileSystem`. Direct use is not required in most cases.
|
|
221
214
|
|
|
222
215
|
```typescript
|
|
223
|
-
import { type
|
|
216
|
+
import { type FileSystemPlugin } from "@simplysm/capacitor-plugin-file-system";
|
|
224
217
|
|
|
225
|
-
interface
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
readdir(options: { path: string }): Promise<{ files:
|
|
229
|
-
getStoragePath(options: { type:
|
|
230
|
-
|
|
218
|
+
interface FileSystemPlugin {
|
|
219
|
+
checkPermissions(): Promise<{ granted: boolean }>;
|
|
220
|
+
requestPermissions(): Promise<void>;
|
|
221
|
+
readdir(options: { path: string }): Promise<{ files: FileInfo[] }>;
|
|
222
|
+
getStoragePath(options: { type: StorageType }): Promise<{ path: string }>;
|
|
223
|
+
getUri(options: { path: string }): Promise<{ uri: string }>;
|
|
231
224
|
writeFile(options: { path: string; data: string; encoding?: "utf8" | "base64" }): Promise<void>;
|
|
232
225
|
readFile(options: { path: string; encoding?: "utf8" | "base64" }): Promise<{ data: string }>;
|
|
233
226
|
remove(options: { path: string }): Promise<void>;
|
|
@@ -32,7 +32,7 @@ public class FileSystemPlugin extends Plugin {
|
|
|
32
32
|
private static final int PERMISSION_REQUEST_CODE = 1001;
|
|
33
33
|
|
|
34
34
|
@PluginMethod
|
|
35
|
-
public void
|
|
35
|
+
public void checkPermissions(PluginCall call) {
|
|
36
36
|
boolean granted;
|
|
37
37
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
|
38
38
|
granted = Environment.isExternalStorageManager();
|
|
@@ -47,7 +47,7 @@ public class FileSystemPlugin extends Plugin {
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
@PluginMethod
|
|
50
|
-
public void
|
|
50
|
+
public void requestPermissions(PluginCall call) {
|
|
51
51
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
|
52
52
|
if (!Environment.isExternalStorageManager()) {
|
|
53
53
|
Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
|
|
@@ -155,7 +155,7 @@ public class FileSystemPlugin extends Plugin {
|
|
|
155
155
|
}
|
|
156
156
|
|
|
157
157
|
@PluginMethod
|
|
158
|
-
public void
|
|
158
|
+
public void getUri(PluginCall call) {
|
|
159
159
|
String path = call.getString("path");
|
|
160
160
|
if (path == null) {
|
|
161
161
|
call.reject("path is required");
|
|
@@ -169,8 +169,8 @@ public class FileSystemPlugin extends Plugin {
|
|
|
169
169
|
ret.put("uri", uri.toString());
|
|
170
170
|
call.resolve(ret);
|
|
171
171
|
} catch (Exception e) {
|
|
172
|
-
Log.e(TAG, "
|
|
173
|
-
call.reject("
|
|
172
|
+
Log.e(TAG, "getUri failed", e);
|
|
173
|
+
call.reject("getUri failed: " + e.getMessage());
|
|
174
174
|
}
|
|
175
175
|
}
|
|
176
176
|
|
package/dist/FileSystem.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { FileInfo, StorageType } from "./FileSystemPlugin";
|
|
2
2
|
import type { Bytes } from "@simplysm/core-common";
|
|
3
3
|
/**
|
|
4
4
|
* File system access plugin
|
|
@@ -10,17 +10,17 @@ export declare abstract class FileSystem {
|
|
|
10
10
|
/**
|
|
11
11
|
* Check permission
|
|
12
12
|
*/
|
|
13
|
-
static
|
|
13
|
+
static checkPermissions(): Promise<boolean>;
|
|
14
14
|
/**
|
|
15
15
|
* Request permission
|
|
16
16
|
* - Android 11+: Navigate to settings
|
|
17
17
|
* - Android 10-: Show permission dialog
|
|
18
18
|
*/
|
|
19
|
-
static
|
|
19
|
+
static requestPermissions(): Promise<void>;
|
|
20
20
|
/**
|
|
21
21
|
* Read directory
|
|
22
22
|
*/
|
|
23
|
-
static readdir(dirPath: string): Promise<
|
|
23
|
+
static readdir(dirPath: string): Promise<FileInfo[]>;
|
|
24
24
|
/**
|
|
25
25
|
* Get storage path
|
|
26
26
|
* @param type Storage type
|
|
@@ -32,23 +32,20 @@ export declare abstract class FileSystem {
|
|
|
32
32
|
* - appFiles: App files directory
|
|
33
33
|
* - appCache: App cache directory
|
|
34
34
|
*/
|
|
35
|
-
static getStoragePath(type:
|
|
35
|
+
static getStoragePath(type: StorageType): Promise<string>;
|
|
36
36
|
/**
|
|
37
37
|
* Get file URI (FileProvider)
|
|
38
38
|
*/
|
|
39
|
-
static
|
|
39
|
+
static getUri(filePath: string): Promise<string>;
|
|
40
40
|
/**
|
|
41
41
|
* Write file
|
|
42
42
|
*/
|
|
43
43
|
static writeFile(filePath: string, data: string | Bytes): Promise<void>;
|
|
44
44
|
/**
|
|
45
|
-
* Read file (
|
|
45
|
+
* Read file (default: Bytes, with encoding "utf8": string)
|
|
46
46
|
*/
|
|
47
|
-
static
|
|
48
|
-
|
|
49
|
-
* Read file (Bytes)
|
|
50
|
-
*/
|
|
51
|
-
static readFileBytes(filePath: string): Promise<Bytes>;
|
|
47
|
+
static readFile(filePath: string): Promise<Bytes>;
|
|
48
|
+
static readFile(filePath: string, encoding: "utf8"): Promise<string>;
|
|
52
49
|
/**
|
|
53
50
|
* Delete file/directory (recursive)
|
|
54
51
|
*/
|
package/dist/FileSystem.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileSystem.d.ts","sourceRoot":"","sources":["..\\src\\FileSystem.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"FileSystem.d.ts","sourceRoot":"","sources":["..\\src\\FileSystem.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAoB,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAClF,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAUnD;;;;;GAKG;AACH,8BAAsB,UAAU;IAC9B;;OAEG;WACU,gBAAgB,IAAI,OAAO,CAAC,OAAO,CAAC;IAKjD;;;;OAIG;WACU,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC;IAIhD;;OAEG;WACU,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;IAK1D;;;;;;;;;;OAUG;WACU,cAAc,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC;IAK/D;;OAEG;WACU,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAKtD;;OAEG;WACU,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC;IAiB7E;;OAEG;WACU,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;WAC1C,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAW1E;;OAEG;WACU,MAAM,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAItD;;OAEG;WACU,KAAK,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIrD;;OAEG;WACU,MAAM,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAI1D"}
|
package/dist/FileSystem.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { registerPlugin } from "@capacitor/core";
|
|
2
|
-
import {
|
|
3
|
-
const
|
|
2
|
+
import { bytes } from "@simplysm/core-common";
|
|
3
|
+
const fileSystemPlugin = registerPlugin("FileSystem", {
|
|
4
4
|
web: async () => {
|
|
5
5
|
const { FileSystemWeb } = await import("./web/FileSystemWeb");
|
|
6
6
|
return new FileSystemWeb();
|
|
@@ -10,8 +10,8 @@ class FileSystem {
|
|
|
10
10
|
/**
|
|
11
11
|
* Check permission
|
|
12
12
|
*/
|
|
13
|
-
static async
|
|
14
|
-
const result = await
|
|
13
|
+
static async checkPermissions() {
|
|
14
|
+
const result = await fileSystemPlugin.checkPermissions();
|
|
15
15
|
return result.granted;
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
@@ -19,14 +19,14 @@ class FileSystem {
|
|
|
19
19
|
* - Android 11+: Navigate to settings
|
|
20
20
|
* - Android 10-: Show permission dialog
|
|
21
21
|
*/
|
|
22
|
-
static async
|
|
23
|
-
await
|
|
22
|
+
static async requestPermissions() {
|
|
23
|
+
await fileSystemPlugin.requestPermissions();
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
26
|
* Read directory
|
|
27
27
|
*/
|
|
28
28
|
static async readdir(dirPath) {
|
|
29
|
-
const result = await
|
|
29
|
+
const result = await fileSystemPlugin.readdir({ path: dirPath });
|
|
30
30
|
return result.files;
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
@@ -41,14 +41,14 @@ class FileSystem {
|
|
|
41
41
|
* - appCache: App cache directory
|
|
42
42
|
*/
|
|
43
43
|
static async getStoragePath(type) {
|
|
44
|
-
const result = await
|
|
44
|
+
const result = await fileSystemPlugin.getStoragePath({ type });
|
|
45
45
|
return result.path;
|
|
46
46
|
}
|
|
47
47
|
/**
|
|
48
48
|
* Get file URI (FileProvider)
|
|
49
49
|
*/
|
|
50
|
-
static async
|
|
51
|
-
const result = await
|
|
50
|
+
static async getUri(filePath) {
|
|
51
|
+
const result = await fileSystemPlugin.getUri({ path: filePath });
|
|
52
52
|
return result.uri;
|
|
53
53
|
}
|
|
54
54
|
/**
|
|
@@ -56,50 +56,45 @@ class FileSystem {
|
|
|
56
56
|
*/
|
|
57
57
|
static async writeFile(filePath, data) {
|
|
58
58
|
if (typeof data !== "string") {
|
|
59
|
-
await
|
|
59
|
+
await fileSystemPlugin.writeFile({
|
|
60
60
|
path: filePath,
|
|
61
|
-
data:
|
|
61
|
+
data: bytes.toBase64(data),
|
|
62
62
|
encoding: "base64"
|
|
63
63
|
});
|
|
64
64
|
} else {
|
|
65
|
-
await
|
|
65
|
+
await fileSystemPlugin.writeFile({
|
|
66
66
|
path: filePath,
|
|
67
67
|
data,
|
|
68
68
|
encoding: "utf8"
|
|
69
69
|
});
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
* Read file (Bytes)
|
|
81
|
-
*/
|
|
82
|
-
static async readFileBytes(filePath) {
|
|
83
|
-
const result = await FileSystemPlugin.readFile({ path: filePath, encoding: "base64" });
|
|
84
|
-
return bytesFromBase64(result.data);
|
|
72
|
+
static async readFile(filePath, encoding) {
|
|
73
|
+
if (encoding === "utf8") {
|
|
74
|
+
const result = await fileSystemPlugin.readFile({ path: filePath, encoding: "utf8" });
|
|
75
|
+
return result.data;
|
|
76
|
+
} else {
|
|
77
|
+
const result = await fileSystemPlugin.readFile({ path: filePath, encoding: "base64" });
|
|
78
|
+
return bytes.fromBase64(result.data);
|
|
79
|
+
}
|
|
85
80
|
}
|
|
86
81
|
/**
|
|
87
82
|
* Delete file/directory (recursive)
|
|
88
83
|
*/
|
|
89
84
|
static async remove(targetPath) {
|
|
90
|
-
await
|
|
85
|
+
await fileSystemPlugin.remove({ path: targetPath });
|
|
91
86
|
}
|
|
92
87
|
/**
|
|
93
88
|
* Create directory (recursive)
|
|
94
89
|
*/
|
|
95
90
|
static async mkdir(targetPath) {
|
|
96
|
-
await
|
|
91
|
+
await fileSystemPlugin.mkdir({ path: targetPath });
|
|
97
92
|
}
|
|
98
93
|
/**
|
|
99
94
|
* Check existence
|
|
100
95
|
*/
|
|
101
96
|
static async exists(targetPath) {
|
|
102
|
-
const result = await
|
|
97
|
+
const result = await fileSystemPlugin.exists({ path: targetPath });
|
|
103
98
|
return result.exists;
|
|
104
99
|
}
|
|
105
100
|
}
|
package/dist/FileSystem.js.map
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/FileSystem.ts"],
|
|
4
|
-
"mappings": "AAAA,SAAS,sBAAsB;AAG/B,SAAS,
|
|
4
|
+
"mappings": "AAAA,SAAS,sBAAsB;AAG/B,SAAS,aAAa;AAEtB,MAAM,mBAAmB,eAAiC,cAAc;AAAA,EACtE,KAAK,YAAY;AACf,UAAM,EAAE,cAAc,IAAI,MAAM,OAAO,qBAAqB;AAC5D,WAAO,IAAI,cAAc;AAAA,EAC3B;AACF,CAAC;AAQM,MAAe,WAAW;AAAA;AAAA;AAAA;AAAA,EAI/B,aAAa,mBAAqC;AAChD,UAAM,SAAS,MAAM,iBAAiB,iBAAiB;AACvD,WAAO,OAAO;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,aAAa,qBAAoC;AAC/C,UAAM,iBAAiB,mBAAmB;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA,EAKA,aAAa,QAAQ,SAAsC;AACzD,UAAM,SAAS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MAAM,EAAE,MAAM,WAAW,CAAC;AAAA,EACnD;AAAA;AAAA;AAAA;AAAA,EAKA,aAAa,OAAO,YAAsC;AACxD,UAAM,SAAS,MAAM,iBAAiB,OAAO,EAAE,MAAM,WAAW,CAAC;AACjE,WAAO,OAAO;AAAA,EAChB;AACF;",
|
|
5
5
|
"names": []
|
|
6
6
|
}
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
export type
|
|
2
|
-
export interface
|
|
1
|
+
export type StorageType = "external" | "externalFiles" | "externalCache" | "externalMedia" | "appData" | "appFiles" | "appCache";
|
|
2
|
+
export interface FileInfo {
|
|
3
3
|
name: string;
|
|
4
4
|
isDirectory: boolean;
|
|
5
5
|
}
|
|
6
|
-
export interface
|
|
7
|
-
|
|
6
|
+
export interface FileSystemPlugin {
|
|
7
|
+
checkPermissions(): Promise<{
|
|
8
8
|
granted: boolean;
|
|
9
9
|
}>;
|
|
10
|
-
|
|
10
|
+
requestPermissions(): Promise<void>;
|
|
11
11
|
readdir(options: {
|
|
12
12
|
path: string;
|
|
13
13
|
}): Promise<{
|
|
14
|
-
files:
|
|
14
|
+
files: FileInfo[];
|
|
15
15
|
}>;
|
|
16
16
|
getStoragePath(options: {
|
|
17
|
-
type:
|
|
17
|
+
type: StorageType;
|
|
18
18
|
}): Promise<{
|
|
19
19
|
path: string;
|
|
20
20
|
}>;
|
|
21
|
-
|
|
21
|
+
getUri(options: {
|
|
22
22
|
path: string;
|
|
23
23
|
}): Promise<{
|
|
24
24
|
uri: string;
|
|
@@ -46,4 +46,4 @@ export interface IFileSystemPlugin {
|
|
|
46
46
|
exists: boolean;
|
|
47
47
|
}>;
|
|
48
48
|
}
|
|
49
|
-
//# sourceMappingURL=
|
|
49
|
+
//# sourceMappingURL=FileSystemPlugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FileSystemPlugin.d.ts","sourceRoot":"","sources":["..\\src\\FileSystemPlugin.ts"],"names":[],"mappings":"AAAA,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KAAK,CAAC,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAChD,MAAM,CAAC,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC;QAAE,MAAM,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;CACjE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=FileSystemPlugin.js.map
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["..\\src\\index.ts"],"names":[],"mappings":"AACA,cAAc,cAAc,CAAC;AAC7B,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["..\\src\\index.ts"],"names":[],"mappings":"AACA,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { WebPlugin } from "@capacitor/core";
|
|
2
|
-
import type {
|
|
3
|
-
export declare class FileSystemWeb extends WebPlugin implements
|
|
2
|
+
import type { FileInfo, FileSystemPlugin, StorageType } from "../FileSystemPlugin";
|
|
3
|
+
export declare class FileSystemWeb extends WebPlugin implements FileSystemPlugin {
|
|
4
4
|
private readonly _fs;
|
|
5
5
|
private readonly _textEncoder;
|
|
6
6
|
private readonly _textDecoder;
|
|
7
|
-
|
|
7
|
+
checkPermissions(): Promise<{
|
|
8
8
|
granted: boolean;
|
|
9
9
|
}>;
|
|
10
|
-
|
|
10
|
+
requestPermissions(): Promise<void>;
|
|
11
11
|
readdir(options: {
|
|
12
12
|
path: string;
|
|
13
13
|
}): Promise<{
|
|
14
|
-
files:
|
|
14
|
+
files: FileInfo[];
|
|
15
15
|
}>;
|
|
16
16
|
getStoragePath(options: {
|
|
17
|
-
type:
|
|
17
|
+
type: StorageType;
|
|
18
18
|
}): Promise<{
|
|
19
19
|
path: string;
|
|
20
20
|
}>;
|
|
@@ -23,7 +23,7 @@ export declare class FileSystemWeb extends WebPlugin implements IFileSystemPlugi
|
|
|
23
23
|
* @warning The returned URI must be released by calling `URL.revokeObjectURL(uri)` after use.
|
|
24
24
|
* Failure to release may cause memory leaks.
|
|
25
25
|
*/
|
|
26
|
-
|
|
26
|
+
getUri(options: {
|
|
27
27
|
path: string;
|
|
28
28
|
}): Promise<{
|
|
29
29
|
uri: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileSystemWeb.d.ts","sourceRoot":"","sources":["..\\..\\src\\web\\FileSystemWeb.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"FileSystemWeb.d.ts","sourceRoot":"","sources":["..\\..\\src\\web\\FileSystemWeb.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAInF,qBAAa,aAAc,SAAQ,SAAU,YAAW,gBAAgB;IACtE,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAqD;IACzE,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAqB;IAClD,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAqB;IAE5C,gBAAgB,IAAI,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC;IAIjD,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC;IAEnC,OAAO,CAAC,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC;QAAE,KAAK,EAAE,QAAQ,EAAE,CAAA;KAAE,CAAC;IASlE,cAAc,CAAC,OAAO,EAAE;QAAE,IAAI,EAAE,WAAW,CAAA;KAAE,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IAM/E;;;;OAIG;IACG,MAAM,CAAC,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC;IAU3D,SAAS,CAAC,OAAO,EAAE;QACvB,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,CAAC,EAAE,MAAM,GAAG,QAAQ,CAAC;KAC9B,GAAG,OAAO,CAAC,IAAI,CAAC;IAWX,QAAQ,CAAC,OAAO,EAAE;QACtB,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,CAAC,EAAE,MAAM,GAAG,QAAQ,CAAC;KAC9B,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IAYvB,MAAM,CAAC,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAOhD,KAAK,CAAC,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAI/C,MAAM,CAAC,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC;QAAE,MAAM,EAAE,OAAO,CAAA;KAAE,CAAC;CAItE"}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { WebPlugin } from "@capacitor/core";
|
|
2
2
|
import { VirtualFileSystem } from "./VirtualFileSystem.js";
|
|
3
|
-
import {
|
|
3
|
+
import { bytes } from "@simplysm/core-common";
|
|
4
4
|
class FileSystemWeb extends WebPlugin {
|
|
5
5
|
_fs = new VirtualFileSystem("capacitor_web_virtual_fs");
|
|
6
6
|
_textEncoder = new TextEncoder();
|
|
7
7
|
_textDecoder = new TextDecoder();
|
|
8
|
-
async
|
|
8
|
+
async checkPermissions() {
|
|
9
9
|
return Promise.resolve({ granted: true });
|
|
10
10
|
}
|
|
11
|
-
async
|
|
11
|
+
async requestPermissions() {
|
|
12
12
|
}
|
|
13
13
|
async readdir(options) {
|
|
14
14
|
const entry = await this._fs.getEntry(options.path);
|
|
@@ -19,33 +19,7 @@ class FileSystemWeb extends WebPlugin {
|
|
|
19
19
|
return { files };
|
|
20
20
|
}
|
|
21
21
|
async getStoragePath(options) {
|
|
22
|
-
const
|
|
23
|
-
let storagePath;
|
|
24
|
-
switch (options.type) {
|
|
25
|
-
case "external":
|
|
26
|
-
storagePath = base + "/external";
|
|
27
|
-
break;
|
|
28
|
-
case "externalFiles":
|
|
29
|
-
storagePath = base + "/externalFiles";
|
|
30
|
-
break;
|
|
31
|
-
case "externalCache":
|
|
32
|
-
storagePath = base + "/externalCache";
|
|
33
|
-
break;
|
|
34
|
-
case "externalMedia":
|
|
35
|
-
storagePath = base + "/externalMedia";
|
|
36
|
-
break;
|
|
37
|
-
case "appData":
|
|
38
|
-
storagePath = base + "/appData";
|
|
39
|
-
break;
|
|
40
|
-
case "appFiles":
|
|
41
|
-
storagePath = base + "/appFiles";
|
|
42
|
-
break;
|
|
43
|
-
case "appCache":
|
|
44
|
-
storagePath = base + "/appCache";
|
|
45
|
-
break;
|
|
46
|
-
default:
|
|
47
|
-
throw new Error("Unknown storage type: " + options.type);
|
|
48
|
-
}
|
|
22
|
+
const storagePath = "/webfs/" + options.type;
|
|
49
23
|
await this._fs.ensureDir(storagePath);
|
|
50
24
|
return { path: storagePath };
|
|
51
25
|
}
|
|
@@ -54,20 +28,20 @@ class FileSystemWeb extends WebPlugin {
|
|
|
54
28
|
* @warning The returned URI must be released by calling `URL.revokeObjectURL(uri)` after use.
|
|
55
29
|
* Failure to release may cause memory leaks.
|
|
56
30
|
*/
|
|
57
|
-
async
|
|
31
|
+
async getUri(options) {
|
|
58
32
|
const entry = await this._fs.getEntry(options.path);
|
|
59
33
|
if (!entry || entry.kind !== "file" || entry.dataBase64 == null) {
|
|
60
34
|
throw new Error("File not found: " + options.path);
|
|
61
35
|
}
|
|
62
|
-
const
|
|
63
|
-
const blob = new Blob([
|
|
36
|
+
const data = bytes.fromBase64(entry.dataBase64);
|
|
37
|
+
const blob = new Blob([data]);
|
|
64
38
|
return { uri: URL.createObjectURL(blob) };
|
|
65
39
|
}
|
|
66
40
|
async writeFile(options) {
|
|
67
41
|
const idx = options.path.lastIndexOf("/");
|
|
68
42
|
const dir = idx === -1 ? "." : options.path.substring(0, idx) || "/";
|
|
69
43
|
await this._fs.ensureDir(dir);
|
|
70
|
-
const dataBase64 = options.encoding === "base64" ? options.data :
|
|
44
|
+
const dataBase64 = options.encoding === "base64" ? options.data : bytes.toBase64(this._textEncoder.encode(options.data));
|
|
71
45
|
await this._fs.putEntry({ path: options.path, kind: "file", dataBase64 });
|
|
72
46
|
}
|
|
73
47
|
async readFile(options) {
|
|
@@ -75,7 +49,7 @@ class FileSystemWeb extends WebPlugin {
|
|
|
75
49
|
if (!entry || entry.kind !== "file" || entry.dataBase64 == null) {
|
|
76
50
|
throw new Error("File not found: " + options.path);
|
|
77
51
|
}
|
|
78
|
-
const data = options.encoding === "base64" ? entry.dataBase64 : this._textDecoder.decode(
|
|
52
|
+
const data = options.encoding === "base64" ? entry.dataBase64 : this._textDecoder.decode(bytes.fromBase64(entry.dataBase64));
|
|
79
53
|
return { data };
|
|
80
54
|
}
|
|
81
55
|
async remove(options) {
|