@simplysm/capacitor-plugin-file-system 14.0.1 → 14.0.4
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 +134 -0
- package/package.json +4 -4
package/README.md
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# @simplysm/capacitor-plugin-file-system
|
|
2
|
+
|
|
3
|
+
Capacitor file system plugin with full storage access on Android 11+.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @simplysm/capacitor-plugin-file-system
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## API Overview
|
|
12
|
+
|
|
13
|
+
### File System
|
|
14
|
+
|
|
15
|
+
| API | Type | Description |
|
|
16
|
+
|-----|------|-------------|
|
|
17
|
+
| `StorageType` | Type | Union of supported Android storage location identifiers |
|
|
18
|
+
| `FileInfo` | Interface | File entry metadata returned by directory listing |
|
|
19
|
+
| `FileSystemPlugin` | Interface | Native plugin interface for file system operations |
|
|
20
|
+
| `FileSystem` | Class | Static API for file system access with permission management |
|
|
21
|
+
|
|
22
|
+
## Types
|
|
23
|
+
|
|
24
|
+
### StorageType
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
type StorageType = "external" | "externalFiles" | "externalCache" | "externalMedia" | "appData" | "appFiles" | "appCache";
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
| Value | Description |
|
|
31
|
+
|-------|-------------|
|
|
32
|
+
| `"external"` | Shared external storage root |
|
|
33
|
+
| `"externalFiles"` | App-specific external files directory |
|
|
34
|
+
| `"externalCache"` | App-specific external cache directory |
|
|
35
|
+
| `"externalMedia"` | App-specific external media directory |
|
|
36
|
+
| `"appData"` | Internal app data directory |
|
|
37
|
+
| `"appFiles"` | Internal app files directory |
|
|
38
|
+
| `"appCache"` | Internal app cache directory |
|
|
39
|
+
|
|
40
|
+
## Interfaces
|
|
41
|
+
|
|
42
|
+
### FileInfo
|
|
43
|
+
|
|
44
|
+
Metadata for a single file or directory entry.
|
|
45
|
+
|
|
46
|
+
| Field | Type | Description |
|
|
47
|
+
|-------|------|-------------|
|
|
48
|
+
| `name` | `string` | Name of the file or directory |
|
|
49
|
+
| `isDirectory` | `boolean` | `true` if the entry is a directory |
|
|
50
|
+
|
|
51
|
+
### FileSystemPlugin
|
|
52
|
+
|
|
53
|
+
Native plugin interface for file system operations.
|
|
54
|
+
|
|
55
|
+
| Method | Signature | Description |
|
|
56
|
+
|--------|-----------|-------------|
|
|
57
|
+
| `checkPermissions` | `() => Promise<{ granted: boolean }>` | Check if storage permissions are granted |
|
|
58
|
+
| `requestPermissions` | `() => Promise<void>` | Request storage permissions |
|
|
59
|
+
| `readdir` | `(options: { path: string }) => Promise<{ files: FileInfo[] }>` | List files in a directory |
|
|
60
|
+
| `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 |
|
|
62
|
+
| `writeFile` | `(options: { path: string; data: string; encoding?: "utf8" \| "base64" }) => Promise<void>` | Write data to a file |
|
|
63
|
+
| `readFile` | `(options: { path: string; encoding?: "utf8" \| "base64" }) => Promise<{ data: string }>` | Read data from a file |
|
|
64
|
+
| `remove` | `(options: { path: string }) => Promise<void>` | Remove a file or directory |
|
|
65
|
+
| `mkdir` | `(options: { path: string }) => Promise<void>` | Create a directory |
|
|
66
|
+
| `exists` | `(options: { path: string }) => Promise<{ exists: boolean }>` | Check if a path exists |
|
|
67
|
+
|
|
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.
|
|
75
|
+
|
|
76
|
+
| Method | Signature | Description |
|
|
77
|
+
|--------|-----------|-------------|
|
|
78
|
+
| `checkPermissions` | `static async checkPermissions(): Promise<boolean>` | Check whether storage permissions are granted |
|
|
79
|
+
| `requestPermissions` | `static async requestPermissions(): Promise<void>` | Request storage permissions from the user |
|
|
80
|
+
| `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 |
|
|
83
|
+
| `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
|
+
| `readFile` | `static async readFile(filePath: string): Promise<Bytes>` | Read a file as binary data |
|
|
85
|
+
| `readFile` (overload) | `static async readFile(filePath: string, encoding: "utf8"): Promise<string>` | Read a file as a UTF-8 string |
|
|
86
|
+
| `remove` | `static async remove(targetPath: string): Promise<void>` | Recursively delete a file or directory |
|
|
87
|
+
| `mkdir` | `static async mkdir(targetPath: string): Promise<void>` | Recursively create a directory and all parent directories |
|
|
88
|
+
| `exists` | `static async exists(targetPath: string): Promise<boolean>` | Check whether a file or directory exists at the given path |
|
|
89
|
+
|
|
90
|
+
## Usage Examples
|
|
91
|
+
|
|
92
|
+
### Read and write files
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
import { FileSystem } from "@simplysm/capacitor-plugin-file-system";
|
|
96
|
+
|
|
97
|
+
// Ensure permissions
|
|
98
|
+
const granted = await FileSystem.checkPermissions();
|
|
99
|
+
if (!granted) {
|
|
100
|
+
await FileSystem.requestPermissions();
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Get external files directory
|
|
104
|
+
const basePath = await FileSystem.getStoragePath("externalFiles");
|
|
105
|
+
|
|
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");
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### List directory contents
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
import { FileSystem } from "@simplysm/capacitor-plugin-file-system";
|
|
117
|
+
|
|
118
|
+
const files = await FileSystem.readdir("/storage/emulated/0/Download");
|
|
119
|
+
for (const file of files) {
|
|
120
|
+
console.log(`${file.name} (${file.isDirectory ? "dir" : "file"})`);
|
|
121
|
+
}
|
|
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
|
+
|
|
131
|
+
if (!(await FileSystem.exists(dirPath))) {
|
|
132
|
+
await FileSystem.mkdir(dirPath);
|
|
133
|
+
}
|
|
134
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simplysm/capacitor-plugin-file-system",
|
|
3
|
-
"version": "14.0.
|
|
3
|
+
"version": "14.0.4",
|
|
4
4
|
"description": "심플리즘 패키지 - Capacitor 파일 시스템 플러그인",
|
|
5
5
|
"author": "simplysm",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -18,11 +18,11 @@
|
|
|
18
18
|
"android"
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@simplysm/core-browser": "14.0.
|
|
22
|
-
"@simplysm/core-common": "14.0.
|
|
21
|
+
"@simplysm/core-browser": "14.0.4",
|
|
22
|
+
"@simplysm/core-common": "14.0.4"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@capacitor/core": "^7.6.
|
|
25
|
+
"@capacitor/core": "^7.6.1"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"@capacitor/core": "^7"
|