@simplysm/capacitor-plugin-file-system 13.0.97 → 13.0.98
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 +132 -0
- package/package.json +3 -3
package/README.md
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# @simplysm/capacitor-plugin-file-system
|
|
2
|
+
|
|
3
|
+
Capacitor File System Plugin -- full file system access for Android with IndexedDB fallback for browser.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @simplysm/capacitor-plugin-file-system
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## API Overview
|
|
12
|
+
|
|
13
|
+
### Types
|
|
14
|
+
|
|
15
|
+
| API | Type | Description |
|
|
16
|
+
|-----|------|-------------|
|
|
17
|
+
| `StorageType` | type | Storage location type (`"external"`, `"externalFiles"`, `"externalCache"`, `"externalMedia"`, `"appData"`, `"appFiles"`, `"appCache"`) |
|
|
18
|
+
| `FileInfo` | interface | File entry info (`name`, `isDirectory`) |
|
|
19
|
+
|
|
20
|
+
### Interfaces
|
|
21
|
+
|
|
22
|
+
| API | Type | Description |
|
|
23
|
+
|-----|------|-------------|
|
|
24
|
+
| `FileSystemPlugin` | interface | Low-level Capacitor plugin interface for file system operations |
|
|
25
|
+
|
|
26
|
+
### Classes
|
|
27
|
+
|
|
28
|
+
| API | Type | Description |
|
|
29
|
+
|-----|------|-------------|
|
|
30
|
+
| `FileSystem` | abstract class | File system access with permission management |
|
|
31
|
+
|
|
32
|
+
## `StorageType`
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
type StorageType =
|
|
36
|
+
| "external"
|
|
37
|
+
| "externalFiles"
|
|
38
|
+
| "externalCache"
|
|
39
|
+
| "externalMedia"
|
|
40
|
+
| "appData"
|
|
41
|
+
| "appFiles"
|
|
42
|
+
| "appCache";
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## `FileInfo`
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
interface FileInfo {
|
|
49
|
+
name: string;
|
|
50
|
+
isDirectory: boolean;
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## `FileSystemPlugin`
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
interface FileSystemPlugin {
|
|
58
|
+
checkPermissions(): Promise<{ granted: boolean }>;
|
|
59
|
+
requestPermissions(): Promise<void>;
|
|
60
|
+
readdir(options: { path: string }): Promise<{ files: FileInfo[] }>;
|
|
61
|
+
getStoragePath(options: { type: StorageType }): Promise<{ path: string }>;
|
|
62
|
+
getUri(options: { path: string }): Promise<{ uri: string }>;
|
|
63
|
+
writeFile(options: { path: string; data: string; encoding?: "utf8" | "base64" }): Promise<void>;
|
|
64
|
+
readFile(options: { path: string; encoding?: "utf8" | "base64" }): Promise<{ data: string }>;
|
|
65
|
+
remove(options: { path: string }): Promise<void>;
|
|
66
|
+
mkdir(options: { path: string }): Promise<void>;
|
|
67
|
+
exists(options: { path: string }): Promise<{ exists: boolean }>;
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Low-level Capacitor plugin interface. Use `FileSystem` static methods instead of calling this directly.
|
|
72
|
+
|
|
73
|
+
## `FileSystem`
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
abstract class FileSystem {
|
|
77
|
+
static async checkPermissions(): Promise<boolean>;
|
|
78
|
+
static async requestPermissions(): Promise<void>;
|
|
79
|
+
static async readdir(dirPath: string): Promise<FileInfo[]>;
|
|
80
|
+
static async getStoragePath(type: StorageType): Promise<string>;
|
|
81
|
+
static async getUri(filePath: string): Promise<string>;
|
|
82
|
+
static async writeFile(filePath: string, data: string | Bytes): Promise<void>;
|
|
83
|
+
static async readFile(filePath: string): Promise<Bytes>;
|
|
84
|
+
static async readFile(filePath: string, encoding: "utf8"): Promise<string>;
|
|
85
|
+
static async remove(targetPath: string): Promise<void>;
|
|
86
|
+
static async mkdir(targetPath: string): Promise<void>;
|
|
87
|
+
static async exists(targetPath: string): Promise<boolean>;
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
File system access plugin.
|
|
92
|
+
- Android 11+: Full file system access via `MANAGE_EXTERNAL_STORAGE` permission.
|
|
93
|
+
- Android 10-: `READ/WRITE_EXTERNAL_STORAGE` permission.
|
|
94
|
+
- Browser: IndexedDB-based emulation.
|
|
95
|
+
|
|
96
|
+
## Usage Examples
|
|
97
|
+
|
|
98
|
+
### Read and write files
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
import { FileSystem } from "@simplysm/capacitor-plugin-file-system";
|
|
102
|
+
|
|
103
|
+
const storagePath = await FileSystem.getStoragePath("appFiles");
|
|
104
|
+
const filePath = storagePath + "/data.txt";
|
|
105
|
+
|
|
106
|
+
await FileSystem.writeFile(filePath, "Hello, World!");
|
|
107
|
+
const content = await FileSystem.readFile(filePath, "utf8");
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### List directory contents
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
import { FileSystem } from "@simplysm/capacitor-plugin-file-system";
|
|
114
|
+
|
|
115
|
+
const granted = await FileSystem.checkPermissions();
|
|
116
|
+
if (!granted) {
|
|
117
|
+
await FileSystem.requestPermissions();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const externalPath = await FileSystem.getStoragePath("external");
|
|
121
|
+
const files = await FileSystem.readdir(externalPath + "/Documents");
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Write binary data
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
127
|
+
import { FileSystem } from "@simplysm/capacitor-plugin-file-system";
|
|
128
|
+
|
|
129
|
+
const storagePath = await FileSystem.getStoragePath("appCache");
|
|
130
|
+
await FileSystem.writeFile(storagePath + "/image.bin", myUint8Array);
|
|
131
|
+
const data = await FileSystem.readFile(storagePath + "/image.bin");
|
|
132
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simplysm/capacitor-plugin-file-system",
|
|
3
|
-
"version": "13.0.
|
|
3
|
+
"version": "13.0.98",
|
|
4
4
|
"description": "Simplysm Package - Capacitor File System Plugin",
|
|
5
5
|
"author": "simplysm",
|
|
6
6
|
"license": "MIT",
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
"android"
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@simplysm/core-browser": "13.0.
|
|
22
|
-
"@simplysm/core-common": "13.0.
|
|
21
|
+
"@simplysm/core-browser": "13.0.98",
|
|
22
|
+
"@simplysm/core-common": "13.0.98"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@capacitor/core": "^7.6.0"
|