1

This is an example file viewed in a hex editor: link I have a binary file on my computer that I want to upload and store as a JavaScript array. It doesn't matter if the final array is

thebytes = [0x00, 0x43, 0x41, 0x46, 0x45, 0x42, 0x41, 0x42, 0x45, 0xFF]

or

thebytes = [0, 67, 65, 70, 69, 66, 65, 66, 69, 255]

but it can't be any kind of ASCII or Unicode representation, I simply want the file's byte values to an array.

I've found numerous guides but they all either concentrate on text files or Strings generally or are ~5 years old and imply that it isn't possible with JS.

Related: a Codepen I'm trying to implement it into. The first variable is "thebytes" and contains a boatload of bytes, manually formatted and inserted. This is what I'm trying to avert - I just need a method of pushing "Choose file" and "OK" so I don't have to jump between a hex editor, a text editor and Codepen.

Thanks.

6
  • So you want to use a local file on client without uploading it to server? If so, this article may help you. Commented Dec 8, 2015 at 8:09
  • Really doesn't matter, I'm doing everything on Codepen (which to my knowledge allows temporary uploads to server) and I don't intend on moving the project anywhere else like a home server or Github. @hindmost thanks, I'll look into it Commented Dec 8, 2015 at 8:13
  • Why you dont use the hex format to send data? I think that the best way to send byte array via ajax and xml or json format is converting it to hex format. Commented Dec 8, 2015 at 8:13
  • Because it's very tedious to first open a file in a hex editor, copy all the bytes, paste them into a text editor, format them as a Javascript array, and paste them into Codepen. Commented Dec 8, 2015 at 8:15
  • Take a look at this: stackoverflow.com/questions/14603205/… Commented Dec 8, 2015 at 8:23

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.