Created
January 30, 2021 10:45
-
-
Save corocoto/7e80b310d4a735000a1a6193187d99c1 to your computer and use it in GitHub Desktop.
Creating download link that contains various ASCII codes (created by TypedArray)
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
function typedArrayToURL(typedArr, mimeType) { | |
return URL.createObjectURL(new Blob([typedArr.buffer], {type: mimeType})); | |
} | |
const bytes = new Uint8Array(59); | |
for(let i = 0; i < 59; i++) { | |
bytes[i] = 32 + i; | |
} | |
const url = typedArrayToURL(bytes, 'application/octet-binary'); | |
const a = document.createElement('a'); | |
a.href = url; | |
a.textContent = 'Download file'; | |
document.body.appendChild(a); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment