0

我正在使用 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)

有什么解决办法吗?

4

1 回答 1

0

当我使用binaryas 编码读取文件时,它对我有用:

fs.readFile(filepath, 'binary') // <-- set the encoding
.then(content => {
    let zip = new PizZip(content);
    // ... your code
})
.catch(err => doSomethingWith(err));
于 2021-09-13T23:03:40.160 回答