I am working on a web application that opens binary files and allows editing them.
This process is basically ondrop -> dataTransfer.files[0] -> FileReader -> Uint8Array
Essentially, I want to save the modified file back as a binary file. Ideal as downloading a file with the specified file name.
There seems to be no standard method for this, and that sucks because everything up to this point is well supported.
I am currently converting an array to a string using String.fromCharCode() , base64 encodings and using the uri of the data in the hyperlink, e.g. data:application/octet-stream;base64,.. , along with the download attribute to indicate the file name.
This seems to work, but it's pretty hacky, and I think converting raw bytes to strings can lead to encoding problems depending on the byte values. I do not want the data to become corrupted or break the line.
If this is not the case, is there a better / correct method for getting an array of bytes as a binary for the user?
javascript cross-browser binary-data file-io typed-arrays
bryc
source share