let _fs = void 0;function set_fs(fs) { _fs = fs; }export { set_fs };
function blobify(data) { if(typeof data === "string") return s2ab(data); if(Array.isArray(data)) return a2u(data); return data;}function write_dl(fname, payload, enc) { if(typeof _fs !== 'undefined' && _fs.writeFileSync) return enc ? _fs.writeFileSync(fname, payload, enc) : _fs.writeFileSync(fname, payload); if(typeof Deno !== 'undefined') { if(enc && typeof payload == "string") switch(enc) { case "utf8": payload = new TextEncoder(enc).encode(payload); break; case "binary": payload = s2ab(payload); break; default: throw new Error("Unsupported encoding " + enc); } return Deno.writeFileSync(fname, payload); } var data = (enc == "utf8") ? utf8write(payload) : payload; if(typeof IE_SaveFile !== 'undefined') return IE_SaveFile(data, fname); if(typeof Blob !== 'undefined') { var blob = new Blob([blobify(data)], {type:"application/octet-stream"}); if(typeof navigator !== 'undefined' && navigator.msSaveBlob) return navigator.msSaveBlob(blob, fname); if(typeof saveAs !== 'undefined') return saveAs(blob, fname); if(typeof URL !== 'undefined' && typeof document !== 'undefined' && document.createElement && URL.createObjectURL) { var url = URL.createObjectURL(blob); if(typeof chrome === 'object' && typeof (chrome.downloads||{}).download == "function") { if(URL.revokeObjectURL && typeof setTimeout !== 'undefined') setTimeout(function() { URL.revokeObjectURL(url); }, 60000); return chrome.downloads.download({ url: url, filename: fname, saveAs: true}); } var a = document.createElement("a"); if(a.download != null) { a.download = fname; a.href = url; document.body.appendChild(a); a.click(); document.body.removeChild(a); if(URL.revokeObjectURL && typeof setTimeout !== 'undefined') setTimeout(function() { URL.revokeObjectURL(url); }, 60000); return url; } } } if(typeof $ !== 'undefined' && typeof File !== 'undefined' && typeof Folder !== 'undefined') try { var out = File(fname); out.open("w"); out.encoding = "binary"; if(Array.isArray(payload)) payload = a2s(payload); out.write(payload); out.close(); return payload; } catch(e) { if(!e.message || !e.message.match(/onstruct/)) throw e; } throw new Error("cannot save file " + fname);}
function read_binary(path) { if(typeof _fs !== 'undefined') return _fs.readFileSync(path); if(typeof Deno !== 'undefined') return Deno.readFileSync(path); if(typeof $ !== 'undefined' && typeof File !== 'undefined' && typeof Folder !== 'undefined') try { var infile = File(path); infile.open("r"); infile.encoding = "binary"; var data = infile.read(); infile.close(); return data; } catch(e) { if(!e.message || !e.message.match(/onstruct/)) throw e; } throw new Error("Cannot access file " + path);}