Open skratchdot opened 8 years ago
In case anyone is reading, here's the patch I'm using in my tests:
global.FileReader = function () {
const reader = new FileReader();
const originalAddEventListener = reader.addEventListener;
reader.addEventListener = function (on, callback) {
originalAddEventListener(on, (event) => {
// convert Uint8Array to ArrayBuffer
if (on === 'load' && event && event.target &&
event.target.result && event.target.result.buffer) {
event.target.result = toArrayBuffer(event.target.result.buffer);
}
callback(event);
});
};
return reader;
};
This is not a great monkey patch because it only works for people using readAsArrayBuffer() with a 'load' event listener...
@coolaj86 - Let me know if you want me to submit a PR. I have a workaround, so it's no big deal for me, but figured I'd log something in case anyone else has a similar issue...
I have some browser code that does:
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:
https://github.com/node-file-api/FileReader/blob/805a7b0f2db34f4d00c696068d1ce7c3c022e62a/FileReader.js#L42-L44
Can be changed to:
And the following function needs to be included: