Created
February 5, 2017 23:55
-
-
Save afaur/46fd8344a126e349ddffb3792168ca09 to your computer and use it in GitHub Desktop.
Testing out binary reading and parsing in the browser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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