1 回答

TA貢獻1811條經(jīng)驗 獲得超5個贊
是想多了。剛剛結(jié)束直接從UInt8Arrays 的數(shù)組創(chuàng)建一個 blob。
async function start(event) {
console.log("Starting IPFS...");
node = await Ipfs.create();
for await (const file of node.get('QmQxBX5ZKRY8k6W2UqYTMxhdFTvkmNw8X7GJN3t5UiyBpe')) {
console.log("Starting");
var content = [];
for await (const chunk of file.content) {
console.log("Gathering");
content.push(chunk);
}
console.log("Assembling");
saveFile(content, "archlinux-2020.04.01-x86_64.iso");
console.log("Done");
};
}
// https://stackoverflow.com/a/36899900/2700296
function saveFile(data, fileName) {
if (data !== null && navigator.msSaveBlob) {
return navigator.msSaveBlob(new Blob(data, { "type": "application/octet-stream" }), fileName);
}
var a = document.createElement('a');
a.style.display = "none";
var url = window.URL.createObjectURL(new Blob(data, {type: "application/octet-stream"}));
a.setAttribute("href", url);
a.setAttribute("download", fileName);
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(url);
a.remove();
}
添加回答
舉報