@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.
Files changed (2) hide show
  1. package/README.md +89 -129
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -1,172 +1,132 @@
1
1
  # @simplysm/capacitor-plugin-file-system
2
2
 
3
- Capacitor 파일시스템 플러그인. Android 네이티브 파일시스템 접근과 Web IndexedDB 기반 가상 파일시스템을 제공한다.
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
- **의존성:** `@simplysm/core-common` (Bytes, bytes 유틸), `@simplysm/core-browser` (IndexedDbStore, IndexedDbVirtualFs)
12
- **Peer:** `@capacitor/core` ^7.4.4
11
+ ## API Overview
13
12
 
14
- ## Export 목록
13
+ ### Types
15
14
 
16
- ```typescript
17
- // index.ts
18
- export { FileSystem } from "./FileSystem";
19
- export type { FileSystemPlugin, FileInfo, StorageType } from "./FileSystemPlugin";
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
- ```typescript
27
- import { FileSystem } from "@simplysm/capacitor-plugin-file-system";
26
+ ### Classes
28
27
 
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
- }
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
- import type { Bytes } from "@simplysm/core-common";
41
-
42
- // 텍스트 파일 쓰기
43
- await FileSystem.writeFile("/storage/emulated/0/test.txt", "Hello World");
44
-
45
- // 바이너리 파일 쓰기 (Bytes = Uint8Array)
46
- const data: Bytes = new Uint8Array([0x48, 0x65, 0x6c, 0x6c, 0x6f]);
47
- await FileSystem.writeFile("/storage/emulated/0/data.bin", data);
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
- `writeFile`은 내부적으로 string이면 utf8, Bytes이면 base64로 인코딩하여 네이티브에 전달한다.
57
-
58
- ### 디렉토리 조작
45
+ ## `FileInfo`
59
46
 
60
47
  ```typescript
61
- // 디렉토리 생성 (재귀)
62
- await FileSystem.mkdir("/storage/emulated/0/myapp/data");
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
- const path = await FileSystem.getStoragePath("external"); // string
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
- | 타입 | 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()` | 앱 캐시 디렉토리 |
71
+ Low-level Capacitor plugin interface. Use `FileSystem` static methods instead of calling this directly.
90
72
 
91
- Web 환경에서는 `/webfs/{type}` 가상 경로를 반환한다.
92
-
93
- ### FileProvider URI
94
-
95
- 파일의 `content://` URI를 얻는다. APK 설치 등 인텐트에 파일을 전달할 때 사용한다.
73
+ ## `FileSystem`
96
74
 
97
75
  ```typescript
98
- const uri = await FileSystem.getUri("/path/to/file.apk");
99
- // content://{applicationId}.filesystem.provider/...
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
- ## API 레퍼런스
103
-
104
- ### `FileSystem` (abstract class, static 메서드)
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
- ### `StorageType` (type alias)
98
+ ### Read and write files
121
99
 
122
100
  ```typescript
123
- type StorageType =
124
- | "external"
125
- | "externalFiles"
126
- | "externalCache"
127
- | "externalMedia"
128
- | "appData"
129
- | "appFiles"
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
- ### `FileInfo` (interface)
110
+ ### List directory contents
134
111
 
135
112
  ```typescript
136
- interface FileInfo {
137
- name: string; // 파일/디렉토리 이름
138
- isDirectory: boolean;
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
- | 기능 | 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
- - 암묵적 디렉토리 처리: 파일 경로만 저장되어 있어도 중간 경로를 디렉토리로 인식
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.96",
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.96",
22
- "@simplysm/core-common": "13.0.96"
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"