@simplysm/capacitor-plugin-usb-storage 13.0.81 → 13.0.83
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 +225 -0
- package/package.json +4 -5
package/README.md
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
# @simplysm/capacitor-plugin-usb-storage
|
|
2
|
+
|
|
3
|
+
Capacitor plugin for reading USB mass storage devices.
|
|
4
|
+
|
|
5
|
+
- **Android**: USB Mass Storage access via the libaums library
|
|
6
|
+
- **Browser**: IndexedDB-based virtual USB storage emulation (for development/testing)
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @simplysm/capacitor-plugin-usb-storage
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
### Peer Dependencies
|
|
15
|
+
|
|
16
|
+
| Package | Version |
|
|
17
|
+
|---------|---------|
|
|
18
|
+
| `@capacitor/core` | `^7.4.4` |
|
|
19
|
+
|
|
20
|
+
## API Reference
|
|
21
|
+
|
|
22
|
+
### `UsbStorage` (static class)
|
|
23
|
+
|
|
24
|
+
The main entry point. All methods are static and return Promises.
|
|
25
|
+
|
|
26
|
+
#### `UsbStorage.getDevices()`
|
|
27
|
+
|
|
28
|
+
Get a list of connected USB devices.
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
const devices: UsbDeviceInfo[] = await UsbStorage.getDevices();
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
**Returns:** `Promise<UsbDeviceInfo[]>`
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
#### `UsbStorage.requestPermissions(filter)`
|
|
39
|
+
|
|
40
|
+
Request access permission for a USB device.
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
const granted: boolean = await UsbStorage.requestPermissions({
|
|
44
|
+
vendorId: 0x1234,
|
|
45
|
+
productId: 0x5678,
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
| Parameter | Type | Description |
|
|
50
|
+
|-----------|------|-------------|
|
|
51
|
+
| `filter` | `UsbDeviceFilter` | Target device vendor/product IDs |
|
|
52
|
+
|
|
53
|
+
**Returns:** `Promise<boolean>` -- `true` if permission was granted.
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
#### `UsbStorage.checkPermissions(filter)`
|
|
58
|
+
|
|
59
|
+
Check whether access permission is already granted for a USB device.
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
const hasPermission: boolean = await UsbStorage.checkPermissions({
|
|
63
|
+
vendorId: 0x1234,
|
|
64
|
+
productId: 0x5678,
|
|
65
|
+
});
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
| Parameter | Type | Description |
|
|
69
|
+
|-----------|------|-------------|
|
|
70
|
+
| `filter` | `UsbDeviceFilter` | Target device vendor/product IDs |
|
|
71
|
+
|
|
72
|
+
**Returns:** `Promise<boolean>` -- `true` if permission is held.
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
#### `UsbStorage.readdir(filter, dirPath)`
|
|
77
|
+
|
|
78
|
+
Read directory contents from a USB storage device.
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
const files: UsbFileInfo[] = await UsbStorage.readdir(
|
|
82
|
+
{ vendorId: 0x1234, productId: 0x5678 },
|
|
83
|
+
"/Documents",
|
|
84
|
+
);
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
| Parameter | Type | Description |
|
|
88
|
+
|-----------|------|-------------|
|
|
89
|
+
| `filter` | `UsbDeviceFilter` | Target device vendor/product IDs |
|
|
90
|
+
| `dirPath` | `string` | Directory path to read |
|
|
91
|
+
|
|
92
|
+
**Returns:** `Promise<UsbFileInfo[]>`
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
#### `UsbStorage.readFile(filter, filePath)`
|
|
97
|
+
|
|
98
|
+
Read a file from a USB storage device. Returns the file contents as `Bytes`, or `undefined` if the file was not found.
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
import type { Bytes } from "@simplysm/core-common";
|
|
102
|
+
|
|
103
|
+
const data: Bytes | undefined = await UsbStorage.readFile(
|
|
104
|
+
{ vendorId: 0x1234, productId: 0x5678 },
|
|
105
|
+
"/Documents/report.pdf",
|
|
106
|
+
);
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
| Parameter | Type | Description |
|
|
110
|
+
|-----------|------|-------------|
|
|
111
|
+
| `filter` | `UsbDeviceFilter` | Target device vendor/product IDs |
|
|
112
|
+
| `filePath` | `string` | File path to read |
|
|
113
|
+
|
|
114
|
+
**Returns:** `Promise<Bytes | undefined>`
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
### Interfaces
|
|
119
|
+
|
|
120
|
+
#### `UsbDeviceInfo`
|
|
121
|
+
|
|
122
|
+
Information about a connected USB device.
|
|
123
|
+
|
|
124
|
+
```ts
|
|
125
|
+
interface UsbDeviceInfo {
|
|
126
|
+
deviceName: string;
|
|
127
|
+
manufacturerName: string;
|
|
128
|
+
productName: string;
|
|
129
|
+
vendorId: number;
|
|
130
|
+
productId: number;
|
|
131
|
+
}
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
#### `UsbDeviceFilter`
|
|
135
|
+
|
|
136
|
+
Filter used to identify a specific USB device by vendor and product ID.
|
|
137
|
+
|
|
138
|
+
```ts
|
|
139
|
+
interface UsbDeviceFilter {
|
|
140
|
+
vendorId: number;
|
|
141
|
+
productId: number;
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
#### `UsbFileInfo`
|
|
146
|
+
|
|
147
|
+
Information about a file or directory on the USB device.
|
|
148
|
+
|
|
149
|
+
```ts
|
|
150
|
+
interface UsbFileInfo {
|
|
151
|
+
name: string;
|
|
152
|
+
isDirectory: boolean;
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
---
|
|
157
|
+
|
|
158
|
+
### `UsbStoragePlugin` (low-level interface)
|
|
159
|
+
|
|
160
|
+
The raw Capacitor plugin interface. Prefer using the `UsbStorage` static class instead.
|
|
161
|
+
|
|
162
|
+
```ts
|
|
163
|
+
interface UsbStoragePlugin {
|
|
164
|
+
getDevices(): Promise<{ devices: UsbDeviceInfo[] }>;
|
|
165
|
+
requestPermissions(options: UsbDeviceFilter): Promise<{ granted: boolean }>;
|
|
166
|
+
checkPermissions(options: UsbDeviceFilter): Promise<{ granted: boolean }>;
|
|
167
|
+
readdir(options: UsbDeviceFilter & { path: string }): Promise<{ files: UsbFileInfo[] }>;
|
|
168
|
+
readFile(options: UsbDeviceFilter & { path: string }): Promise<{ data: string | null }>;
|
|
169
|
+
}
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
## Web Platform (Virtual USB Storage)
|
|
175
|
+
|
|
176
|
+
On the web platform, the plugin uses an IndexedDB-backed virtual file system for development and testing. The `UsbStorageWeb` class exposes additional helper methods to set up virtual devices and files.
|
|
177
|
+
|
|
178
|
+
### `UsbStorageWeb.addVirtualDevice(device)`
|
|
179
|
+
|
|
180
|
+
Register a virtual USB device.
|
|
181
|
+
|
|
182
|
+
```ts
|
|
183
|
+
await web.addVirtualDevice({
|
|
184
|
+
vendorId: 0x1234,
|
|
185
|
+
productId: 0x5678,
|
|
186
|
+
deviceName: "Virtual USB",
|
|
187
|
+
manufacturerName: "Test",
|
|
188
|
+
productName: "Virtual Drive",
|
|
189
|
+
});
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### `UsbStorageWeb.addVirtualFile(filter, filePath, data)`
|
|
193
|
+
|
|
194
|
+
Add a file to a virtual USB device.
|
|
195
|
+
|
|
196
|
+
```ts
|
|
197
|
+
const content = new TextEncoder().encode("hello");
|
|
198
|
+
await web.addVirtualFile(
|
|
199
|
+
{ vendorId: 0x1234, productId: 0x5678 },
|
|
200
|
+
"/docs/readme.txt",
|
|
201
|
+
content,
|
|
202
|
+
);
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
| Parameter | Type | Description |
|
|
206
|
+
|-----------|------|-------------|
|
|
207
|
+
| `filter` | `UsbDeviceFilter` | Target virtual device |
|
|
208
|
+
| `filePath` | `string` | File path on the virtual device |
|
|
209
|
+
| `data` | `Uint8Array` | File contents |
|
|
210
|
+
|
|
211
|
+
### `UsbStorageWeb.addVirtualDirectory(filter, dirPath)`
|
|
212
|
+
|
|
213
|
+
Create a directory on a virtual USB device.
|
|
214
|
+
|
|
215
|
+
```ts
|
|
216
|
+
await web.addVirtualDirectory(
|
|
217
|
+
{ vendorId: 0x1234, productId: 0x5678 },
|
|
218
|
+
"/docs/reports",
|
|
219
|
+
);
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
| Parameter | Type | Description |
|
|
223
|
+
|-----------|------|-------------|
|
|
224
|
+
| `filter` | `UsbDeviceFilter` | Target virtual device |
|
|
225
|
+
| `dirPath` | `string` | Directory path to create |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simplysm/capacitor-plugin-usb-storage",
|
|
3
|
-
"version": "13.0.
|
|
3
|
+
"version": "13.0.83",
|
|
4
4
|
"description": "Simplysm Package - Capacitor USB Storage Plugin",
|
|
5
5
|
"author": "simplysm",
|
|
6
6
|
"license": "MIT",
|
|
@@ -15,12 +15,11 @@
|
|
|
15
15
|
"files": [
|
|
16
16
|
"dist",
|
|
17
17
|
"src",
|
|
18
|
-
"android"
|
|
19
|
-
"docs"
|
|
18
|
+
"android"
|
|
20
19
|
],
|
|
21
20
|
"dependencies": {
|
|
22
|
-
"@simplysm/core-browser": "13.0.
|
|
23
|
-
"@simplysm/core-common": "13.0.
|
|
21
|
+
"@simplysm/core-browser": "13.0.83",
|
|
22
|
+
"@simplysm/core-common": "13.0.83"
|
|
24
23
|
},
|
|
25
24
|
"devDependencies": {
|
|
26
25
|
"@capacitor/core": "^7.6.0"
|