@simplysm/capacitor-plugin-usb-storage 14.0.1 → 14.0.4

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 +125 -0
  2. package/package.json +4 -4
package/README.md ADDED
@@ -0,0 +1,125 @@
1
+ # @simplysm/capacitor-plugin-usb-storage
2
+
3
+ Capacitor USB mass storage plugin using the libaums library on Android.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @simplysm/capacitor-plugin-usb-storage
9
+ ```
10
+
11
+ ## API Overview
12
+
13
+ ### USB Storage
14
+
15
+ | API | Type | Description |
16
+ |-----|------|-------------|
17
+ | `UsbDeviceInfo` | Interface | Metadata about a connected USB mass storage device |
18
+ | `UsbDeviceFilter` | Interface | Vendor/product ID pair used to target a specific USB device |
19
+ | `UsbFileInfo` | Interface | File entry metadata from a USB storage directory listing |
20
+ | `UsbStoragePlugin` | Interface | Native plugin interface for USB storage operations |
21
+ | `UsbStorage` | Class | Static API for USB mass storage access |
22
+
23
+ ## Interfaces
24
+
25
+ ### UsbDeviceInfo
26
+
27
+ Metadata about a connected USB mass storage device.
28
+
29
+ | Field | Type | Description |
30
+ |-------|------|-------------|
31
+ | `deviceName` | `string` | System-assigned device name |
32
+ | `manufacturerName` | `string` | USB device manufacturer name |
33
+ | `productName` | `string` | USB device product name |
34
+ | `vendorId` | `number` | USB vendor ID |
35
+ | `productId` | `number` | USB product ID |
36
+
37
+ ### UsbDeviceFilter
38
+
39
+ Identifies a specific USB device by its vendor and product IDs. Used as a parameter for all device-specific operations.
40
+
41
+ | Field | Type | Description |
42
+ |-------|------|-------------|
43
+ | `vendorId` | `number` | USB vendor ID of the target device |
44
+ | `productId` | `number` | USB product ID of the target device |
45
+
46
+ ### UsbFileInfo
47
+
48
+ Metadata for a single file or directory entry on a USB storage device.
49
+
50
+ | Field | Type | Description |
51
+ |-------|------|-------------|
52
+ | `name` | `string` | Name of the file or directory |
53
+ | `isDirectory` | `boolean` | `true` if the entry is a directory |
54
+
55
+ ### UsbStoragePlugin
56
+
57
+ Native plugin interface for USB storage operations.
58
+
59
+ | Method | Signature | Description |
60
+ |--------|-----------|-------------|
61
+ | `getDevices` | `() => Promise<{ devices: UsbDeviceInfo[] }>` | List all connected USB mass storage devices |
62
+ | `requestPermissions` | `(options: UsbDeviceFilter) => Promise<{ granted: boolean }>` | Request permission to access a specific USB device |
63
+ | `checkPermissions` | `(options: UsbDeviceFilter) => Promise<{ granted: boolean }>` | Check if permission is granted for a specific USB device |
64
+ | `readdir` | `(options: UsbDeviceFilter & { path: string }) => Promise<{ files: UsbFileInfo[] }>` | List files in a directory on the USB device |
65
+ | `readFile` | `(options: UsbDeviceFilter & { path: string }) => Promise<{ data: string \| null }>` | Read a file from the USB device as a base64 string |
66
+
67
+ ## Classes
68
+
69
+ ### UsbStorage
70
+
71
+ USB mass storage access plugin. On Android it uses the libaums library for direct USB communication. On the browser it falls back to IndexedDB-based virtual USB storage emulation.
72
+
73
+ All methods are static.
74
+
75
+ | Method | Signature | Description |
76
+ |--------|-----------|-------------|
77
+ | `getDevices` | `static async getDevices(): Promise<UsbDeviceInfo[]>` | List all connected USB mass storage devices |
78
+ | `requestPermissions` | `static async requestPermissions(filter: UsbDeviceFilter): Promise<boolean>` | Request permission to access the specified USB device. Returns `true` if granted. |
79
+ | `checkPermissions` | `static async checkPermissions(filter: UsbDeviceFilter): Promise<boolean>` | Check if permission is granted for the specified USB device |
80
+ | `readdir` | `static async readdir(filter: UsbDeviceFilter, dirPath: string): Promise<UsbFileInfo[]>` | List files and directories at the given path on the USB device |
81
+ | `readFile` | `static async readFile(filter: UsbDeviceFilter, filePath: string): Promise<Bytes \| undefined>` | Read a file from the USB device. Returns `Bytes` on success, `undefined` if the file does not exist or data is null. |
82
+
83
+ ## Usage Examples
84
+
85
+ ### Discover and access a USB device
86
+
87
+ ```ts
88
+ import { UsbStorage } from "@simplysm/capacitor-plugin-usb-storage";
89
+
90
+ // List connected USB devices
91
+ const devices = await UsbStorage.getDevices();
92
+ if (devices.length === 0) {
93
+ throw new Error("No USB storage device connected");
94
+ }
95
+
96
+ const device = devices[0];
97
+ const filter = { vendorId: device.vendorId, productId: device.productId };
98
+
99
+ // Request permission
100
+ const granted = await UsbStorage.requestPermissions(filter);
101
+ if (!granted) {
102
+ throw new Error("USB permission denied");
103
+ }
104
+
105
+ // List root directory
106
+ const files = await UsbStorage.readdir(filter, "/");
107
+ for (const file of files) {
108
+ console.log(`${file.name} (${file.isDirectory ? "dir" : "file"})`);
109
+ }
110
+ ```
111
+
112
+ ### Read a file from USB storage
113
+
114
+ ```ts
115
+ import { UsbStorage } from "@simplysm/capacitor-plugin-usb-storage";
116
+
117
+ const filter = { vendorId: 0x1234, productId: 0x5678 };
118
+
119
+ const data = await UsbStorage.readFile(filter, "/data/export.csv");
120
+ if (data !== undefined) {
121
+ // Convert Bytes to string for text files
122
+ const text = new TextDecoder().decode(data);
123
+ processCSV(text);
124
+ }
125
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simplysm/capacitor-plugin-usb-storage",
3
- "version": "14.0.1",
3
+ "version": "14.0.4",
4
4
  "description": "심플리즘 패키지 - Capacitor USB 저장소 플러그인",
5
5
  "author": "심플리즘",
6
6
  "license": "Apache-2.0",
@@ -18,11 +18,11 @@
18
18
  "android"
19
19
  ],
20
20
  "dependencies": {
21
- "@simplysm/core-common": "14.0.1",
22
- "@simplysm/core-browser": "14.0.1"
21
+ "@simplysm/core-common": "14.0.4",
22
+ "@simplysm/core-browser": "14.0.4"
23
23
  },
24
24
  "devDependencies": {
25
- "@capacitor/core": "^7.6.0"
25
+ "@capacitor/core": "^7.6.1"
26
26
  },
27
27
  "peerDependencies": {
28
28
  "@capacitor/core": "^7"