Zipping files with javascript - corrupt archive

孤街醉人 提交于 2020-01-13 09:41:13

问题


I'm trying to use JSZip to zip some text and then open it with 7Zip. The problem is, the archive is apparently corrupted at some point. I can't open it. I'm guessing it's not created correctly, possibly because I'm not using the correct encoding, but there could also be a slight chance that it's happening during transfer from my Android device (this is a Phonegap project) to my PC (I use adb to transfer the archive).

My code is:

var zip = new JSZip();
zip.add("hi.txt", "Hello World");
var content = zip.generate(true); // true == get raw byte string
writer.write(content);

Where writer is a Phonegap FileWriter object.

Any ideas?


回答1:


It is currently impossible to write binary data with Phonegap's FileWriter, as stated here by a PhoneGap guy.




回答2:


Maybe the same problem I've documented here document generation only works the first time

In my case the document generation works fine when having the remote debugger attached. In addition I can reproduce only on Android 4.4 (kitkat)



来源:https://stackoverflow.com/questions/8743593/zipping-files-with-javascript-corrupt-archive

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!