Skip to content

Instantly share code, notes, and snippets.

@corocoto
Created January 30, 2021 10:45
Show Gist options
  • Save corocoto/7e80b310d4a735000a1a6193187d99c1 to your computer and use it in GitHub Desktop.
Save corocoto/7e80b310d4a735000a1a6193187d99c1 to your computer and use it in GitHub Desktop.
Creating download link that contains various ASCII codes (created by TypedArray)
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