Is it possible to read a file in from a path in JavaScript and create a byte[] of that file?
var bytes = []; var reader = new FileReader(); reader. onload = function () { bytes = reader. result; }; reader. readAsArrayBuffer(myFile);
The byte() function in p5. js is used to convert the given string of number, number value or boolean into its byte representation. This byte number can only be whole number in between -128 to 127.
A byte array is simply an area of memory containing a group of contiguous (side by side) bytes, such that it makes sense to talk about them in order: the first byte, the second byte etc..
Yes, you can — in Firefox, anyway. Other browsers may or may not choose to allow it in the future.
Make a file upload field for the user to pick the file, and read it through the input.files list. eg. document.getElementById('myuploadfield').files[0].getAsBinary()
. This puts each byte in a single character of a JavaScript String, which is about as close to a byte[] as you're going to get.
This is quite a specialized interface and probably Not The Right Thing — heed the other replies, because it's very possible you are trying to do something in a inappropriate way. Difficult to tell without context.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With