@simplysm/capacitor-plugin-usb-storage 12.16.30 → 12.16.35

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 +153 -0
  2. package/package.json +2 -2
package/README.md ADDED
@@ -0,0 +1,153 @@
1
+ # @simplysm/capacitor-plugin-usb-storage
2
+
3
+ Capacitor USB Storage Plugin -- USB mass storage device interaction for Android. Enumerate connected USB devices, manage access permissions, read directories, and read files from USB mass storage devices using the libaums library. Falls back to alert-based stubs on browser.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @simplysm/capacitor-plugin-usb-storage
9
+ ```
10
+
11
+ ## API Overview
12
+
13
+ | API | Type | Description |
14
+ |-----|------|-------------|
15
+ | `UsbStorage` | Abstract class | Static methods for USB mass storage device interaction |
16
+ | `IUsbDeviceInfo` | Interface | USB device information (name, manufacturer, IDs) |
17
+ | `IUsbDeviceFilter` | Interface | Filter to identify a USB device by vendor/product ID |
18
+ | `IUsbStoragePlugin` | Interface | Low-level Capacitor plugin interface for USB storage operations |
19
+
20
+ ## API Reference
21
+
22
+ ### `IUsbDeviceInfo`
23
+
24
+ Information about a connected USB device.
25
+
26
+ ```typescript
27
+ export interface IUsbDeviceInfo {
28
+ deviceName: string;
29
+ manufacturerName: string;
30
+ productName: string;
31
+ vendorId: number;
32
+ productId: number;
33
+ }
34
+ ```
35
+
36
+ | Field | Type | Description |
37
+ |-------|------|-------------|
38
+ | `deviceName` | `string` | System device name |
39
+ | `manufacturerName` | `string` | USB device manufacturer name |
40
+ | `productName` | `string` | USB device product name |
41
+ | `vendorId` | `number` | USB vendor ID |
42
+ | `productId` | `number` | USB product ID |
43
+
44
+ ### `IUsbDeviceFilter`
45
+
46
+ Filter used to identify a specific USB device by its vendor and product IDs.
47
+
48
+ ```typescript
49
+ export interface IUsbDeviceFilter {
50
+ vendorId: number;
51
+ productId: number;
52
+ }
53
+ ```
54
+
55
+ | Field | Type | Description |
56
+ |-------|------|-------------|
57
+ | `vendorId` | `number` | USB vendor ID to match |
58
+ | `productId` | `number` | USB product ID to match |
59
+
60
+ ### `IUsbStoragePlugin`
61
+
62
+ Low-level Capacitor plugin interface. Use `UsbStorage` instead for a simplified API.
63
+
64
+ ```typescript
65
+ export interface IUsbStoragePlugin {
66
+ getDevices(): Promise<{ devices: IUsbDeviceInfo[] }>;
67
+ requestPermission(options: IUsbDeviceFilter): Promise<{ granted: boolean }>;
68
+ hasPermission(options: IUsbDeviceFilter): Promise<{ granted: boolean }>;
69
+ readdir(options: IUsbDeviceFilter & { path: string }): Promise<{ files: string[] }>;
70
+ read(options: IUsbDeviceFilter & { path: string }): Promise<{ data: string | null }>;
71
+ }
72
+ ```
73
+
74
+ | Method | Parameters | Returns | Description |
75
+ |--------|------------|---------|-------------|
76
+ | `getDevices` | -- | `Promise<{ devices: IUsbDeviceInfo[] }>` | List connected USB devices |
77
+ | `requestPermission` | `options: IUsbDeviceFilter` | `Promise<{ granted: boolean }>` | Request access permission for a USB device |
78
+ | `hasPermission` | `options: IUsbDeviceFilter` | `Promise<{ granted: boolean }>` | Check if permission is granted for a USB device |
79
+ | `readdir` | `options: IUsbDeviceFilter & { path }` | `Promise<{ files: string[] }>` | List files in a directory on the USB device |
80
+ | `read` | `options: IUsbDeviceFilter & { path }` | `Promise<{ data: string \| null }>` | Read a file from the USB device as base64 |
81
+
82
+ ### `UsbStorage`
83
+
84
+ Abstract class with static methods for USB mass storage device interaction.
85
+
86
+ - **Android**: Uses libaums library for USB Mass Storage access
87
+ - **Browser**: Shows alert and returns empty values
88
+
89
+ ```typescript
90
+ export abstract class UsbStorage {
91
+ static async getDevices(): Promise<IUsbDeviceInfo[]>;
92
+ static async requestPermission(filter: { vendorId: number; productId: number }): Promise<boolean>;
93
+ static async hasPermission(filter: { vendorId: number; productId: number }): Promise<boolean>;
94
+ static async readdir(
95
+ filter: { vendorId: number; productId: number },
96
+ dirPath: string,
97
+ ): Promise<string[]>;
98
+ static async read(
99
+ filter: { vendorId: number; productId: number },
100
+ filePath: string,
101
+ ): Promise<Buffer | undefined>;
102
+ }
103
+ ```
104
+
105
+ | Method | Parameters | Returns | Description |
106
+ |--------|------------|---------|-------------|
107
+ | `getDevices` | -- | `Promise<IUsbDeviceInfo[]>` | Get a list of connected USB storage devices |
108
+ | `requestPermission` | `filter: { vendorId: number; productId: number }` | `Promise<boolean>` | Request access permission for a USB device; returns whether permission was granted |
109
+ | `hasPermission` | `filter: { vendorId: number; productId: number }` | `Promise<boolean>` | Check if access permission is granted for a USB device |
110
+ | `readdir` | `filter: { vendorId, productId }, dirPath: string` | `Promise<string[]>` | List file and directory names in a directory on the USB device |
111
+ | `read` | `filter: { vendorId, productId }, filePath: string` | `Promise<Buffer \| undefined>` | Read a file from the USB device as a Buffer; returns `undefined` if data is null |
112
+
113
+ ## Usage Examples
114
+
115
+ ### List USB devices and read a file
116
+
117
+ ```typescript
118
+ import { UsbStorage } from "@simplysm/capacitor-plugin-usb-storage";
119
+
120
+ // Get connected USB devices
121
+ const devices = await UsbStorage.getDevices();
122
+ if (devices.length === 0) {
123
+ console.log("No USB devices connected");
124
+ return;
125
+ }
126
+
127
+ const device = devices[0];
128
+ console.log(`Found: ${device.productName} by ${device.manufacturerName}`);
129
+
130
+ // Request permission
131
+ const granted = await UsbStorage.requestPermission({
132
+ vendorId: device.vendorId,
133
+ productId: device.productId,
134
+ });
135
+
136
+ if (granted) {
137
+ // List root directory
138
+ const files = await UsbStorage.readdir(
139
+ { vendorId: device.vendorId, productId: device.productId },
140
+ "/",
141
+ );
142
+ console.log("Files:", files);
143
+
144
+ // Read a file
145
+ const data = await UsbStorage.read(
146
+ { vendorId: device.vendorId, productId: device.productId },
147
+ "/data.txt",
148
+ );
149
+ if (data) {
150
+ console.log("Content:", data.toString("utf-8"));
151
+ }
152
+ }
153
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simplysm/capacitor-plugin-usb-storage",
3
- "version": "12.16.30",
3
+ "version": "12.16.35",
4
4
  "description": "심플리즘 패키지 - Capacitor USB Storage Plugin",
5
5
  "author": "김석래",
6
6
  "repository": {
@@ -18,7 +18,7 @@
18
18
  }
19
19
  },
20
20
  "devDependencies": {
21
- "@capacitor/core": "^7.5.0"
21
+ "@capacitor/core": "^7.6.0"
22
22
  },
23
23
  "peerDependencies": {
24
24
  "@capacitor/core": "^7.0.0"