Skip to content

Instantly share code, notes, and snippets.

@kijart
Created June 30, 2019 18:50
Show Gist options
  • Save kijart/d4fe564859835a05ad98dc466a1c27e7 to your computer and use it in GitHub Desktop.
Save kijart/d4fe564859835a05ad98dc466a1c27e7 to your computer and use it in GitHub Desktop.
function hex2binDownload(hex, fileName) {
const binary = hex.match(/[A-F0-9]{2}/g).map((value) => parseInt(value, 16));
const byteArray = new Uint8Array(binary);
let a = window.document.createElement('a');
a.href = window.URL.createObjectURL(new Blob([byteArray], { type: 'application/octet-stream' }));
a.download = fileName;
document.body.appendChild(a)
a.click();
document.body.removeChild(a)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment