thejoshwolfe/yazl

ZIP is valid on Linux, but not on Windows

zadam opened this issue · 1 comments

zadam commented

Hi, I've encountered a strange issue with YAZL generated ZIPs. This is described in detail in zadam/trilium#1122 but here are the most relevant parts:

Example ZIP generated by YAZL: root.zip

On Linux it all seems fine:

$ unzip -t root.zip 
Archive:  root.zip
    testing: !!!meta.json             OK
    testing: root/                    OK
    testing: root/Trilium Demo.html   OK
    testing: root/Trilium Demo/       OK
    testing: root/Trilium Demo/Formatting examples/   OK
    testing: root/Trilium Demo/Formatting examples/School schedule.html   OK
...
    testing: root/Trilium Demo/Statistics/Note type count/template/js/renderTable.js   OK
    testing: root/Trilium Demo/Statistics/Note type count/template/js/renderPieChart.clone.html   OK
    testing: root/Trilium Demo/Statistics/Most cloned notes/   OK
    testing: root/Trilium Demo/Statistics/Most cloned notes/template.html   OK
    testing: root/Trilium Demo/Statistics/Most cloned notes/template/   OK
    testing: root/Trilium Demo/Statistics/Most cloned notes/template/js.js   OK
    testing: navigation.html          OK
    testing: index.html               OK
    testing: style.css                OK
No errors detected in compressed data of root.zip.

But on windows most apps seem to report checksum errors:

image

image

Any idea what might be causing this?

chdh commented

This error occurs when you pass a string to addBuffer() instead of a buffer. Trilium Notes has done that, before it switched from Yazl to Archiver. When the content string contains non-ASCII characters, the number of characters will differ from the number of bytes.

Test case:

const yazl = require("yazl");
const fs = require("fs");

const zipfile = new yazl.ZipFile();
zipfile.addBuffer("A \u00E4 Z", "test.txt");
zipfile.outputStream.pipe(fs.createWriteStream("test.zip"));
zipfile.end();

In this example, the number of characters is 5, but the number of UTF-8 encoded bytes in 6. In the ZIP directory entry the file size is 5, which is wrong.