Skip to content

Instantly share code, notes, and snippets.

@frozonfreak
Created December 21, 2015 02:08
Show Gist options
  • Save frozonfreak/9b84b4fd124d0fea0f31 to your computer and use it in GitHub Desktop.
Save frozonfreak/9b84b4fd124d0fea0f31 to your computer and use it in GitHub Desktop.
Check for file format using magic numbers in file
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
};
@pavankumar0425
Copy link

Thanks a lot for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment