@simplysm/capacitor-plugin-file-system 13.0.85 → 13.0.87
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 +112 -140
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,200 +1,172 @@
|
|
|
1
1
|
# @simplysm/capacitor-plugin-file-system
|
|
2
2
|
|
|
3
|
-
Capacitor
|
|
3
|
+
Capacitor 파일시스템 플러그인. Android 네이티브 파일시스템 접근과 Web IndexedDB 기반 가상 파일시스템을 제공한다.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
- **Android 10 and below**: `READ_EXTERNAL_STORAGE` / `WRITE_EXTERNAL_STORAGE` permissions
|
|
7
|
-
- **Browser**: IndexedDB-based virtual file system emulation
|
|
8
|
-
|
|
9
|
-
## Installation
|
|
5
|
+
## 설치
|
|
10
6
|
|
|
11
7
|
```bash
|
|
12
8
|
npm install @simplysm/capacitor-plugin-file-system
|
|
13
9
|
```
|
|
14
10
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
- `@capacitor/core` ^7.4.4
|
|
18
|
-
|
|
19
|
-
## API
|
|
11
|
+
**의존성:** `@simplysm/core-common` (Bytes, bytes 유틸), `@simplysm/core-browser` (IndexedDbStore, IndexedDbVirtualFs)
|
|
12
|
+
**Peer:** `@capacitor/core` ^7.4.4
|
|
20
13
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
Abstract static class providing all file system operations.
|
|
14
|
+
## Export 목록
|
|
24
15
|
|
|
25
16
|
```typescript
|
|
26
|
-
|
|
17
|
+
// index.ts
|
|
18
|
+
export { FileSystem } from "./FileSystem";
|
|
19
|
+
export type { FileSystemPlugin, FileInfo, StorageType } from "./FileSystemPlugin";
|
|
27
20
|
```
|
|
28
21
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
Check whether file system permissions are granted.
|
|
32
|
-
|
|
33
|
-
```typescript
|
|
34
|
-
static async checkPermissions(): Promise<boolean>
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
**Returns**: `true` if permissions are granted, `false` otherwise. On the web platform, always returns `true`.
|
|
38
|
-
|
|
39
|
-
#### `FileSystem.requestPermissions()`
|
|
22
|
+
## 주요 사용법
|
|
40
23
|
|
|
41
|
-
|
|
24
|
+
### 권한 관리
|
|
42
25
|
|
|
43
26
|
```typescript
|
|
44
|
-
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
- Android 11+: Navigates to the system settings page for the user to grant access.
|
|
48
|
-
- Android 10 and below: Shows the standard permission dialog.
|
|
49
|
-
|
|
50
|
-
#### `FileSystem.readdir(dirPath)`
|
|
51
|
-
|
|
52
|
-
Read the contents of a directory.
|
|
27
|
+
import { FileSystem } from "@simplysm/capacitor-plugin-file-system";
|
|
53
28
|
|
|
54
|
-
|
|
55
|
-
|
|
29
|
+
const granted = await FileSystem.checkPermissions(); // boolean
|
|
30
|
+
if (!granted) {
|
|
31
|
+
await FileSystem.requestPermissions();
|
|
32
|
+
// Android 11+: MANAGE_EXTERNAL_STORAGE 설정 화면 이동
|
|
33
|
+
// Android 10-: READ/WRITE_EXTERNAL_STORAGE 권한 다이얼로그
|
|
34
|
+
}
|
|
56
35
|
```
|
|
57
36
|
|
|
58
|
-
|
|
59
|
-
|-----------|------|-------------|
|
|
60
|
-
| `dirPath` | `string` | Absolute path to the directory |
|
|
61
|
-
|
|
62
|
-
**Returns**: Array of `FileInfo` objects.
|
|
63
|
-
|
|
64
|
-
#### `FileSystem.getStoragePath(type)`
|
|
65
|
-
|
|
66
|
-
Get the absolute path for a specific storage location.
|
|
37
|
+
### 파일 읽기/쓰기
|
|
67
38
|
|
|
68
39
|
```typescript
|
|
69
|
-
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
| Parameter | Type | Description |
|
|
73
|
-
|-----------|------|-------------|
|
|
74
|
-
| `type` | `StorageType` | The storage location type |
|
|
40
|
+
import type { Bytes } from "@simplysm/core-common";
|
|
75
41
|
|
|
76
|
-
|
|
42
|
+
// 텍스트 파일 쓰기
|
|
43
|
+
await FileSystem.writeFile("/storage/emulated/0/test.txt", "Hello World");
|
|
77
44
|
|
|
78
|
-
|
|
45
|
+
// 바이너리 파일 쓰기 (Bytes = Uint8Array)
|
|
46
|
+
const data: Bytes = new Uint8Array([0x48, 0x65, 0x6c, 0x6c, 0x6f]);
|
|
47
|
+
await FileSystem.writeFile("/storage/emulated/0/data.bin", data);
|
|
79
48
|
|
|
80
|
-
|
|
49
|
+
// 텍스트 읽기
|
|
50
|
+
const text: string = await FileSystem.readFile("/path/to/file.txt", "utf8");
|
|
81
51
|
|
|
82
|
-
|
|
83
|
-
|
|
52
|
+
// 바이너리 읽기 (기본값, Bytes 반환)
|
|
53
|
+
const bytes: Bytes = await FileSystem.readFile("/path/to/file.bin");
|
|
84
54
|
```
|
|
85
55
|
|
|
86
|
-
|
|
87
|
-
|-----------|------|-------------|
|
|
88
|
-
| `filePath` | `string` | Absolute path to the file |
|
|
56
|
+
`writeFile`은 내부적으로 string이면 utf8, Bytes이면 base64로 인코딩하여 네이티브에 전달한다.
|
|
89
57
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
#### `FileSystem.writeFile(filePath, data)`
|
|
93
|
-
|
|
94
|
-
Write data to a file. Parent directories are created automatically.
|
|
58
|
+
### 디렉토리 조작
|
|
95
59
|
|
|
96
60
|
```typescript
|
|
97
|
-
|
|
98
|
-
|
|
61
|
+
// 디렉토리 생성 (재귀)
|
|
62
|
+
await FileSystem.mkdir("/storage/emulated/0/myapp/data");
|
|
99
63
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
| `data` | `string \| Bytes` | Content to write. Strings are written as UTF-8; `Bytes` (`Uint8Array`) is encoded as base64 for transfer. |
|
|
64
|
+
// 디렉토리 목록 조회
|
|
65
|
+
const files = await FileSystem.readdir("/storage/emulated/0/myapp");
|
|
66
|
+
// FileInfo[] = [{ name: "data", isDirectory: true }, { name: "config.json", isDirectory: false }]
|
|
104
67
|
|
|
105
|
-
|
|
68
|
+
// 파일/디렉토리 삭제 (재귀)
|
|
69
|
+
await FileSystem.remove("/storage/emulated/0/myapp/temp");
|
|
106
70
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
```typescript
|
|
110
|
-
static async readFile(filePath: string): Promise<Bytes>
|
|
111
|
-
static async readFile(filePath: string, encoding: "utf8"): Promise<string>
|
|
71
|
+
// 존재 여부 확인
|
|
72
|
+
const exists = await FileSystem.exists("/storage/emulated/0/myapp"); // boolean
|
|
112
73
|
```
|
|
113
74
|
|
|
114
|
-
|
|
115
|
-
|-----------|------|-------------|
|
|
116
|
-
| `filePath` | `string` | Absolute path to the file |
|
|
117
|
-
| `encoding` | `"utf8"` (optional) | If provided, returns a UTF-8 decoded string |
|
|
118
|
-
|
|
119
|
-
**Returns**: `Bytes` (binary) or `string` depending on the encoding parameter.
|
|
120
|
-
|
|
121
|
-
#### `FileSystem.remove(targetPath)`
|
|
122
|
-
|
|
123
|
-
Delete a file or directory. Directories are removed recursively.
|
|
75
|
+
### 스토리지 경로 조회
|
|
124
76
|
|
|
125
77
|
```typescript
|
|
126
|
-
|
|
78
|
+
const path = await FileSystem.getStoragePath("external"); // string
|
|
127
79
|
```
|
|
128
80
|
|
|
129
|
-
|
|
|
130
|
-
|
|
131
|
-
| `
|
|
81
|
+
| 타입 | Android 경로 | 설명 |
|
|
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()` | 앱 캐시 디렉토리 |
|
|
132
90
|
|
|
133
|
-
|
|
91
|
+
Web 환경에서는 `/webfs/{type}` 가상 경로를 반환한다.
|
|
134
92
|
|
|
135
|
-
|
|
93
|
+
### FileProvider URI
|
|
136
94
|
|
|
137
|
-
|
|
138
|
-
static async mkdir(targetPath: string): Promise<void>
|
|
139
|
-
```
|
|
140
|
-
|
|
141
|
-
| Parameter | Type | Description |
|
|
142
|
-
|-----------|------|-------------|
|
|
143
|
-
| `targetPath` | `string` | Absolute path to the directory |
|
|
144
|
-
|
|
145
|
-
#### `FileSystem.exists(targetPath)`
|
|
146
|
-
|
|
147
|
-
Check whether a file or directory exists.
|
|
95
|
+
파일의 `content://` URI를 얻는다. APK 설치 등 인텐트에 파일을 전달할 때 사용한다.
|
|
148
96
|
|
|
149
97
|
```typescript
|
|
150
|
-
|
|
98
|
+
const uri = await FileSystem.getUri("/path/to/file.apk");
|
|
99
|
+
// content://{applicationId}.filesystem.provider/...
|
|
151
100
|
```
|
|
152
101
|
|
|
153
|
-
|
|
154
|
-
|-----------|------|-------------|
|
|
155
|
-
| `targetPath` | `string` | Absolute path to check |
|
|
102
|
+
## API 레퍼런스
|
|
156
103
|
|
|
157
|
-
|
|
104
|
+
### `FileSystem` (abstract class, static 메서드)
|
|
158
105
|
|
|
159
|
-
|
|
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>` | 존재 여부 확인 |
|
|
160
119
|
|
|
161
|
-
### `StorageType`
|
|
120
|
+
### `StorageType` (type alias)
|
|
162
121
|
|
|
163
122
|
```typescript
|
|
164
123
|
type StorageType =
|
|
165
|
-
| "external"
|
|
166
|
-
| "externalFiles"
|
|
167
|
-
| "externalCache"
|
|
168
|
-
| "externalMedia"
|
|
169
|
-
| "appData"
|
|
170
|
-
| "appFiles"
|
|
171
|
-
| "appCache";
|
|
124
|
+
| "external"
|
|
125
|
+
| "externalFiles"
|
|
126
|
+
| "externalCache"
|
|
127
|
+
| "externalMedia"
|
|
128
|
+
| "appData"
|
|
129
|
+
| "appFiles"
|
|
130
|
+
| "appCache";
|
|
172
131
|
```
|
|
173
132
|
|
|
174
|
-
### `FileInfo`
|
|
133
|
+
### `FileInfo` (interface)
|
|
175
134
|
|
|
176
135
|
```typescript
|
|
177
136
|
interface FileInfo {
|
|
178
|
-
name: string; //
|
|
179
|
-
isDirectory: boolean;
|
|
137
|
+
name: string; // 파일/디렉토리 이름
|
|
138
|
+
isDirectory: boolean;
|
|
180
139
|
}
|
|
181
140
|
```
|
|
182
141
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
142
|
+
## 플랫폼 지원
|
|
143
|
+
|
|
144
|
+
| 기능 | Android | Web |
|
|
145
|
+
|------|---------|-----|
|
|
146
|
+
| 파일 읽기/쓰기 | 네이티브 파일시스템 (base64/utf8) | IndexedDB 가상 파일시스템 |
|
|
147
|
+
| 디렉토리 | `java.io.File` API | IndexedDB 기반 가상 경로 |
|
|
148
|
+
| 스토리지 경로 | Android 스토리지 API | `/webfs/{type}` 가상 경로 |
|
|
149
|
+
| FileProvider | `content://` URI 생성 | Blob URL (`URL.createObjectURL`) |
|
|
150
|
+
| 권한 | MANAGE_EXTERNAL_STORAGE / READ+WRITE | 항상 granted |
|
|
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
|
+
- 암묵적 디렉토리 처리: 파일 경로만 저장되어 있어도 중간 경로를 디렉토리로 인식
|
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.87",
|
|
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-
|
|
22
|
-
"@simplysm/core-
|
|
21
|
+
"@simplysm/core-browser": "13.0.87",
|
|
22
|
+
"@simplysm/core-common": "13.0.87"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@capacitor/core": "^7.6.0"
|