Created
June 9, 2017 05:30
-
-
Save khlbrg/78198863c59bef651a3bac0118123ed5 to your computer and use it in GitHub Desktop.
Filereader example
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
const fileSelector = document.getElementById('file-selector') | |
fileSelector.addEventListener('change', (event) => { | |
const file = event.target.files[0] | |
const filereader = new FileReader() | |
filereader.onloadend = function (evt) { | |
if (evt.target.readyState === FileReader.DONE) { | |
const uint = new Uint8Array(evt.target.result) | |
let bytes = [] | |
uint.forEach((byte) => { | |
bytes.push(byte.toString(16)) | |
}) | |
const hex = bytes.join('').toUpperCase() | |
console.log(hex) | |
} | |
} | |
const blob = file.slice(0, 4); | |
filereader.readAsArrayBuffer(blob); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment