@simplysm/capacitor-plugin-file-system 13.0.96 → 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 +89 -129
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,172 +1,132 @@
|
|
|
1
1
|
# @simplysm/capacitor-plugin-file-system
|
|
2
2
|
|
|
3
|
-
Capacitor
|
|
3
|
+
Capacitor File System Plugin -- full file system access for Android with IndexedDB fallback for browser.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
8
|
npm install @simplysm/capacitor-plugin-file-system
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
**Peer:** `@capacitor/core` ^7.4.4
|
|
11
|
+
## API Overview
|
|
13
12
|
|
|
14
|
-
|
|
13
|
+
### Types
|
|
15
14
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
```
|
|
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`) |
|
|
21
19
|
|
|
22
|
-
|
|
20
|
+
### Interfaces
|
|
23
21
|
|
|
24
|
-
|
|
22
|
+
| API | Type | Description |
|
|
23
|
+
|-----|------|-------------|
|
|
24
|
+
| `FileSystemPlugin` | interface | Low-level Capacitor plugin interface for file system operations |
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
import { FileSystem } from "@simplysm/capacitor-plugin-file-system";
|
|
26
|
+
### Classes
|
|
28
27
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
// Android 11+: MANAGE_EXTERNAL_STORAGE 설정 화면 이동
|
|
33
|
-
// Android 10-: READ/WRITE_EXTERNAL_STORAGE 권한 다이얼로그
|
|
34
|
-
}
|
|
35
|
-
```
|
|
28
|
+
| API | Type | Description |
|
|
29
|
+
|-----|------|-------------|
|
|
30
|
+
| `FileSystem` | abstract class | File system access with permission management |
|
|
36
31
|
|
|
37
|
-
|
|
32
|
+
## `StorageType`
|
|
38
33
|
|
|
39
34
|
```typescript
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
// 텍스트 읽기
|
|
50
|
-
const text: string = await FileSystem.readFile("/path/to/file.txt", "utf8");
|
|
51
|
-
|
|
52
|
-
// 바이너리 읽기 (기본값, Bytes 반환)
|
|
53
|
-
const bytes: Bytes = await FileSystem.readFile("/path/to/file.bin");
|
|
35
|
+
type StorageType =
|
|
36
|
+
| "external"
|
|
37
|
+
| "externalFiles"
|
|
38
|
+
| "externalCache"
|
|
39
|
+
| "externalMedia"
|
|
40
|
+
| "appData"
|
|
41
|
+
| "appFiles"
|
|
42
|
+
| "appCache";
|
|
54
43
|
```
|
|
55
44
|
|
|
56
|
-
`
|
|
57
|
-
|
|
58
|
-
### 디렉토리 조작
|
|
45
|
+
## `FileInfo`
|
|
59
46
|
|
|
60
47
|
```typescript
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const files = await FileSystem.readdir("/storage/emulated/0/myapp");
|
|
66
|
-
// FileInfo[] = [{ name: "data", isDirectory: true }, { name: "config.json", isDirectory: false }]
|
|
67
|
-
|
|
68
|
-
// 파일/디렉토리 삭제 (재귀)
|
|
69
|
-
await FileSystem.remove("/storage/emulated/0/myapp/temp");
|
|
70
|
-
|
|
71
|
-
// 존재 여부 확인
|
|
72
|
-
const exists = await FileSystem.exists("/storage/emulated/0/myapp"); // boolean
|
|
48
|
+
interface FileInfo {
|
|
49
|
+
name: string;
|
|
50
|
+
isDirectory: boolean;
|
|
51
|
+
}
|
|
73
52
|
```
|
|
74
53
|
|
|
75
|
-
|
|
54
|
+
## `FileSystemPlugin`
|
|
76
55
|
|
|
77
56
|
```typescript
|
|
78
|
-
|
|
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
|
+
}
|
|
79
69
|
```
|
|
80
70
|
|
|
81
|
-
|
|
82
|
-
|------|-------------|------|
|
|
83
|
-
| `"external"` | `Environment.getExternalStorageDirectory()` | 외부 스토리지 루트 |
|
|
84
|
-
| `"externalFiles"` | `getExternalFilesDir(null)` | 앱 전용 외부 파일 |
|
|
85
|
-
| `"externalCache"` | `getExternalCacheDir()` | 앱 전용 외부 캐시 |
|
|
86
|
-
| `"externalMedia"` | `getExternalMediaDirs()[0]` | 앱 전용 미디어 |
|
|
87
|
-
| `"appData"` | `getApplicationInfo().dataDir` | 앱 데이터 디렉토리 |
|
|
88
|
-
| `"appFiles"` | `getFilesDir()` | 앱 파일 디렉토리 |
|
|
89
|
-
| `"appCache"` | `getCacheDir()` | 앱 캐시 디렉토리 |
|
|
71
|
+
Low-level Capacitor plugin interface. Use `FileSystem` static methods instead of calling this directly.
|
|
90
72
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
### FileProvider URI
|
|
94
|
-
|
|
95
|
-
파일의 `content://` URI를 얻는다. APK 설치 등 인텐트에 파일을 전달할 때 사용한다.
|
|
73
|
+
## `FileSystem`
|
|
96
74
|
|
|
97
75
|
```typescript
|
|
98
|
-
|
|
99
|
-
|
|
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
|
+
}
|
|
100
89
|
```
|
|
101
90
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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.
|
|
105
95
|
|
|
106
|
-
|
|
107
|
-
|--------|----------|------|
|
|
108
|
-
| `checkPermissions` | `() => Promise<boolean>` | 파일시스템 권한 확인 |
|
|
109
|
-
| `requestPermissions` | `() => Promise<void>` | 권한 요청 |
|
|
110
|
-
| `readdir` | `(dirPath: string) => Promise<FileInfo[]>` | 디렉토리 목록 |
|
|
111
|
-
| `getStoragePath` | `(type: StorageType) => Promise<string>` | 스토리지 경로 조회 |
|
|
112
|
-
| `getUri` | `(filePath: string) => Promise<string>` | FileProvider URI |
|
|
113
|
-
| `writeFile` | `(filePath: string, data: string \| Bytes) => Promise<void>` | 파일 쓰기 |
|
|
114
|
-
| `readFile` | `(filePath: string) => Promise<Bytes>` | 바이너리 읽기 |
|
|
115
|
-
| `readFile` | `(filePath: string, encoding: "utf8") => Promise<string>` | 텍스트 읽기 |
|
|
116
|
-
| `remove` | `(targetPath: string) => Promise<void>` | 재귀 삭제 |
|
|
117
|
-
| `mkdir` | `(targetPath: string) => Promise<void>` | 재귀 생성 |
|
|
118
|
-
| `exists` | `(targetPath: string) => Promise<boolean>` | 존재 여부 확인 |
|
|
96
|
+
## Usage Examples
|
|
119
97
|
|
|
120
|
-
###
|
|
98
|
+
### Read and write files
|
|
121
99
|
|
|
122
100
|
```typescript
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
| "appCache";
|
|
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");
|
|
131
108
|
```
|
|
132
109
|
|
|
133
|
-
###
|
|
110
|
+
### List directory contents
|
|
134
111
|
|
|
135
112
|
```typescript
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
113
|
+
import { FileSystem } from "@simplysm/capacitor-plugin-file-system";
|
|
114
|
+
|
|
115
|
+
const granted = await FileSystem.checkPermissions();
|
|
116
|
+
if (!granted) {
|
|
117
|
+
await FileSystem.requestPermissions();
|
|
139
118
|
}
|
|
119
|
+
|
|
120
|
+
const externalPath = await FileSystem.getStoragePath("external");
|
|
121
|
+
const files = await FileSystem.readdir(externalPath + "/Documents");
|
|
140
122
|
```
|
|
141
123
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
## Android 네이티브 구현
|
|
153
|
-
|
|
154
|
-
- **패키지:** `kr.co.simplysm.capacitor.filesystem`
|
|
155
|
-
- **플러그인명:** `FileSystem`
|
|
156
|
-
- **FileProvider authority:** `${applicationId}.filesystem.provider`
|
|
157
|
-
- **FileProvider paths:** external, external_files, external_cache, files, cache (모두 root `.`)
|
|
158
|
-
- **AndroidManifest 권한:**
|
|
159
|
-
- `READ_EXTERNAL_STORAGE` (maxSdkVersion=32)
|
|
160
|
-
- `WRITE_EXTERNAL_STORAGE` (maxSdkVersion=29)
|
|
161
|
-
- `MANAGE_EXTERNAL_STORAGE`
|
|
162
|
-
- `writeFile`: 부모 디렉토리 자동 생성 (`mkdirs`), BufferedOutputStream 사용
|
|
163
|
-
- `readFile`: BufferedInputStream + ByteArrayOutputStream (8KB 버퍼)
|
|
164
|
-
|
|
165
|
-
## Web 구현 상세
|
|
166
|
-
|
|
167
|
-
`FileSystemWeb`은 `VirtualFileSystem` 클래스를 사용하며, 내부적으로 `IndexedDbStore`와 `IndexedDbVirtualFs`(`@simplysm/core-browser`)를 활용한다.
|
|
168
|
-
|
|
169
|
-
- **IndexedDB 이름:** `capacitor_web_virtual_fs`
|
|
170
|
-
- **스토어:** `entries` (keyPath: `path`)
|
|
171
|
-
- `getUri`: Blob URL 반환. 사용 후 `URL.revokeObjectURL(uri)` 호출 필요 (메모리 누수 방지)
|
|
172
|
-
- 암묵적 디렉토리 처리: 파일 경로만 저장되어 있어도 중간 경로를 디렉토리로 인식
|
|
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"
|