Created
December 21, 2015 02:08
-
-
Save frozonfreak/9b84b4fd124d0fea0f31 to your computer and use it in GitHub Desktop.
Check for file format using magic numbers in file
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
var blob = $(this).get(0).files[0]; | |
var fileReader = new FileReader(); | |
fileReader.readAsArrayBuffer(blob); | |
fileReader.onloadend = function(e) { | |
var arr = (new Uint8Array(e.target.result)).subarray(0, 4); | |
var header = ""; | |
for(var i = 0; i < arr.length; i++) { | |
header += arr[i].toString(16); | |
} | |
console.log(header); | |
// Check the file signature against known types | |
//https://en.wikipedia.org/wiki/List_of_file_signatures | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks a lot for this.