@simplysm/capacitor-plugin-usb-storage 14.0.1 → 14.0.5
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 +161 -0
- package/package.json +4 -4
package/README.md
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
# @simplysm/capacitor-plugin-usb-storage
|
|
2
|
+
|
|
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
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @simplysm/capacitor-plugin-usb-storage
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## API Overview
|
|
15
|
+
|
|
16
|
+
### Interfaces
|
|
17
|
+
|
|
18
|
+
| API | Type | Description |
|
|
19
|
+
|-----|------|-------------|
|
|
20
|
+
| `UsbDeviceInfo` | Interface | Metadata about a connected USB mass storage device |
|
|
21
|
+
| `UsbDeviceFilter` | Interface | Vendor/product ID pair used to target a specific USB device |
|
|
22
|
+
| `UsbFileInfo` | Interface | File entry metadata from a USB storage directory listing |
|
|
23
|
+
| `UsbStoragePlugin` | Interface | Native plugin interface for USB storage operations |
|
|
24
|
+
|
|
25
|
+
### Classes
|
|
26
|
+
|
|
27
|
+
| API | Type | Description |
|
|
28
|
+
|-----|------|-------------|
|
|
29
|
+
| `UsbStorage` | Class | Static API for USB mass storage access |
|
|
30
|
+
|
|
31
|
+
## `UsbDeviceInfo`
|
|
32
|
+
|
|
33
|
+
Metadata about a connected USB mass storage device.
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
interface UsbDeviceInfo {
|
|
37
|
+
deviceName: string;
|
|
38
|
+
manufacturerName: string;
|
|
39
|
+
productName: string;
|
|
40
|
+
vendorId: number;
|
|
41
|
+
productId: number;
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
| Field | Type | Description |
|
|
46
|
+
|-------|------|-------------|
|
|
47
|
+
| `deviceName` | `string` | System-assigned device name |
|
|
48
|
+
| `manufacturerName` | `string` | USB device manufacturer name |
|
|
49
|
+
| `productName` | `string` | USB device product name |
|
|
50
|
+
| `vendorId` | `number` | USB vendor ID |
|
|
51
|
+
| `productId` | `number` | USB product ID |
|
|
52
|
+
|
|
53
|
+
## `UsbDeviceFilter`
|
|
54
|
+
|
|
55
|
+
Identifies a specific USB device by its vendor and product IDs. Used as a parameter for all device-specific operations.
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
interface UsbDeviceFilter {
|
|
59
|
+
vendorId: number;
|
|
60
|
+
productId: number;
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
| Field | Type | Description |
|
|
65
|
+
|-------|------|-------------|
|
|
66
|
+
| `vendorId` | `number` | USB vendor ID of the target device |
|
|
67
|
+
| `productId` | `number` | USB product ID of the target device |
|
|
68
|
+
|
|
69
|
+
## `UsbFileInfo`
|
|
70
|
+
|
|
71
|
+
Metadata for a single file or directory entry on a USB storage device.
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
interface UsbFileInfo {
|
|
75
|
+
name: string;
|
|
76
|
+
isDirectory: boolean;
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
| Field | Type | Description |
|
|
81
|
+
|-------|------|-------------|
|
|
82
|
+
| `name` | `string` | Name of the file or directory |
|
|
83
|
+
| `isDirectory` | `boolean` | `true` if the entry is a directory |
|
|
84
|
+
|
|
85
|
+
## `UsbStoragePlugin`
|
|
86
|
+
|
|
87
|
+
Native plugin interface for USB storage operations. Use the `UsbStorage` class for a simplified API.
|
|
88
|
+
|
|
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
|
+
```
|
|
98
|
+
|
|
99
|
+
| Method | Signature | Description |
|
|
100
|
+
|--------|-----------|-------------|
|
|
101
|
+
| `getDevices` | `() => Promise<{ devices: UsbDeviceInfo[] }>` | List all connected USB mass storage devices |
|
|
102
|
+
| `requestPermissions` | `(options: UsbDeviceFilter) => Promise<{ granted: boolean }>` | Request permission to access a specific USB device |
|
|
103
|
+
| `checkPermissions` | `(options: UsbDeviceFilter) => Promise<{ granted: boolean }>` | Check if permission is granted for a specific USB device |
|
|
104
|
+
| `readdir` | `(options: UsbDeviceFilter & { path: string }) => Promise<{ files: UsbFileInfo[] }>` | List files in a directory on the USB device |
|
|
105
|
+
| `readFile` | `(options: UsbDeviceFilter & { path: string }) => Promise<{ data: string \| null }>` | Read a file from the USB device as a base64 string |
|
|
106
|
+
|
|
107
|
+
## `UsbStorage`
|
|
108
|
+
|
|
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.
|
|
110
|
+
|
|
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
|
+
```
|
|
120
|
+
|
|
121
|
+
| Method | Signature | Description |
|
|
122
|
+
|--------|-----------|-------------|
|
|
123
|
+
| `getDevices` | `static async getDevices(): Promise<UsbDeviceInfo[]>` | List all connected USB mass storage devices |
|
|
124
|
+
| `requestPermissions` | `static async requestPermissions(filter: UsbDeviceFilter): Promise<boolean>` | Request permission to access the specified USB device. Returns `true` if granted. |
|
|
125
|
+
| `checkPermissions` | `static async checkPermissions(filter: UsbDeviceFilter): Promise<boolean>` | Check if permission is granted for the specified USB device |
|
|
126
|
+
| `readdir` | `static async readdir(filter: UsbDeviceFilter, dirPath: string): Promise<UsbFileInfo[]>` | List files and directories at the given path on the USB device |
|
|
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. |
|
|
128
|
+
|
|
129
|
+
## Usage Examples
|
|
130
|
+
|
|
131
|
+
### Discover and access a USB device
|
|
132
|
+
|
|
133
|
+
```typescript
|
|
134
|
+
import { UsbStorage } from "@simplysm/capacitor-plugin-usb-storage";
|
|
135
|
+
|
|
136
|
+
// List connected USB devices
|
|
137
|
+
const devices = await UsbStorage.getDevices();
|
|
138
|
+
if (devices.length === 0) {
|
|
139
|
+
return; // No USB devices connected
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const device = devices[0];
|
|
143
|
+
const filter = { vendorId: device.vendorId, productId: device.productId };
|
|
144
|
+
|
|
145
|
+
// Request permission
|
|
146
|
+
const granted = await UsbStorage.requestPermissions(filter);
|
|
147
|
+
if (!granted) {
|
|
148
|
+
return; // Permission denied
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// List root directory
|
|
152
|
+
const files = await UsbStorage.readdir(filter, "/");
|
|
153
|
+
for (const file of files) {
|
|
154
|
+
if (!file.isDirectory) {
|
|
155
|
+
const data = await UsbStorage.readFile(filter, `/${file.name}`);
|
|
156
|
+
if (data !== undefined) {
|
|
157
|
+
// process binary data
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
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.5",
|
|
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-
|
|
22
|
-
"@simplysm/core-
|
|
21
|
+
"@simplysm/core-browser": "14.0.5",
|
|
22
|
+
"@simplysm/core-common": "14.0.5"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@capacitor/core": "^7.6.
|
|
25
|
+
"@capacitor/core": "^7.6.1"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"@capacitor/core": "^7"
|