Skip to content

Instantly share code, notes, and snippets.

@afaur
Created February 5, 2017 23:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save afaur/46fd8344a126e349ddffb3792168ca09 to your computer and use it in GitHub Desktop.
Save afaur/46fd8344a126e349ddffb3792168ca09 to your computer and use it in GitHub Desktop.
Testing out binary reading and parsing in the browser
fetch('binary_file1.dat').then(function(response) {
return response.blob()
})
.then(function(blobData) {
var reader, header, level;
reader = new FileReader()
reader.addEventListener('loadend', function() {
// Each 16bit unsigned value is two bytes in size
// By asking for 0, 3 (pos 0-3) of the result we are taking 6 bytes.
header = new Uint16Array(reader.result, 0, 3)
// Read rest of binary data as 8bit each and break up into 4bit after read?
// Not Tested: levelData = new Uint8Array(reader.result, 3, reader.result.byteLength)
console.log(header)
})
reader.readAsArrayBuffer(blobData)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment