使用javascript压缩文件 - 损坏的存档 [英] Zipping files with javascript - corrupt archive
问题描述
我尝试使用 JSZip 压缩一些文字,然后使用 7Zip 。问题是,归档文件在某些时候显然已损坏。我无法打开它。我猜它没有正确创建,可能是因为我没有使用正确的编码,但也可能有一个轻微的机会,它发生在从我的Android设备(这是一个 Phonegap 项目)到我的电脑(我使用adb传输档案)。
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).
我的代码是:
var zip = new JSZip();
zip.add("hi.txt", "Hello World");
var content = zip.generate(true); // true == get raw byte string
writer.write(content);
其中 writer
是Phonegap FileWriter 对象。
Where writer
is a Phonegap FileWriter object.
任何想法?
推荐答案
数据与PhoneGap的FileWriter,如电话Gap家伙这里所述。
It is currently impossible to write binary data with Phonegap's FileWriter, as stated here by a PhoneGap guy.
这篇关于使用javascript压缩文件 - 损坏的存档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!