未捕获的错误:zip已损坏:缺少589个字节



我使用pizzip.js,创建了一个新的pizzip实例,然后传入文件结果,然后使用docxtemplatr包我的代码:

var zip = new PizZip(reader.result);
var doc = new window.docxtemplater().loadZip(zip);
var text = doc.getFullText();
console.log(text);

错误:

zipEntries.js:270 Uncaught Error: Corrupted zip: missing 589 bytes.
at ZipEntries.readEndOfCentral (zipEntries.js:270)
at ZipEntries.load (zipEntries.js:296)
at new ZipEntries (zipEntries.js:32)
at PizZip.module.exports [as load] (load.js:25)
at new PizZip (index.js:41)
at FileReader.reader.onload (en:393)

有解决方案吗

当我使用binary作为编码读取文件时,它对我有效:

fs.readFile(filepath, 'binary') // <-- set the encoding
.then(content => {
let zip = new PizZip(content);
// ... your code
})
.catch(err => doSomethingWith(err));

相关内容

最新更新