Javascript JSZip文件不是';t工作:“';错误:数据为';加载的zip文件';格式不受支持&引用;
出现以下错误消息:Javascript JSZip文件不是';t工作:“';错误:数据为';加载的zip文件';格式不受支持&引用;,javascript,html,zip,jszip,Javascript,Html,Zip,Jszip,出现以下错误消息: "Error: The data of 'the loaded zip file' is in an unsupported format !". 我正在使用谷歌Chrome-最新版本 下面是一个代码粘贴箱:(对于stackoverflow来说太长了) 您可以在此处看到一个模板: <!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/xhtml"> <head>
"Error: The data of 'the loaded zip file' is in an unsupported format !".
我正在使用谷歌Chrome-最新版本
下面是一个代码粘贴箱:(对于stackoverflow来说太长了)
您可以在此处看到一个模板:
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<script>
(jszip)
</script>
</head>
<body>
Loading...<br />
<progress id="pBar"></progress>
<script>
var pBar = document.getElementById('pBar');
var content = atob('(base64 zip)');
var zipFile = new JSZip();
main();
async function loadFile(toLoad, base64) {{
return await zipFile.file(toLoad + (base64 ? ".txt" : "")).async(base64 ? "text" : "base64");
}}
async function loadScript(toLoad) {{
var content = await loadFile(toLoad, false);
var script = document.createElement('script');
script.src = 'data:text/javascript;base64,' + v;
document.head.appendChild(script);
await new Promise(callback => script.onload = callback);
}}
async function main()
{{
await zipFile.loadAsync(content);
var content = await zipFile.file('load.txt').async("string");
var files = arg0.replace(/\r/g, '').split('\n');
pBar.max = files.length;
for (var fileName of files)
{{
(pBar ? pBar.value++ : void 0);
await loadScript(fileName);
}}
}}
</script>
</body>
</html>
(jszip)
正在加载…
var pBar=document.getElementById('pBar');
var content=atob(‘(base64-zip)’);
var zipFile=new JSZip();
main();
异步函数加载文件(toLoad,base64){{
return wait wait zipFile.file(toLoad+(base64?.txt:“)).async(base64?.text:“base64”);
}}
异步函数加载脚本(toLoad){{
var content=等待加载文件(toLoad,false);
var script=document.createElement('script');
script.src='data:text/javascript;base64'+v;
document.head.appendChild(脚本);
等待新承诺(callback=>script.onload=callback);
}}
异步函数main()
{{
等待zipFile.loadAsync(内容);
var content=await zipFile.file('load.txt').async(“字符串”);
var files=arg0.replace(/\r/g').split('\n');
pBar.max=files.length;
for(文件的var文件名)
{{
(pBar?pBar.value++:void 0);
等待加载脚本(文件名);
}}
}}
使用loadAsync()时,您可能应该返回承诺。
请参阅文档以更好地理解: