Last active
June 8, 2021 12:22
-
-
Save Totati/11ddde815d5bf255d38ce823261c43ac to your computer and use it in GitHub Desktop.
Read the magic number of a 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
export async function getMagicNumber(file: File, signatureLength: number = 4) { | |
return file | |
.slice(0, signatureLength) | |
.arrayBuffer() | |
.then((buffer) => | |
Array.from(new Uint8Array(buffer)) | |
.map((byte) => byte.toString(16).padStart(2, '0')) | |
.join('') | |
.toUpperCase() | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment