-
-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for Browser's File Object (i.e. ArrayBuffers/Uint8Array) #292
Comments
Just experimented with what needs to be done to use - const contentChunkUTF8 = buffer.toString(textEncoding, chunkBegin, chunkEnd)
+ const contentChunkUTF8 = new TextDecoder().decode(buffer.subarray(chunkBegin, chunkEnd)); Once that this change was made, a browser could read a file's content like this: const handleChange = (e) => {
const file = e.target.files[0];
const reader = new FileReader();
reader.onload = (e) => {
console.log(getEncoding(new Uint8Array(e.target.result)));
};
reader.readAsArrayBuffer(file);
}
return <input type="file" onChange={handleChange}/> I'm a bit hesitant to turn this into a PR as it's a fairly big architectural decision on how to support those two types in parallel. |
It seems TextDecoder is available in Node.js since Node.js v8: https://nodejs.org/api/util.html#class-utiltextdecoder https://github.com/bevry/boundation does give us the ability to specify say a |
Hi there, I'm working in a browser-only context and would like to see if an uploaded file is a text file or not.
It seems though that the Buffer argument doesn't work with with the browser-based ArrayBuffer or Uint8Array (probably due to calling the
buffer.toString
with additional parameters). I could add a Buffer polyfill to my client code, but it would be nice if the native browser types would be supported as well.The text was updated successfully, but these errors were encountered: