Reading binary files using Ajax
Below is an excerpt from the post.
So I put them all together in this BinFileReader function, which provides cross-browser support and helper methods to easily access the binary contents.
* BinFileReader: http://www.heypage.com/nagoon97/BinFileReader/BinFileReader.js
getFileSize() Return the file size getFilePointer() Return the reading position movePointerTo(iTo) Move the reading position to iTo. movePointer(iDirection) Move the reading position in iDirection. For all the following read functions,
- The reading position will move to the end of where the content is last read
- When iFrom is ommited, current reading position is used
readNumber(iNumBytes, iFrom) Read and return iNumBytes-byte number starting at iFrom. readString(iNumChars, iFrom) Read and return iNumChars characters starting at iFrom. readUnicodeString(iNumChars, iFrom) Read and return iNumChars unicoded characters starting at iFrom.
var bmpFile = new BinFileReader(”image.bmp”);
var width = bmpFile.readNumber(4);
var height = bmpFile.readNumber(4);
You can read the full post here.
This script could be used to make some interesting applications, now if we could only write binary files to the system (I know that there would be a huge security hurdle to get pass). If you use this script then I would love to hear about your experience with it (as usual you can leave it in the comments or write a blog post about it using your free Ajaxonomy account).