@simplysm/capacitor-plugin-file-system 14.0.4 → 14.0.5

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 +94 -43
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # @simplysm/capacitor-plugin-file-system
2
2
 
3
- Capacitor file system plugin with full storage access on Android 11+.
3
+ Capacitor plugin for file system access on Android with an IndexedDB-based fallback for browsers.
4
+
5
+ - **Android 11+**: Full file system access via `MANAGE_EXTERNAL_STORAGE` permission
6
+ - **Android 10-**: `READ/WRITE_EXTERNAL_STORAGE` permissions
7
+ - **Browser**: IndexedDB-based emulation
4
8
 
5
9
  ## Installation
6
10
 
@@ -10,26 +14,43 @@ npm install @simplysm/capacitor-plugin-file-system
10
14
 
11
15
  ## API Overview
12
16
 
13
- ### File System
17
+ ### Types
14
18
 
15
19
  | API | Type | Description |
16
20
  |-----|------|-------------|
17
21
  | `StorageType` | Type | Union of supported Android storage location identifiers |
22
+
23
+ ### Interfaces
24
+
25
+ | API | Type | Description |
26
+ |-----|------|-------------|
18
27
  | `FileInfo` | Interface | File entry metadata returned by directory listing |
19
28
  | `FileSystemPlugin` | Interface | Native plugin interface for file system operations |
29
+
30
+ ### Classes
31
+
32
+ | API | Type | Description |
33
+ |-----|------|-------------|
20
34
  | `FileSystem` | Class | Static API for file system access with permission management |
21
35
 
22
- ## Types
36
+ ## `StorageType`
23
37
 
24
- ### StorageType
38
+ Union type representing available storage location types.
25
39
 
26
- ```ts
27
- type StorageType = "external" | "externalFiles" | "externalCache" | "externalMedia" | "appData" | "appFiles" | "appCache";
40
+ ```typescript
41
+ type StorageType =
42
+ | "external"
43
+ | "externalFiles"
44
+ | "externalCache"
45
+ | "externalMedia"
46
+ | "appData"
47
+ | "appFiles"
48
+ | "appCache";
28
49
  ```
29
50
 
30
51
  | Value | Description |
31
52
  |-------|-------------|
32
- | `"external"` | Shared external storage root |
53
+ | `"external"` | Shared external storage root (`Environment.getExternalStorageDirectory`) |
33
54
  | `"externalFiles"` | App-specific external files directory |
34
55
  | `"externalCache"` | App-specific external cache directory |
35
56
  | `"externalMedia"` | App-specific external media directory |
@@ -37,20 +58,40 @@ type StorageType = "external" | "externalFiles" | "externalCache" | "externalMed
37
58
  | `"appFiles"` | Internal app files directory |
38
59
  | `"appCache"` | Internal app cache directory |
39
60
 
40
- ## Interfaces
41
-
42
- ### FileInfo
61
+ ## `FileInfo`
43
62
 
44
63
  Metadata for a single file or directory entry.
45
64
 
65
+ ```typescript
66
+ interface FileInfo {
67
+ name: string;
68
+ isDirectory: boolean;
69
+ }
70
+ ```
71
+
46
72
  | Field | Type | Description |
47
73
  |-------|------|-------------|
48
74
  | `name` | `string` | Name of the file or directory |
49
75
  | `isDirectory` | `boolean` | `true` if the entry is a directory |
50
76
 
51
- ### FileSystemPlugin
52
-
53
- Native plugin interface for file system operations.
77
+ ## `FileSystemPlugin`
78
+
79
+ Native plugin interface for file system operations. Use the `FileSystem` class for a simplified API.
80
+
81
+ ```typescript
82
+ interface FileSystemPlugin {
83
+ checkPermissions(): Promise<{ granted: boolean }>;
84
+ requestPermissions(): Promise<void>;
85
+ readdir(options: { path: string }): Promise<{ files: FileInfo[] }>;
86
+ getStoragePath(options: { type: StorageType }): Promise<{ path: string }>;
87
+ getUri(options: { path: string }): Promise<{ uri: string }>;
88
+ writeFile(options: { path: string; data: string; encoding?: "utf8" | "base64" }): Promise<void>;
89
+ readFile(options: { path: string; encoding?: "utf8" | "base64" }): Promise<{ data: string }>;
90
+ remove(options: { path: string }): Promise<void>;
91
+ mkdir(options: { path: string }): Promise<void>;
92
+ exists(options: { path: string }): Promise<{ exists: boolean }>;
93
+ }
94
+ ```
54
95
 
55
96
  | Method | Signature | Description |
56
97
  |--------|-----------|-------------|
@@ -58,28 +99,40 @@ Native plugin interface for file system operations.
58
99
  | `requestPermissions` | `() => Promise<void>` | Request storage permissions |
59
100
  | `readdir` | `(options: { path: string }) => Promise<{ files: FileInfo[] }>` | List files in a directory |
60
101
  | `getStoragePath` | `(options: { type: StorageType }) => Promise<{ path: string }>` | Get the absolute path for a storage type |
61
- | `getUri` | `(options: { path: string }) => Promise<{ uri: string }>` | Get a FileProvider content URI for a file path |
102
+ | `getUri` | `(options: { path: string }) => Promise<{ uri: string }>` | Get a FileProvider `content://` URI for a file path |
62
103
  | `writeFile` | `(options: { path: string; data: string; encoding?: "utf8" \| "base64" }) => Promise<void>` | Write data to a file |
63
104
  | `readFile` | `(options: { path: string; encoding?: "utf8" \| "base64" }) => Promise<{ data: string }>` | Read data from a file |
64
105
  | `remove` | `(options: { path: string }) => Promise<void>` | Remove a file or directory |
65
106
  | `mkdir` | `(options: { path: string }) => Promise<void>` | Create a directory |
66
107
  | `exists` | `(options: { path: string }) => Promise<{ exists: boolean }>` | Check if a path exists |
67
108
 
68
- ## Classes
69
-
70
- ### FileSystem
71
-
72
- File system access plugin. On Android 11+ it uses `MANAGE_EXTERNAL_STORAGE`. On Android 10 and below it uses `READ_EXTERNAL_STORAGE` / `WRITE_EXTERNAL_STORAGE`. On the browser it falls back to IndexedDB emulation.
73
-
74
- All methods are static.
109
+ ## `FileSystem`
110
+
111
+ Abstract class with static methods for file system operations. On Android 11+ it uses `MANAGE_EXTERNAL_STORAGE`. On Android 10 and below it uses `READ_EXTERNAL_STORAGE` / `WRITE_EXTERNAL_STORAGE`. On the browser it falls back to IndexedDB emulation.
112
+
113
+ ```typescript
114
+ abstract class FileSystem {
115
+ static async checkPermissions(): Promise<boolean>;
116
+ static async requestPermissions(): Promise<void>;
117
+ static async readdir(dirPath: string): Promise<FileInfo[]>;
118
+ static async getStoragePath(type: StorageType): Promise<string>;
119
+ static async getUri(filePath: string): Promise<string>;
120
+ static async writeFile(filePath: string, data: string | Bytes): Promise<void>;
121
+ static async readFile(filePath: string): Promise<Bytes>;
122
+ static async readFile(filePath: string, encoding: "utf8"): Promise<string>;
123
+ static async remove(targetPath: string): Promise<void>;
124
+ static async mkdir(targetPath: string): Promise<void>;
125
+ static async exists(targetPath: string): Promise<boolean>;
126
+ }
127
+ ```
75
128
 
76
129
  | Method | Signature | Description |
77
130
  |--------|-----------|-------------|
78
131
  | `checkPermissions` | `static async checkPermissions(): Promise<boolean>` | Check whether storage permissions are granted |
79
132
  | `requestPermissions` | `static async requestPermissions(): Promise<void>` | Request storage permissions from the user |
80
133
  | `readdir` | `static async readdir(dirPath: string): Promise<FileInfo[]>` | List files and directories at the given path |
81
- | `getStoragePath` | `static async getStoragePath(type: StorageType): Promise<string>` | Get the absolute path for a storage type (`external`, `externalFiles`, `externalCache`, `externalMedia`, `appData`, `appFiles`, `appCache`) |
82
- | `getUri` | `static async getUri(filePath: string): Promise<string>` | Get a FileProvider content URI for the given file path |
134
+ | `getStoragePath` | `static async getStoragePath(type: StorageType): Promise<string>` | Get the absolute path for a storage type |
135
+ | `getUri` | `static async getUri(filePath: string): Promise<string>` | Get a FileProvider `content://` URI for the given file path |
83
136
  | `writeFile` | `static async writeFile(filePath: string, data: string \| Bytes): Promise<void>` | Write string or binary data to a file. Binary data (`Bytes`) is automatically base64-encoded. |
84
137
  | `readFile` | `static async readFile(filePath: string): Promise<Bytes>` | Read a file as binary data |
85
138
  | `readFile` (overload) | `static async readFile(filePath: string, encoding: "utf8"): Promise<string>` | Read a file as a UTF-8 string |
@@ -91,7 +144,7 @@ All methods are static.
91
144
 
92
145
  ### Read and write files
93
146
 
94
- ```ts
147
+ ```typescript
95
148
  import { FileSystem } from "@simplysm/capacitor-plugin-file-system";
96
149
 
97
150
  // Ensure permissions
@@ -100,34 +153,32 @@ if (!granted) {
100
153
  await FileSystem.requestPermissions();
101
154
  }
102
155
 
103
- // Get external files directory
104
- const basePath = await FileSystem.getStoragePath("externalFiles");
156
+ // Get app cache path and write a file
157
+ const cachePath = await FileSystem.getStoragePath("appCache");
158
+ await FileSystem.writeFile(`${cachePath}/data.json`, JSON.stringify({ key: "value" }));
105
159
 
106
- // Write a text file
107
- await FileSystem.writeFile(`${basePath}/config.json`, '{"key": "value"}');
108
-
109
- // Read it back as a string
110
- const content = await FileSystem.readFile(`${basePath}/config.json`, "utf8");
160
+ // Read the file back as a string
161
+ const content = await FileSystem.readFile(`${cachePath}/data.json`, "utf8");
111
162
  ```
112
163
 
113
- ### List directory contents
164
+ ### List directory contents and check existence
114
165
 
115
- ```ts
166
+ ```typescript
116
167
  import { FileSystem } from "@simplysm/capacitor-plugin-file-system";
117
168
 
118
- const files = await FileSystem.readdir("/storage/emulated/0/Download");
169
+ const externalPath = await FileSystem.getStoragePath("external");
170
+ const files = await FileSystem.readdir(`${externalPath}/Documents`);
171
+
119
172
  for (const file of files) {
120
- console.log(`${file.name} (${file.isDirectory ? "dir" : "file"})`);
173
+ if (file.isDirectory) {
174
+ // handle directory
175
+ } else {
176
+ // handle file
177
+ }
121
178
  }
122
- ```
123
-
124
- ### Create directories and check existence
125
-
126
- ```ts
127
- import { FileSystem } from "@simplysm/capacitor-plugin-file-system";
128
-
129
- const dirPath = "/storage/emulated/0/MyApp/data/logs";
130
179
 
180
+ // Create a directory if it does not exist
181
+ const dirPath = `${externalPath}/MyApp/data/logs`;
131
182
  if (!(await FileSystem.exists(dirPath))) {
132
183
  await FileSystem.mkdir(dirPath);
133
184
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simplysm/capacitor-plugin-file-system",
3
- "version": "14.0.4",
3
+ "version": "14.0.5",
4
4
  "description": "심플리즘 패키지 - Capacitor 파일 시스템 플러그인",
5
5
  "author": "simplysm",
6
6
  "license": "Apache-2.0",
@@ -18,8 +18,8 @@
18
18
  "android"
19
19
  ],
20
20
  "dependencies": {
21
- "@simplysm/core-browser": "14.0.4",
22
- "@simplysm/core-common": "14.0.4"
21
+ "@simplysm/core-browser": "14.0.5",
22
+ "@simplysm/core-common": "14.0.5"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@capacitor/core": "^7.6.1"