MCPcopy Index your code
hub / github.com/microsoft/SandDance / downloadData

Function downloadData

docs/app/js/sanddance-app.js:52015–52030  ·  view source on GitHub ↗
(data, fileName)

Source from the content-addressed store, hash-verified

52013// Licensed under the MIT license.
52014parcelHelpers.export(exports, "downloadData", ()=>downloadData);
52015function downloadData(data, fileName) {
52016 // Adapted from https://ourcodeworld.com/articles/read/189/how-to-create-a-file-and-generate-a-download-with-javascript-in-the-browser-without-a-server
52017 var a = document.createElement("a");
52018 a.setAttribute("download", fileName);
52019 document.body.appendChild(a);
52020 const blob = dataURIToBlob(data);
52021 a.href = URL.createObjectURL(blob);
52022 // we must revoke the object URL,
52023 // since we can't know when the download occured, we have to attach it on the click handler..
52024 a.onclick = ()=>{
52025 // ..and to wait a frame
52026 requestAnimationFrame(()=>URL.revokeObjectURL(a.href));
52027 document.body.removeChild(a);
52028 };
52029 a.click();
52030}
52031//from https://stackoverflow.com/a/37151835/620501
52032function dataURIToBlob(binStr) {
52033 var len = binStr.length, arr = new Uint8Array(len);

Callers

nothing calls this directly

Calls 2

dataURIToBlobFunction · 0.70
requestAnimationFrameFunction · 0.70

Tested by

no test coverage detected