@simplysm/capacitor-plugin-file-system 14.0.23 → 14.0.25
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/package.json +3 -3
- package/README.md +0 -185
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.25",
|
|
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-
|
|
22
|
-
"@simplysm/core-
|
|
21
|
+
"@simplysm/core-common": "14.0.25",
|
|
22
|
+
"@simplysm/core-browser": "14.0.25"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@capacitor/core": "^7.6.1"
|
package/README.md
DELETED
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
# @simplysm/capacitor-plugin-file-system
|
|
2
|
-
|
|
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
|
|
8
|
-
|
|
9
|
-
## Installation
|
|
10
|
-
|
|
11
|
-
```bash
|
|
12
|
-
npm install @simplysm/capacitor-plugin-file-system
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
## API Overview
|
|
16
|
-
|
|
17
|
-
### Types
|
|
18
|
-
|
|
19
|
-
| API | Type | Description |
|
|
20
|
-
|-----|------|-------------|
|
|
21
|
-
| `StorageType` | Type | Union of supported Android storage location identifiers |
|
|
22
|
-
|
|
23
|
-
### Interfaces
|
|
24
|
-
|
|
25
|
-
| API | Type | Description |
|
|
26
|
-
|-----|------|-------------|
|
|
27
|
-
| `FileInfo` | Interface | File entry metadata returned by directory listing |
|
|
28
|
-
| `FileSystemPlugin` | Interface | Native plugin interface for file system operations |
|
|
29
|
-
|
|
30
|
-
### Classes
|
|
31
|
-
|
|
32
|
-
| API | Type | Description |
|
|
33
|
-
|-----|------|-------------|
|
|
34
|
-
| `FileSystem` | Class | Static API for file system access with permission management |
|
|
35
|
-
|
|
36
|
-
## `StorageType`
|
|
37
|
-
|
|
38
|
-
Union type representing available storage location types.
|
|
39
|
-
|
|
40
|
-
```typescript
|
|
41
|
-
type StorageType =
|
|
42
|
-
| "external"
|
|
43
|
-
| "externalFiles"
|
|
44
|
-
| "externalCache"
|
|
45
|
-
| "externalMedia"
|
|
46
|
-
| "appData"
|
|
47
|
-
| "appFiles"
|
|
48
|
-
| "appCache";
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
| Value | Description |
|
|
52
|
-
|-------|-------------|
|
|
53
|
-
| `"external"` | Shared external storage root (`Environment.getExternalStorageDirectory`) |
|
|
54
|
-
| `"externalFiles"` | App-specific external files directory |
|
|
55
|
-
| `"externalCache"` | App-specific external cache directory |
|
|
56
|
-
| `"externalMedia"` | App-specific external media directory |
|
|
57
|
-
| `"appData"` | Internal app data directory |
|
|
58
|
-
| `"appFiles"` | Internal app files directory |
|
|
59
|
-
| `"appCache"` | Internal app cache directory |
|
|
60
|
-
|
|
61
|
-
## `FileInfo`
|
|
62
|
-
|
|
63
|
-
Metadata for a single file or directory entry.
|
|
64
|
-
|
|
65
|
-
```typescript
|
|
66
|
-
interface FileInfo {
|
|
67
|
-
name: string;
|
|
68
|
-
isDirectory: boolean;
|
|
69
|
-
}
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
| Field | Type | Description |
|
|
73
|
-
|-------|------|-------------|
|
|
74
|
-
| `name` | `string` | Name of the file or directory |
|
|
75
|
-
| `isDirectory` | `boolean` | `true` if the entry is a directory |
|
|
76
|
-
|
|
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
|
-
```
|
|
95
|
-
|
|
96
|
-
| Method | Signature | Description |
|
|
97
|
-
|--------|-----------|-------------|
|
|
98
|
-
| `checkPermissions` | `() => Promise<{ granted: boolean }>` | Check if storage permissions are granted |
|
|
99
|
-
| `requestPermissions` | `() => Promise<void>` | Request storage permissions |
|
|
100
|
-
| `readdir` | `(options: { path: string }) => Promise<{ files: FileInfo[] }>` | List files in a directory |
|
|
101
|
-
| `getStoragePath` | `(options: { type: StorageType }) => Promise<{ path: string }>` | Get the absolute path for a storage type |
|
|
102
|
-
| `getUri` | `(options: { path: string }) => Promise<{ uri: string }>` | Get a FileProvider `content://` URI for a file path |
|
|
103
|
-
| `writeFile` | `(options: { path: string; data: string; encoding?: "utf8" \| "base64" }) => Promise<void>` | Write data to a file |
|
|
104
|
-
| `readFile` | `(options: { path: string; encoding?: "utf8" \| "base64" }) => Promise<{ data: string }>` | Read data from a file |
|
|
105
|
-
| `remove` | `(options: { path: string }) => Promise<void>` | Remove a file or directory |
|
|
106
|
-
| `mkdir` | `(options: { path: string }) => Promise<void>` | Create a directory |
|
|
107
|
-
| `exists` | `(options: { path: string }) => Promise<{ exists: boolean }>` | Check if a path exists |
|
|
108
|
-
|
|
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
|
-
```
|
|
128
|
-
|
|
129
|
-
| Method | Signature | Description |
|
|
130
|
-
|--------|-----------|-------------|
|
|
131
|
-
| `checkPermissions` | `static async checkPermissions(): Promise<boolean>` | Check whether storage permissions are granted |
|
|
132
|
-
| `requestPermissions` | `static async requestPermissions(): Promise<void>` | Request storage permissions from the user |
|
|
133
|
-
| `readdir` | `static async readdir(dirPath: string): Promise<FileInfo[]>` | List files and directories at the given 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 |
|
|
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. |
|
|
137
|
-
| `readFile` | `static async readFile(filePath: string): Promise<Bytes>` | Read a file as binary data |
|
|
138
|
-
| `readFile` (overload) | `static async readFile(filePath: string, encoding: "utf8"): Promise<string>` | Read a file as a UTF-8 string |
|
|
139
|
-
| `remove` | `static async remove(targetPath: string): Promise<void>` | Recursively delete a file or directory |
|
|
140
|
-
| `mkdir` | `static async mkdir(targetPath: string): Promise<void>` | Recursively create a directory and all parent directories |
|
|
141
|
-
| `exists` | `static async exists(targetPath: string): Promise<boolean>` | Check whether a file or directory exists at the given path |
|
|
142
|
-
|
|
143
|
-
## Usage Examples
|
|
144
|
-
|
|
145
|
-
### Read and write files
|
|
146
|
-
|
|
147
|
-
```typescript
|
|
148
|
-
import { FileSystem } from "@simplysm/capacitor-plugin-file-system";
|
|
149
|
-
|
|
150
|
-
// Ensure permissions
|
|
151
|
-
const granted = await FileSystem.checkPermissions();
|
|
152
|
-
if (!granted) {
|
|
153
|
-
await FileSystem.requestPermissions();
|
|
154
|
-
}
|
|
155
|
-
|
|
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" }));
|
|
159
|
-
|
|
160
|
-
// Read the file back as a string
|
|
161
|
-
const content = await FileSystem.readFile(`${cachePath}/data.json`, "utf8");
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
### List directory contents and check existence
|
|
165
|
-
|
|
166
|
-
```typescript
|
|
167
|
-
import { FileSystem } from "@simplysm/capacitor-plugin-file-system";
|
|
168
|
-
|
|
169
|
-
const externalPath = await FileSystem.getStoragePath("external");
|
|
170
|
-
const files = await FileSystem.readdir(`${externalPath}/Documents`);
|
|
171
|
-
|
|
172
|
-
for (const file of files) {
|
|
173
|
-
if (file.isDirectory) {
|
|
174
|
-
// handle directory
|
|
175
|
-
} else {
|
|
176
|
-
// handle file
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
// Create a directory if it does not exist
|
|
181
|
-
const dirPath = `${externalPath}/MyApp/data/logs`;
|
|
182
|
-
if (!(await FileSystem.exists(dirPath))) {
|
|
183
|
-
await FileSystem.mkdir(dirPath);
|
|
184
|
-
}
|
|
185
|
-
```
|