Uncaught Error: Corrupted zip: missing 589 bytes

2.2k Views Asked by At

I'm using pizzip.js and made a new instance of the pizzip then passed in the file result and then used docxtemplatr package my code:

            var zip = new PizZip(reader.result);

            var doc = new window.docxtemplater().loadZip(zip);

            var text = doc.getFullText();

            console.log(text);

The error:

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)

Any solution?

1

There are 1 best solutions below

0
On

It works for me when I read the file using binary as encoding:

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