thegecko / webusb

Node.js implementation of the WebUSB Specification
https://thegecko.github.io/webusb/
MIT License
183 stars 27 forks source link

bufferSourceToBuffer would remove the byteOffset and length information #31

Closed qazwsxedcrfvtg14 closed 5 years ago

qazwsxedcrfvtg14 commented 5 years ago

bufferSourceToBuffer in src/adapter.ts would remove the byteOffset and length information from data.

For example:

const buffer = new ArrayBuffer(16);
const array = new Uint8Array(buffer,4,8);
console.log(array.byteLength); // output: 8
console.log(array.buffer.byteLength); // output: 16

bufferSource.buffer would return the original buffer, and that is not the right data to transfer. It should transfer the data with the correct offset and length.