node-raspberrypi-usbboot
Advanced tools
Comparing version 0.0.10 to 0.0.11-chunk-transfers-b9107bec86a99f9f49627b4091fcf7dc43bffb9b
"use strict"; | ||
/* | ||
* This work is heavily based on https://github.com/raspberrypi/usbboot | ||
* Copyright 2016 Raspberry Pi Foundation | ||
*/ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -15,3 +11,6 @@ return new (P || (P = Promise))(function (resolve, reject) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const async_mutex_1 = require("async-mutex"); | ||
/* | ||
* This work is heavily based on https://github.com/raspberrypi/usbboot | ||
* Copyright 2016 Raspberry Pi Foundation | ||
*/ | ||
const bluebird_1 = require("bluebird"); | ||
@@ -23,5 +22,5 @@ const _debug = require("debug"); | ||
const usb = require("usb"); | ||
const mutex = new async_mutex_1.Mutex(); | ||
const readFile = bluebird_1.promisify(fs_1.readFile); | ||
const debug = _debug('node-raspberrypi-usbboot'); | ||
const TRANSFER_BLOCK_SIZE = Math.pow(1024, 2); | ||
// The equivalent of a NULL buffer, given that node-usb complains | ||
@@ -180,11 +179,16 @@ // if the data argument is not an instance of Buffer | ||
}); | ||
function* chunks(buffer, size) { | ||
for (let start = 0; start < buffer.length; start += size) { | ||
yield buffer.slice(start, start + size); | ||
} | ||
} | ||
const epWrite = (buffer, device, endpoint) => __awaiter(this, void 0, void 0, function* () { | ||
const release = yield mutex.acquire(); | ||
yield sendSize(device, buffer.length); | ||
if (buffer.length > 0) { | ||
yield bluebird_1.fromCallback((callback) => { | ||
endpoint.transfer(buffer, callback); | ||
}); | ||
for (const chunk of chunks(buffer, TRANSFER_BLOCK_SIZE)) { | ||
yield bluebird_1.fromCallback((callback) => { | ||
endpoint.transfer(chunk, callback); | ||
}); | ||
} | ||
} | ||
release(); | ||
}); | ||
@@ -191,0 +195,0 @@ const epRead = (device, bytesToRead) => __awaiter(this, void 0, void 0, function* () { |
@@ -7,2 +7,6 @@ # Change Log | ||
## v0.0.11 - 2018-10-19 | ||
* Remove mutex in epWrite [Alexis Svinartchouk] | ||
## v0.0.10 - 2018-10-18 | ||
@@ -9,0 +13,0 @@ |
{ | ||
"name": "node-raspberrypi-usbboot", | ||
"version": "0.0.10", | ||
"version": "0.0.11-chunk-transfers-b9107bec86a99f9f49627b4091fcf7dc43bffb9b", | ||
"description": "Transforms Raspberry Pi Compute Modules and Zeros to mass storage devices.", | ||
@@ -28,3 +28,2 @@ "main": "build/index.js", | ||
"@types/node": "^6.0.112", | ||
"async-mutex": "^0.1.3", | ||
"debug": "^3.1.0", | ||
@@ -31,0 +30,0 @@ "usb": "github:resin-io/node-usb#1.3.5" |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27731387
3
455
- Removedasync-mutex@^0.1.3
- Removedasync-mutex@0.1.4(transitive)