@simplysm/capacitor-plugin-usb-storage 13.0.72 → 13.0.75
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 +146 -9
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -2,21 +2,158 @@
|
|
|
2
2
|
|
|
3
3
|
Simplysm Package - Capacitor USB Storage Plugin
|
|
4
4
|
|
|
5
|
+
Provides access to USB Mass Storage devices from a Capacitor application.
|
|
6
|
+
|
|
7
|
+
- **Android**: USB Mass Storage access via the libaums library.
|
|
8
|
+
- **Browser**: IndexedDB-based virtual USB storage emulation for development.
|
|
9
|
+
|
|
5
10
|
## Installation
|
|
6
11
|
|
|
12
|
+
```bash
|
|
7
13
|
pnpm add @simplysm/capacitor-plugin-usb-storage
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Main Modules
|
|
17
|
+
|
|
18
|
+
### UsbStorage
|
|
19
|
+
|
|
20
|
+
An abstract class that exposes static methods for interacting with USB storage devices.
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
import { UsbStorage } from "@simplysm/capacitor-plugin-usb-storage";
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
#### `UsbStorage.getDevices()`
|
|
27
|
+
|
|
28
|
+
Returns a list of currently connected USB devices.
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
static async getDevices(): Promise<IUsbDeviceInfo[]>
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
const devices = await UsbStorage.getDevices();
|
|
36
|
+
for (const device of devices) {
|
|
37
|
+
console.log(device.productName, device.vendorId, device.productId);
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
#### `UsbStorage.requestPermission(filter)`
|
|
42
|
+
|
|
43
|
+
Requests access permission for a specific USB device identified by its vendor and product IDs.
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
static async requestPermission(filter: IUsbDeviceFilter): Promise<boolean>
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
const granted = await UsbStorage.requestPermission({ vendorId: 0x1234, productId: 0x5678 });
|
|
51
|
+
if (granted) {
|
|
52
|
+
console.log("Permission granted");
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
#### `UsbStorage.hasPermission(filter)`
|
|
57
|
+
|
|
58
|
+
Checks whether access permission for a specific USB device is currently held.
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
static async hasPermission(filter: IUsbDeviceFilter): Promise<boolean>
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
const alreadyGranted = await UsbStorage.hasPermission({ vendorId: 0x1234, productId: 0x5678 });
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
#### `UsbStorage.readdir(filter, dirPath)`
|
|
69
|
+
|
|
70
|
+
Reads the contents of a directory on the USB storage device.
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
static async readdir(filter: IUsbDeviceFilter, dirPath: string): Promise<IUsbFileInfo[]>
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
const filter = { vendorId: 0x1234, productId: 0x5678 };
|
|
78
|
+
const entries = await UsbStorage.readdir(filter, "/");
|
|
79
|
+
for (const entry of entries) {
|
|
80
|
+
console.log(entry.name, entry.isDirectory ? "(dir)" : "(file)");
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
#### `UsbStorage.read(filter, filePath)`
|
|
85
|
+
|
|
86
|
+
Reads a file from the USB storage device and returns its contents as `Bytes`. Returns `undefined` if the file does not exist.
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
static async read(filter: IUsbDeviceFilter, filePath: string): Promise<Bytes | undefined>
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
const filter = { vendorId: 0x1234, productId: 0x5678 };
|
|
94
|
+
const bytes = await UsbStorage.read(filter, "/data/file.bin");
|
|
95
|
+
if (bytes !== undefined) {
|
|
96
|
+
console.log("File size:", bytes.length);
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Types
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
import type {
|
|
104
|
+
IUsbDeviceInfo,
|
|
105
|
+
IUsbDeviceFilter,
|
|
106
|
+
IUsbFileInfo,
|
|
107
|
+
IUsbStoragePlugin,
|
|
108
|
+
} from "@simplysm/capacitor-plugin-usb-storage";
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### `IUsbDeviceInfo`
|
|
112
|
+
|
|
113
|
+
Describes a connected USB device.
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
interface IUsbDeviceInfo {
|
|
117
|
+
deviceName: string;
|
|
118
|
+
manufacturerName: string;
|
|
119
|
+
productName: string;
|
|
120
|
+
vendorId: number;
|
|
121
|
+
productId: number;
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### `IUsbDeviceFilter`
|
|
126
|
+
|
|
127
|
+
Identifies a USB device by its vendor and product IDs. Used as a selector in permission and file-system calls.
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
interface IUsbDeviceFilter {
|
|
131
|
+
vendorId: number;
|
|
132
|
+
productId: number;
|
|
133
|
+
}
|
|
134
|
+
```
|
|
8
135
|
|
|
9
|
-
|
|
136
|
+
### `IUsbFileInfo`
|
|
10
137
|
|
|
11
|
-
|
|
138
|
+
Describes a single entry (file or directory) returned by `readdir`.
|
|
12
139
|
|
|
13
|
-
|
|
140
|
+
```typescript
|
|
141
|
+
interface IUsbFileInfo {
|
|
142
|
+
name: string;
|
|
143
|
+
isDirectory: boolean;
|
|
144
|
+
}
|
|
145
|
+
```
|
|
14
146
|
|
|
15
|
-
|
|
16
|
-
|--------|---------|-------------|------|
|
|
17
|
-
| `src/IUsbStoragePlugin.ts` | `IUsbDeviceInfo`, `IUsbDeviceFilter`, `IUsbFileInfo`, `IUsbStoragePlugin` | Interfaces for USB device info, file info, filters, and the native plugin contract | - |
|
|
18
|
-
| `src/UsbStorage.ts` | `UsbStorage` | Static class to enumerate USB devices, manage permissions, and read files | - |
|
|
147
|
+
### `IUsbStoragePlugin`
|
|
19
148
|
|
|
20
|
-
|
|
149
|
+
The raw Capacitor plugin interface registered under the `"UsbStorage"` plugin name. Prefer using the `UsbStorage` abstract class instead of calling this interface directly.
|
|
21
150
|
|
|
22
|
-
|
|
151
|
+
```typescript
|
|
152
|
+
interface IUsbStoragePlugin {
|
|
153
|
+
getDevices(): Promise<{ devices: IUsbDeviceInfo[] }>;
|
|
154
|
+
requestPermission(options: IUsbDeviceFilter): Promise<{ granted: boolean }>;
|
|
155
|
+
hasPermission(options: IUsbDeviceFilter): Promise<{ granted: boolean }>;
|
|
156
|
+
readdir(options: IUsbDeviceFilter & { path: string }): Promise<{ files: IUsbFileInfo[] }>;
|
|
157
|
+
read(options: IUsbDeviceFilter & { path: string }): Promise<{ data: string | null }>;
|
|
158
|
+
}
|
|
159
|
+
```
|
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.75",
|
|
4
4
|
"description": "Simplysm Package - Capacitor USB Storage Plugin",
|
|
5
5
|
"author": "simplysm",
|
|
6
6
|
"license": "MIT",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"android"
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@simplysm/core-common": "13.0.
|
|
21
|
+
"@simplysm/core-common": "13.0.75"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@capacitor/core": "^7.5.0"
|