-
Notifications
You must be signed in to change notification settings - Fork 12
Open
Description
I have some browser code that does:
const reader = FileReader();
reader.addEventListener('load', (e) => {
const arrayBuffer = e.target.result;
const view = new DataView(arrayBuffer);
// do some stuff with the view
});
reader.readAsArrayBuffer(file);
When I run my mocha tests in node (making node stubs using the node file-api
package), I see the following error: TypeError: First argument to DataView constructor must be an ArrayBuffer
The fix for this is simple, but I don't know the ramifications for other people that use this library, so I don't know if you want me to submit a pull request or not. Anyways, the following 3 lines:
Lines 42 to 44 in 805a7b0
case 'buffer': | |
return data; | |
break; |
Can be changed to:
case 'buffer':
return toArrayBuffer(data);
break;
And the following function needs to be included:
toArrayBuffer(buffer) {
const ab = new ArrayBuffer(buffer.length);
const view = new Uint8Array(ab);
for (let i = 0; i < buffer.length; ++i) {
view[i] = buffer[i];
}
return ab;
}
Metadata
Metadata
Assignees
Labels
No labels