@simplysm/capacitor-plugin-file-system 14.0.51 → 14.0.53
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.
|
@@ -35,7 +35,7 @@ class FileSystemPlugin : Plugin() {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
@PluginMethod
|
|
38
|
-
fun checkPermissions(call: PluginCall) {
|
|
38
|
+
override fun checkPermissions(call: PluginCall) {
|
|
39
39
|
val granted = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
|
40
40
|
Environment.isExternalStorageManager()
|
|
41
41
|
} else {
|
|
@@ -49,7 +49,7 @@ class FileSystemPlugin : Plugin() {
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
@PluginMethod
|
|
52
|
-
fun requestPermissions(call: PluginCall) {
|
|
52
|
+
override fun requestPermissions(call: PluginCall) {
|
|
53
53
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
|
54
54
|
if (!Environment.isExternalStorageManager()) {
|
|
55
55
|
val intent = Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION)
|
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.53",
|
|
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.53",
|
|
22
|
+
"@simplysm/core-browser": "14.0.53"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@capacitor/core": "^7.6.2"
|
package/README.md
DELETED
|
@@ -1,346 +0,0 @@
|
|
|
1
|
-
# @simplysm/capacitor-plugin-file-system
|
|
2
|
-
|
|
3
|
-
Capacitor 플러그인으로 Android 파일 시스템 접근을 제공합니다. 외부 저장소 전체 접근 및 앱 전용 디렉토리 접근을 지원하며, 브라우저 환경에서는 IndexedDB 기반 가상 파일 시스템으로 에뮬레이션합니다.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
npm install @simplysm/capacitor-plugin-file-system
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## API Overview
|
|
12
|
-
|
|
13
|
-
### `FileSystem`
|
|
14
|
-
|
|
15
|
-
파일 시스템 접근 파사드 클래스. 모든 API는 정적 메서드로 제공됩니다.
|
|
16
|
-
|
|
17
|
-
```typescript
|
|
18
|
-
abstract class FileSystem
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
#### Members
|
|
22
|
-
|
|
23
|
-
| Member | Kind | Signature | Description |
|
|
24
|
-
|--------|------|-----------|-------------|
|
|
25
|
-
| `checkPermissions` | static method | `() => Promise<boolean>` | 파일 시스템 접근 권한 확인 |
|
|
26
|
-
| `requestPermissions` | static method | `() => Promise<void>` | 파일 시스템 접근 권한 요청 |
|
|
27
|
-
| `readdir` | static method | `(dirPath: string) => Promise<FileInfo[]>` | 디렉토리 파일/폴더 목록 조회 |
|
|
28
|
-
| `getStoragePath` | static method | `(type: StorageType) => Promise<string>` | 저장소 유형별 경로 조회 |
|
|
29
|
-
| `getUri` | static method | `(filePath: string) => Promise<string>` | 파일 URI 조회 (FileProvider / Blob URL) |
|
|
30
|
-
| `writeFile` | static method | `(filePath: string, data: string \| Bytes) => Promise<void>` | 파일 쓰기 |
|
|
31
|
-
| `readFile` | static method | `(filePath: string, encoding?: "utf8") => Promise<Bytes \| string>` | 파일 읽기 (오버로드) |
|
|
32
|
-
| `remove` | static method | `(targetPath: string) => Promise<void>` | 파일/디렉토리 삭제 (재귀) |
|
|
33
|
-
| `mkdir` | static method | `(targetPath: string) => Promise<void>` | 디렉토리 생성 (재귀) |
|
|
34
|
-
| `exists` | static method | `(targetPath: string) => Promise<boolean>` | 파일/디렉토리 존재 여부 확인 |
|
|
35
|
-
|
|
36
|
-
---
|
|
37
|
-
|
|
38
|
-
#### `FileSystem.checkPermissions`
|
|
39
|
-
|
|
40
|
-
```typescript
|
|
41
|
-
static async checkPermissions(): Promise<boolean>
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
**Returns**: true (권한 허용), false (권한 거부)
|
|
45
|
-
|
|
46
|
-
**플랫폼별 동작:**
|
|
47
|
-
- **Android**: MANAGE_EXTERNAL_STORAGE 또는 READ/WRITE_EXTERNAL_STORAGE 권한 상태 확인
|
|
48
|
-
- **Web**: 항상 true (권한 개념 없음)
|
|
49
|
-
|
|
50
|
-
---
|
|
51
|
-
|
|
52
|
-
#### `FileSystem.requestPermissions`
|
|
53
|
-
|
|
54
|
-
```typescript
|
|
55
|
-
static async requestPermissions(): Promise<void>
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
**플랫폼별 동작:**
|
|
59
|
-
- **Android 11+ (API 30+)**: `MANAGE_EXTERNAL_STORAGE` 권한 — 설정 화면으로 이동하여 사용자가 수동 허용
|
|
60
|
-
- **Android 10 이하 (API 29-)**: `READ_EXTERNAL_STORAGE` + `WRITE_EXTERNAL_STORAGE` — 표준 권한 대화상자 표시
|
|
61
|
-
- **Web**: 아무 동작 없음
|
|
62
|
-
|
|
63
|
-
**권한 관련 주의사항:**
|
|
64
|
-
- Android 11+: `MANAGE_EXTERNAL_STORAGE`는 특수 권한으로 일반 권한 대화상자가 표시되지 않습니다. AndroidManifest.xml에 `android.permission.MANAGE_EXTERNAL_STORAGE`를 선언해야 합니다.
|
|
65
|
-
- Android 10 이하: `READ_EXTERNAL_STORAGE`, `WRITE_EXTERNAL_STORAGE`는 위험한(Dangerous) 권한으로 런타임 권한 요청이 필요합니다.
|
|
66
|
-
|
|
67
|
-
---
|
|
68
|
-
|
|
69
|
-
#### `FileSystem.readdir`
|
|
70
|
-
|
|
71
|
-
```typescript
|
|
72
|
-
static async readdir(dirPath: string): Promise<FileInfo[]>
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
| Parameter | Type | Description |
|
|
76
|
-
|-----------|------|-------------|
|
|
77
|
-
| `dirPath` | string | 조회할 디렉토리의 절대 경로 |
|
|
78
|
-
|
|
79
|
-
**Returns**: 디렉토리 내 파일/폴더 목록
|
|
80
|
-
|
|
81
|
-
**Throws**: 디렉토리가 존재하지 않거나 허용되지 않는 경로일 경우 Error
|
|
82
|
-
|
|
83
|
-
---
|
|
84
|
-
|
|
85
|
-
#### `FileSystem.getStoragePath`
|
|
86
|
-
|
|
87
|
-
```typescript
|
|
88
|
-
static async getStoragePath(type: StorageType): Promise<string>
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
| Parameter | Type | Description |
|
|
92
|
-
|-----------|------|-------------|
|
|
93
|
-
| `type` | `StorageType` | 저장소 유형 |
|
|
94
|
-
|
|
95
|
-
**Returns**: 절대 경로 문자열
|
|
96
|
-
|
|
97
|
-
**StorageType별 경로:**
|
|
98
|
-
|
|
99
|
-
| Type | Android Path | Web Path | 설명 |
|
|
100
|
-
|------|--------------|----------|------|
|
|
101
|
-
| `external` | `Environment.getExternalStorageDirectory()` | `/webfs/external` | 외부 저장소 루트 (공유 저장소) |
|
|
102
|
-
| `externalFiles` | `getExternalFilesDir(null)` | `/webfs/externalFiles` | 앱 전용 외부 파일 디렉토리 |
|
|
103
|
-
| `externalCache` | `externalCacheDir` | `/webfs/externalCache` | 앱 전용 외부 캐시 디렉토리 |
|
|
104
|
-
| `externalMedia` | `externalMediaDirs[0]` | `/webfs/externalMedia` | 앱 전용 외부 미디어 디렉토리 |
|
|
105
|
-
| `appData` | `applicationInfo.dataDir` | `/webfs/appData` | 앱 데이터 디렉토리 (내부) |
|
|
106
|
-
| `appFiles` | `filesDir` | `/webfs/appFiles` | 앱 파일 디렉토리 (내부) |
|
|
107
|
-
| `appCache` | `cacheDir` | `/webfs/appCache` | 앱 캐시 디렉토리 (내부) |
|
|
108
|
-
|
|
109
|
-
---
|
|
110
|
-
|
|
111
|
-
#### `FileSystem.getUri`
|
|
112
|
-
|
|
113
|
-
```typescript
|
|
114
|
-
static async getUri(filePath: string): Promise<string>
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
| Parameter | Type | Description |
|
|
118
|
-
|-----------|------|-------------|
|
|
119
|
-
| `filePath` | string | 파일의 절대 경로 |
|
|
120
|
-
|
|
121
|
-
**Returns**:
|
|
122
|
-
- Android: `content://` scheme의 FileProvider URI
|
|
123
|
-
- Web: `blob:` scheme의 Blob URL
|
|
124
|
-
|
|
125
|
-
**Web 환경 주의사항**: 반환된 Blob URL은 사용 후 반드시 `URL.revokeObjectURL(uri)`로 해제해야 합니다. 해제하지 않으면 메모리 누수가 발생합니다.
|
|
126
|
-
|
|
127
|
-
---
|
|
128
|
-
|
|
129
|
-
#### `FileSystem.writeFile`
|
|
130
|
-
|
|
131
|
-
```typescript
|
|
132
|
-
static async writeFile(filePath: string, data: string | Bytes): Promise<void>
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
| Parameter | Type | Description |
|
|
136
|
-
|-----------|------|-------------|
|
|
137
|
-
| `filePath` | string | 쓸 파일의 절대 경로 |
|
|
138
|
-
| `data` | `string \| Bytes` | 파일 내용 (문자열 또는 Uint8Array) |
|
|
139
|
-
|
|
140
|
-
**동작:**
|
|
141
|
-
- 문자열인 경우: UTF-8 인코딩으로 저장 (`encoding: "utf8"`)
|
|
142
|
-
- Bytes인 경우: Base64 인코딩을 중간 포맷으로 사용하여 저장 (`encoding: "base64"`)
|
|
143
|
-
- 웹 환경: 상위 디렉토리가 없으면 자동 생성
|
|
144
|
-
|
|
145
|
-
**Throws**: 쓰기 권한 없을 경우 Error
|
|
146
|
-
|
|
147
|
-
---
|
|
148
|
-
|
|
149
|
-
#### `FileSystem.readFile`
|
|
150
|
-
|
|
151
|
-
```typescript
|
|
152
|
-
static async readFile(filePath: string): Promise<Bytes>;
|
|
153
|
-
static async readFile(filePath: string, encoding: "utf8"): Promise<string>;
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
| Parameter | Type | Description |
|
|
157
|
-
|-----------|------|-------------|
|
|
158
|
-
| `filePath` | string | 읽을 파일의 절대 경로 |
|
|
159
|
-
| `encoding` | `"utf8"` (optional) | 생략 시 `Bytes` 반환, `"utf8"` 지정 시 `string` 반환 |
|
|
160
|
-
|
|
161
|
-
**Returns**:
|
|
162
|
-
- `encoding` 생략: `Promise<Bytes>` (Uint8Array)
|
|
163
|
-
- `encoding="utf8"`: `Promise<string>`
|
|
164
|
-
|
|
165
|
-
**Throws**: 파일이 없거나 읽기 권한이 없을 경우 Error
|
|
166
|
-
|
|
167
|
-
---
|
|
168
|
-
|
|
169
|
-
#### `FileSystem.remove`
|
|
170
|
-
|
|
171
|
-
```typescript
|
|
172
|
-
static async remove(targetPath: string): Promise<void>
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
| Parameter | Type | Description |
|
|
176
|
-
|-----------|------|-------------|
|
|
177
|
-
| `targetPath` | string | 삭제할 파일/디렉토리의 절대 경로 |
|
|
178
|
-
|
|
179
|
-
**동작:**
|
|
180
|
-
- 파일: 즉시 삭제
|
|
181
|
-
- 디렉토리: 하위 파일/폴더 포함 재귀 삭제
|
|
182
|
-
- 웹 환경: 경로 프리픽스로 모든 관련 항목 삭제
|
|
183
|
-
|
|
184
|
-
**Throws**: 대상이 존재하지 않거나 권한 없을 경우 Error
|
|
185
|
-
|
|
186
|
-
---
|
|
187
|
-
|
|
188
|
-
#### `FileSystem.mkdir`
|
|
189
|
-
|
|
190
|
-
```typescript
|
|
191
|
-
static async mkdir(targetPath: string): Promise<void>
|
|
192
|
-
```
|
|
193
|
-
|
|
194
|
-
| Parameter | Type | Description |
|
|
195
|
-
|-----------|------|-------------|
|
|
196
|
-
| `targetPath` | string | 생성할 디렉토리의 절대 경로 |
|
|
197
|
-
|
|
198
|
-
**동작:**
|
|
199
|
-
- 중간 경로가 없어도 자동 생성 (재귀)
|
|
200
|
-
- 이미 존재하면 아무 동작 없음
|
|
201
|
-
|
|
202
|
-
**Throws**: 권한 없을 경우 Error
|
|
203
|
-
|
|
204
|
-
---
|
|
205
|
-
|
|
206
|
-
#### `FileSystem.exists`
|
|
207
|
-
|
|
208
|
-
```typescript
|
|
209
|
-
static async exists(targetPath: string): Promise<boolean>
|
|
210
|
-
```
|
|
211
|
-
|
|
212
|
-
| Parameter | Type | Description |
|
|
213
|
-
|-----------|------|-------------|
|
|
214
|
-
| `targetPath` | string | 확인할 파일/디렉토리의 절대 경로 |
|
|
215
|
-
|
|
216
|
-
**Returns**: true (존재), false (존재하지 않음)
|
|
217
|
-
|
|
218
|
-
---
|
|
219
|
-
|
|
220
|
-
### `FileInfo`
|
|
221
|
-
|
|
222
|
-
파일 또는 디렉토리의 정보를 나타내는 인터페이스입니다. `FileSystem.readdir()`의 반환 타입 요소입니다.
|
|
223
|
-
|
|
224
|
-
```typescript
|
|
225
|
-
interface FileInfo {
|
|
226
|
-
name: string;
|
|
227
|
-
isDirectory: boolean;
|
|
228
|
-
}
|
|
229
|
-
```
|
|
230
|
-
|
|
231
|
-
| Field | Type | Description |
|
|
232
|
-
|-------|------|-------------|
|
|
233
|
-
| `name` | string | 파일 또는 디렉토리의 이름 (경로 제외, 확장자 포함) |
|
|
234
|
-
| `isDirectory` | boolean | true이면 디렉토리, false이면 파일 |
|
|
235
|
-
|
|
236
|
-
---
|
|
237
|
-
|
|
238
|
-
### `StorageType`
|
|
239
|
-
|
|
240
|
-
저장소 유형을 나타내는 union type입니다.
|
|
241
|
-
|
|
242
|
-
```typescript
|
|
243
|
-
type StorageType =
|
|
244
|
-
| "external"
|
|
245
|
-
| "externalFiles"
|
|
246
|
-
| "externalCache"
|
|
247
|
-
| "externalMedia"
|
|
248
|
-
| "appData"
|
|
249
|
-
| "appFiles"
|
|
250
|
-
| "appCache";
|
|
251
|
-
```
|
|
252
|
-
|
|
253
|
-
**선택 가이드:**
|
|
254
|
-
- **내부 저장소 (앱 전용)**: `appData` (상태 데이터, 자동 백업 대상) / `appFiles` (일반 파일) / `appCache` (임시 캐시, 시스템이 삭제 가능)
|
|
255
|
-
- **외부 저장소**: `external` (전체 외부 저장소, 권한 필요) / `externalFiles` (앱 전용 외부 파일, 권한 필요) / `externalCache` (앱 전용 외부 캐시, 권한 필요) / `externalMedia` (앱 전용 외부 미디어, 권한 필요)
|
|
256
|
-
|
|
257
|
-
---
|
|
258
|
-
|
|
259
|
-
### `FileSystemPlugin`
|
|
260
|
-
|
|
261
|
-
Capacitor 플러그인 인터페이스입니다. 일반적으로 `FileSystem` 파사드를 통해 간접적으로 사용됩니다.
|
|
262
|
-
|
|
263
|
-
```typescript
|
|
264
|
-
interface FileSystemPlugin {
|
|
265
|
-
checkPermissions(): Promise<{ granted: boolean }>;
|
|
266
|
-
requestPermissions(): Promise<void>;
|
|
267
|
-
readdir(options: { path: string }): Promise<{ files: FileInfo[] }>;
|
|
268
|
-
getStoragePath(options: { type: StorageType }): Promise<{ path: string }>;
|
|
269
|
-
getUri(options: { path: string }): Promise<{ uri: string }>;
|
|
270
|
-
writeFile(options: { path: string; data: string; encoding?: "utf8" | "base64" }): Promise<void>;
|
|
271
|
-
readFile(options: { path: string; encoding?: "utf8" | "base64" }): Promise<{ data: string }>;
|
|
272
|
-
remove(options: { path: string }): Promise<void>;
|
|
273
|
-
mkdir(options: { path: string }): Promise<void>;
|
|
274
|
-
exists(options: { path: string }): Promise<{ exists: boolean }>;
|
|
275
|
-
}
|
|
276
|
-
```
|
|
277
|
-
|
|
278
|
-
이 인터페이스는 내부 플러그인 구현용이며, 외부 사용자는 `FileSystem` 파사드의 정적 메서드를 사용합니다.
|
|
279
|
-
|
|
280
|
-
## Usage Examples
|
|
281
|
-
|
|
282
|
-
### 권한 확인 후 파일 읽기
|
|
283
|
-
|
|
284
|
-
```typescript
|
|
285
|
-
import { FileSystem } from "@simplysm/capacitor-plugin-file-system";
|
|
286
|
-
|
|
287
|
-
async function readAppFile() {
|
|
288
|
-
const hasPermission = await FileSystem.checkPermissions();
|
|
289
|
-
if (!hasPermission) {
|
|
290
|
-
await FileSystem.requestPermissions();
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
const appFilesPath = await FileSystem.getStoragePath("appFiles");
|
|
294
|
-
const content = await FileSystem.readFile(appFilesPath + "/config.json", "utf8");
|
|
295
|
-
}
|
|
296
|
-
```
|
|
297
|
-
|
|
298
|
-
### Bytes 데이터 쓰기
|
|
299
|
-
|
|
300
|
-
```typescript
|
|
301
|
-
import { FileSystem } from "@simplysm/capacitor-plugin-file-system";
|
|
302
|
-
|
|
303
|
-
async function writeImage() {
|
|
304
|
-
const appCachePath = await FileSystem.getStoragePath("appCache");
|
|
305
|
-
const data = new Uint8Array([0x89, 0x50, 0x4e, 0x47]); // PNG header
|
|
306
|
-
await FileSystem.writeFile(appCachePath + "/image.png", data);
|
|
307
|
-
}
|
|
308
|
-
```
|
|
309
|
-
|
|
310
|
-
### 디렉토리 탐색 및 삭제
|
|
311
|
-
|
|
312
|
-
```typescript
|
|
313
|
-
import { FileSystem } from "@simplysm/capacitor-plugin-file-system";
|
|
314
|
-
|
|
315
|
-
async function listAndClean(dirPath: string) {
|
|
316
|
-
const files = await FileSystem.readdir(dirPath);
|
|
317
|
-
for (const file of files) {
|
|
318
|
-
console.log(`${file.name} ${file.isDirectory ? "(dir)" : "(file)"}`);
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
const exists = await FileSystem.exists(dirPath);
|
|
322
|
-
if (exists) {
|
|
323
|
-
await FileSystem.remove(dirPath);
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
```
|
|
327
|
-
|
|
328
|
-
### 웹 환경: Blob URL 사용 후 해제
|
|
329
|
-
|
|
330
|
-
```typescript
|
|
331
|
-
import { FileSystem } from "@simplysm/capacitor-plugin-file-system";
|
|
332
|
-
|
|
333
|
-
async function showImageInBrowser() {
|
|
334
|
-
const appFilesPath = await FileSystem.getStoragePath("appFiles");
|
|
335
|
-
const uri = await FileSystem.getUri(appFilesPath + "/photo.jpg");
|
|
336
|
-
|
|
337
|
-
const img = document.createElement("img");
|
|
338
|
-
img.src = uri;
|
|
339
|
-
document.body.appendChild(img);
|
|
340
|
-
|
|
341
|
-
// 사용 완료 후 반드시 해제 (메모리 누수 방지)
|
|
342
|
-
img.onload = () => {
|
|
343
|
-
URL.revokeObjectURL(uri);
|
|
344
|
-
};
|
|
345
|
-
}
|
|
346
|
-
```
|