-
Notifications
You must be signed in to change notification settings - Fork 9
API Draft
Should be built as a Node (CommonJS) module, so the following should work:
var usbDrive = require('usb-drive');
Support getAll()
(or list()
, or similar); return a promise.
usbDrive.getAll().then(function(devices) {
/* ... do something with devices ... */
}).catch(function(err) { /* ... error handling */ });
devices
should be an array of device objects.
Support get()
(or similar); return a promise.
usbDrive.get(deviceId).then(function(device) {
/* ... do something with device ... */
}).catch(function(err) { /* ... error handling ... */ });
device
should be a device object.
Support unmount()
(or similar); return a promise.
Note that failure (a promise rejection) should only occur if a mounted volume could not be unmounted. If it's already unmounted, the promise should resolve.
usbDrive.unmount(deviceId).then(function() {
/* ... success ... */
}).catch(function(err) { /* ... failure ... */ });
deviceId
should be the id
provided in the device objects from get()
or getAll()
.
usbDrive.on('attach', function(device) { /* ... */ });
device
should be a device object.
Note that this should be emitted before a separate mount
event (if any), as described below. (So, when this is emitted, the device would likely be missing the mount
property.)
usbDrive.on('detach', function(device) { /* ... */ });
device
should be a device object.
When a USB device is mounted.
usbDrive.on('mount', function(device) { /* ... */ });
device
should be a device object.
When a USB device is unmounted.
usbDrive.on('unmount', function(device) { /* ... */ });
device
should be a device object.