@simplysm/capacitor-plugin-usb-storage 14.0.4 → 14.0.6
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 +70 -34
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
# @simplysm/capacitor-plugin-usb-storage
|
|
2
2
|
|
|
3
|
-
Capacitor USB mass storage
|
|
3
|
+
Capacitor plugin for accessing USB mass storage devices on Android.
|
|
4
|
+
|
|
5
|
+
- **Android**: USB Mass Storage access via the libaums library
|
|
6
|
+
- **Browser**: IndexedDB-based virtual USB storage emulation for development
|
|
4
7
|
|
|
5
8
|
## Installation
|
|
6
9
|
|
|
@@ -10,7 +13,7 @@ npm install @simplysm/capacitor-plugin-usb-storage
|
|
|
10
13
|
|
|
11
14
|
## API Overview
|
|
12
15
|
|
|
13
|
-
###
|
|
16
|
+
### Interfaces
|
|
14
17
|
|
|
15
18
|
| API | Type | Description |
|
|
16
19
|
|-----|------|-------------|
|
|
@@ -18,14 +21,27 @@ npm install @simplysm/capacitor-plugin-usb-storage
|
|
|
18
21
|
| `UsbDeviceFilter` | Interface | Vendor/product ID pair used to target a specific USB device |
|
|
19
22
|
| `UsbFileInfo` | Interface | File entry metadata from a USB storage directory listing |
|
|
20
23
|
| `UsbStoragePlugin` | Interface | Native plugin interface for USB storage operations |
|
|
21
|
-
| `UsbStorage` | Class | Static API for USB mass storage access |
|
|
22
24
|
|
|
23
|
-
|
|
25
|
+
### Classes
|
|
24
26
|
|
|
25
|
-
|
|
27
|
+
| API | Type | Description |
|
|
28
|
+
|-----|------|-------------|
|
|
29
|
+
| `UsbStorage` | Class | Static API for USB mass storage access |
|
|
30
|
+
|
|
31
|
+
## `UsbDeviceInfo`
|
|
26
32
|
|
|
27
33
|
Metadata about a connected USB mass storage device.
|
|
28
34
|
|
|
35
|
+
```typescript
|
|
36
|
+
interface UsbDeviceInfo {
|
|
37
|
+
deviceName: string;
|
|
38
|
+
manufacturerName: string;
|
|
39
|
+
productName: string;
|
|
40
|
+
vendorId: number;
|
|
41
|
+
productId: number;
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
29
45
|
| Field | Type | Description |
|
|
30
46
|
|-------|------|-------------|
|
|
31
47
|
| `deviceName` | `string` | System-assigned device name |
|
|
@@ -34,27 +50,51 @@ Metadata about a connected USB mass storage device.
|
|
|
34
50
|
| `vendorId` | `number` | USB vendor ID |
|
|
35
51
|
| `productId` | `number` | USB product ID |
|
|
36
52
|
|
|
37
|
-
|
|
53
|
+
## `UsbDeviceFilter`
|
|
38
54
|
|
|
39
55
|
Identifies a specific USB device by its vendor and product IDs. Used as a parameter for all device-specific operations.
|
|
40
56
|
|
|
57
|
+
```typescript
|
|
58
|
+
interface UsbDeviceFilter {
|
|
59
|
+
vendorId: number;
|
|
60
|
+
productId: number;
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
41
64
|
| Field | Type | Description |
|
|
42
65
|
|-------|------|-------------|
|
|
43
66
|
| `vendorId` | `number` | USB vendor ID of the target device |
|
|
44
67
|
| `productId` | `number` | USB product ID of the target device |
|
|
45
68
|
|
|
46
|
-
|
|
69
|
+
## `UsbFileInfo`
|
|
47
70
|
|
|
48
71
|
Metadata for a single file or directory entry on a USB storage device.
|
|
49
72
|
|
|
73
|
+
```typescript
|
|
74
|
+
interface UsbFileInfo {
|
|
75
|
+
name: string;
|
|
76
|
+
isDirectory: boolean;
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
50
80
|
| Field | Type | Description |
|
|
51
81
|
|-------|------|-------------|
|
|
52
82
|
| `name` | `string` | Name of the file or directory |
|
|
53
83
|
| `isDirectory` | `boolean` | `true` if the entry is a directory |
|
|
54
84
|
|
|
55
|
-
|
|
85
|
+
## `UsbStoragePlugin`
|
|
86
|
+
|
|
87
|
+
Native plugin interface for USB storage operations. Use the `UsbStorage` class for a simplified API.
|
|
56
88
|
|
|
57
|
-
|
|
89
|
+
```typescript
|
|
90
|
+
interface UsbStoragePlugin {
|
|
91
|
+
getDevices(): Promise<{ devices: UsbDeviceInfo[] }>;
|
|
92
|
+
requestPermissions(options: UsbDeviceFilter): Promise<{ granted: boolean }>;
|
|
93
|
+
checkPermissions(options: UsbDeviceFilter): Promise<{ granted: boolean }>;
|
|
94
|
+
readdir(options: UsbDeviceFilter & { path: string }): Promise<{ files: UsbFileInfo[] }>;
|
|
95
|
+
readFile(options: UsbDeviceFilter & { path: string }): Promise<{ data: string | null }>;
|
|
96
|
+
}
|
|
97
|
+
```
|
|
58
98
|
|
|
59
99
|
| Method | Signature | Description |
|
|
60
100
|
|--------|-----------|-------------|
|
|
@@ -64,13 +104,19 @@ Native plugin interface for USB storage operations.
|
|
|
64
104
|
| `readdir` | `(options: UsbDeviceFilter & { path: string }) => Promise<{ files: UsbFileInfo[] }>` | List files in a directory on the USB device |
|
|
65
105
|
| `readFile` | `(options: UsbDeviceFilter & { path: string }) => Promise<{ data: string \| null }>` | Read a file from the USB device as a base64 string |
|
|
66
106
|
|
|
67
|
-
##
|
|
107
|
+
## `UsbStorage`
|
|
68
108
|
|
|
69
|
-
|
|
109
|
+
Abstract class with static methods for USB storage operations. On Android it uses the libaums library for direct USB communication. On the browser it falls back to IndexedDB-based virtual USB storage emulation.
|
|
70
110
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
111
|
+
```typescript
|
|
112
|
+
abstract class UsbStorage {
|
|
113
|
+
static async getDevices(): Promise<UsbDeviceInfo[]>;
|
|
114
|
+
static async requestPermissions(filter: UsbDeviceFilter): Promise<boolean>;
|
|
115
|
+
static async checkPermissions(filter: UsbDeviceFilter): Promise<boolean>;
|
|
116
|
+
static async readdir(filter: UsbDeviceFilter, dirPath: string): Promise<UsbFileInfo[]>;
|
|
117
|
+
static async readFile(filter: UsbDeviceFilter, filePath: string): Promise<Bytes | undefined>;
|
|
118
|
+
}
|
|
119
|
+
```
|
|
74
120
|
|
|
75
121
|
| Method | Signature | Description |
|
|
76
122
|
|--------|-----------|-------------|
|
|
@@ -78,19 +124,19 @@ All methods are static.
|
|
|
78
124
|
| `requestPermissions` | `static async requestPermissions(filter: UsbDeviceFilter): Promise<boolean>` | Request permission to access the specified USB device. Returns `true` if granted. |
|
|
79
125
|
| `checkPermissions` | `static async checkPermissions(filter: UsbDeviceFilter): Promise<boolean>` | Check if permission is granted for the specified USB device |
|
|
80
126
|
| `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
|
|
127
|
+
| `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 data is null. |
|
|
82
128
|
|
|
83
129
|
## Usage Examples
|
|
84
130
|
|
|
85
131
|
### Discover and access a USB device
|
|
86
132
|
|
|
87
|
-
```
|
|
133
|
+
```typescript
|
|
88
134
|
import { UsbStorage } from "@simplysm/capacitor-plugin-usb-storage";
|
|
89
135
|
|
|
90
136
|
// List connected USB devices
|
|
91
137
|
const devices = await UsbStorage.getDevices();
|
|
92
138
|
if (devices.length === 0) {
|
|
93
|
-
|
|
139
|
+
return; // No USB devices connected
|
|
94
140
|
}
|
|
95
141
|
|
|
96
142
|
const device = devices[0];
|
|
@@ -99,27 +145,17 @@ const filter = { vendorId: device.vendorId, productId: device.productId };
|
|
|
99
145
|
// Request permission
|
|
100
146
|
const granted = await UsbStorage.requestPermissions(filter);
|
|
101
147
|
if (!granted) {
|
|
102
|
-
|
|
148
|
+
return; // Permission denied
|
|
103
149
|
}
|
|
104
150
|
|
|
105
151
|
// List root directory
|
|
106
152
|
const files = await UsbStorage.readdir(filter, "/");
|
|
107
153
|
for (const file of files) {
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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);
|
|
154
|
+
if (!file.isDirectory) {
|
|
155
|
+
const data = await UsbStorage.readFile(filter, `/${file.name}`);
|
|
156
|
+
if (data !== undefined) {
|
|
157
|
+
// process binary data
|
|
158
|
+
}
|
|
159
|
+
}
|
|
124
160
|
}
|
|
125
161
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simplysm/capacitor-plugin-usb-storage",
|
|
3
|
-
"version": "14.0.
|
|
3
|
+
"version": "14.0.6",
|
|
4
4
|
"description": "심플리즘 패키지 - Capacitor USB 저장소 플러그인",
|
|
5
5
|
"author": "심플리즘",
|
|
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-browser": "14.0.6",
|
|
22
|
+
"@simplysm/core-common": "14.0.6"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@capacitor/core": "^7.6.1"
|