@simplysm/capacitor-plugin-file-system 13.0.71 → 13.0.74

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.
Files changed (2) hide show
  1. package/README.md +224 -9
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -4,19 +4,234 @@ Simplysm Package - Capacitor File System Plugin
4
4
 
5
5
  ## Installation
6
6
 
7
+ ```bash
7
8
  pnpm add @simplysm/capacitor-plugin-file-system
9
+ ```
8
10
 
9
- **Peer Dependencies:** `@capacitor/core ^7.4.4`
11
+ ## Main Modules
10
12
 
11
- ## Source Index
13
+ ### FileSystem
12
14
 
13
- ### File System
15
+ An abstract class that provides static methods for file system access via the Capacitor plugin bridge.
14
16
 
15
- | Source | Exports | Description | Test |
16
- |--------|---------|-------------|------|
17
- | `src/FileSystem.ts` | `FileSystem` | Static class for file read/write, directory, permission, and URI operations | - |
18
- | `src/IFileSystemPlugin.ts` | `TStorage`, `IFileInfo`, `IFileSystemPlugin` | Types and interface for storage paths, file info, and the native plugin contract | - |
17
+ - **Android 11+**: Full file system access via `MANAGE_EXTERNAL_STORAGE` permission.
18
+ - **Android 10 and below**: `READ_EXTERNAL_STORAGE` / `WRITE_EXTERNAL_STORAGE` permission.
19
+ - **Browser**: IndexedDB-based emulation.
19
20
 
20
- ## License
21
+ ```typescript
22
+ import { FileSystem } from "@simplysm/capacitor-plugin-file-system";
23
+ ```
21
24
 
22
- Apache-2.0
25
+ #### `FileSystem.hasPermission()`
26
+
27
+ Checks whether the required file system permission has been granted.
28
+
29
+ ```typescript
30
+ static async hasPermission(): Promise<boolean>
31
+ ```
32
+
33
+ ```typescript
34
+ const granted = await FileSystem.hasPermission();
35
+ if (!granted) {
36
+ await FileSystem.requestPermission();
37
+ }
38
+ ```
39
+
40
+ #### `FileSystem.requestPermission()`
41
+
42
+ Requests the required file system permission.
43
+
44
+ - Android 11+: Navigates to the system settings page.
45
+ - Android 10 and below: Shows the OS permission dialog.
46
+
47
+ ```typescript
48
+ static async requestPermission(): Promise<void>
49
+ ```
50
+
51
+ ```typescript
52
+ await FileSystem.requestPermission();
53
+ ```
54
+
55
+ #### `FileSystem.readdir(dirPath)`
56
+
57
+ Reads the contents of a directory and returns an array of `IFileInfo` objects.
58
+
59
+ ```typescript
60
+ static async readdir(dirPath: string): Promise<IFileInfo[]>
61
+ ```
62
+
63
+ ```typescript
64
+ const entries = await FileSystem.readdir("/storage/emulated/0/Download");
65
+ for (const entry of entries) {
66
+ console.log(entry.name, entry.isDirectory);
67
+ }
68
+ ```
69
+
70
+ #### `FileSystem.getStoragePath(type)`
71
+
72
+ Returns the absolute path for the given storage type.
73
+
74
+ ```typescript
75
+ static async getStoragePath(type: TStorage): Promise<string>
76
+ ```
77
+
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
+
88
+ ```typescript
89
+ const path = await FileSystem.getStoragePath("external");
90
+ console.log(path); // e.g. "/storage/emulated/0"
91
+ ```
92
+
93
+ #### `FileSystem.getFileUri(filePath)`
94
+
95
+ Returns a `FileProvider` URI for the given file path. Required for sharing files with other apps on Android.
96
+
97
+ ```typescript
98
+ static async getFileUri(filePath: string): Promise<string>
99
+ ```
100
+
101
+ ```typescript
102
+ const uri = await FileSystem.getFileUri("/storage/emulated/0/Download/report.pdf");
103
+ console.log(uri); // content://...
104
+ ```
105
+
106
+ #### `FileSystem.writeFile(filePath, data)`
107
+
108
+ Writes data to a file. Accepts a UTF-8 string or a `Bytes` (`Uint8Array`) value. Strings are written with UTF-8 encoding; byte arrays are written with Base64 encoding.
109
+
110
+ ```typescript
111
+ static async writeFile(filePath: string, data: string | Bytes): Promise<void>
112
+ ```
113
+
114
+ ```typescript
115
+ // Write text
116
+ await FileSystem.writeFile("/storage/emulated/0/Download/hello.txt", "Hello, world!");
117
+
118
+ // Write binary
119
+ const bytes: Uint8Array = new Uint8Array([0x89, 0x50, 0x4e, 0x47]);
120
+ await FileSystem.writeFile("/storage/emulated/0/Download/image.png", bytes);
121
+ ```
122
+
123
+ #### `FileSystem.readFileString(filePath)`
124
+
125
+ Reads a file as a UTF-8 string.
126
+
127
+ ```typescript
128
+ static async readFileString(filePath: string): Promise<string>
129
+ ```
130
+
131
+ ```typescript
132
+ const text = await FileSystem.readFileString("/storage/emulated/0/Download/hello.txt");
133
+ console.log(text);
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");
146
+ console.log(bytes.length);
147
+ ```
148
+
149
+ #### `FileSystem.remove(targetPath)`
150
+
151
+ Deletes a file or directory recursively.
152
+
153
+ ```typescript
154
+ static async remove(targetPath: string): Promise<void>
155
+ ```
156
+
157
+ ```typescript
158
+ await FileSystem.remove("/storage/emulated/0/Download/old-folder");
159
+ ```
160
+
161
+ #### `FileSystem.mkdir(targetPath)`
162
+
163
+ Creates a directory, including any intermediate directories (recursive).
164
+
165
+ ```typescript
166
+ static async mkdir(targetPath: string): Promise<void>
167
+ ```
168
+
169
+ ```typescript
170
+ await FileSystem.mkdir("/storage/emulated/0/Download/new-folder/sub");
171
+ ```
172
+
173
+ #### `FileSystem.exists(targetPath)`
174
+
175
+ Checks whether a file or directory exists at the given path.
176
+
177
+ ```typescript
178
+ static async exists(targetPath: string): Promise<boolean>
179
+ ```
180
+
181
+ ```typescript
182
+ const exists = await FileSystem.exists("/storage/emulated/0/Download/report.pdf");
183
+ console.log(exists); // true or false
184
+ ```
185
+
186
+ ## Types
187
+
188
+ ### `TStorage`
189
+
190
+ Union type representing supported storage location identifiers used with `FileSystem.getStoragePath()`.
191
+
192
+ ```typescript
193
+ import { type TStorage } from "@simplysm/capacitor-plugin-file-system";
194
+
195
+ type TStorage =
196
+ | "external"
197
+ | "externalFiles"
198
+ | "externalCache"
199
+ | "externalMedia"
200
+ | "appData"
201
+ | "appFiles"
202
+ | "appCache";
203
+ ```
204
+
205
+ ### `IFileInfo`
206
+
207
+ Represents a single entry returned by `FileSystem.readdir()`.
208
+
209
+ ```typescript
210
+ import { type IFileInfo } from "@simplysm/capacitor-plugin-file-system";
211
+
212
+ interface IFileInfo {
213
+ name: string; // File or directory name
214
+ isDirectory: boolean; // true if the entry is a directory
215
+ }
216
+ ```
217
+
218
+ ### `IFileSystemPlugin`
219
+
220
+ The low-level plugin interface registered with Capacitor. Used internally by `FileSystem`. Direct use is not required in most cases.
221
+
222
+ ```typescript
223
+ import { type IFileSystemPlugin } from "@simplysm/capacitor-plugin-file-system";
224
+
225
+ interface IFileSystemPlugin {
226
+ hasPermission(): Promise<{ granted: boolean }>;
227
+ requestPermission(): Promise<void>;
228
+ readdir(options: { path: string }): Promise<{ files: IFileInfo[] }>;
229
+ getStoragePath(options: { type: TStorage }): Promise<{ path: string }>;
230
+ getFileUri(options: { path: string }): Promise<{ uri: string }>;
231
+ writeFile(options: { path: string; data: string; encoding?: "utf8" | "base64" }): Promise<void>;
232
+ readFile(options: { path: string; encoding?: "utf8" | "base64" }): Promise<{ data: string }>;
233
+ remove(options: { path: string }): Promise<void>;
234
+ mkdir(options: { path: string }): Promise<void>;
235
+ exists(options: { path: string }): Promise<{ exists: boolean }>;
236
+ }
237
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simplysm/capacitor-plugin-file-system",
3
- "version": "13.0.71",
3
+ "version": "13.0.74",
4
4
  "description": "Simplysm Package - Capacitor File System Plugin",
5
5
  "author": "simplysm",
6
6
  "license": "MIT",
@@ -18,7 +18,7 @@
18
18
  "android"
19
19
  ],
20
20
  "dependencies": {
21
- "@simplysm/core-common": "13.0.71"
21
+ "@simplysm/core-common": "13.0.74"
22
22
  },
23
23
  "devDependencies": {
24
24
  "@capacitor/core": "^7.5.0"