Skip to content

Instantly share code, notes, and snippets.

@khlbrg
Created June 9, 2017 05:30
Show Gist options
  • Save khlbrg/78198863c59bef651a3bac0118123ed5 to your computer and use it in GitHub Desktop.
Save khlbrg/78198863c59bef651a3bac0118123ed5 to your computer and use it in GitHub Desktop.
Filereader example
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