Closed JCarlesVilaseca closed 3 years ago
The extra field is present in the central directory of the zip file. The specification does not require it to be present in the local header.
Ok.
Anyway,
WinZip 9 (obsolete) warns with bad header about uncompressed size = 0
compressed size: 0 bytes
uncompressed size: 0 bytes
Zip4jUtil (current version) can't open the file: java.lang.RuntimeException: AesExtraDataRecord not present in local header for aes encrypted data at net.lingala.zip4j.util.Zip4jUtil.getCompressionMethod(Zip4jUtil.java:112)
const blobWriter = new BlobWriter('application/zip');
const writer = new ZipWriter(blobWriter, {
password: 'password',
encryptionStrength: 3,
useWebWorkers: false,
});
await writer.add('hello.txt', new TextReader('Hello world'));
await writer.close();
It's a bug in Zip4jUtil. It should be able to rely on the extra field data located in the central directory. 7zip does not display any warning or error for example.
The values of the sizes are correct, the real values are stored in the "data descriptor record". I guess setting the option dataDescriptor
to false
should fix the issue.
It's fixed. In the version 2.2.22
, the AES and the custom extra field data is written in the local header.
@JCarlesVilaseca Could you confirm the encrypted zip files produced with zip.js can now be read with Zip4jUtil?
It works like a charm! Thank you so much!
Great! Thank you for the feedback
Using AES encription, WinZip writes 7 bytes extrafield in each file entry. Some other libraries (Zip4jUtil) can't open the zip file if extrafield is not present.
https://github.com/gildas-lormeau/zip.js/blob/103ca465742295168aca1cd60b78337d3aa56f94/lib/core/zip-writer.js#L408
Adding using options doesn't help:
WinZip:
zip.js