gildas-lormeau / zip.js

JavaScript library to zip and unzip files supporting multi-core compression, compression streams, zip64, split files and encryption.
https://gildas-lormeau.github.io/zip.js
BSD 3-Clause "New" or "Revised" License
3.33k stars 506 forks source link

ZIP file corrupt via safari/iOS, but on Chrome working #433

Closed graphefruit closed 1 year ago

graphefruit commented 1 year ago

Hello there,

first of all I wanted to say, this library is realy great and is working fast and great!

Before we start maybe my short use case: I'm developing a open source coffee app which stores all data locally. Android and iOS has issues, when the .JSON-File will get bigger then 5MB. Thats why I implemented with this library a logic to split my IndexDB entries into several .JSON-Files to not reach the 5MB limit on each.

Generating a ZIP-File with one main .JSON works flawless on iOS and on Android. Strange it gets when I create several chunk-sized.json

The idea is to split the users coffee brews to chunk sizes for 500 brews each file and having one main file (Beanconqueror.json) and when importing the zip to put them all together again - which works pretty good!

When I use my sample .JSON-File with a size of 1.9 MB, I'll get a zip file with 3 entries: Beanconqueror.json Beanconqueror_Brews_1.json Beanconqueror_Brews_2.json

On iOS the same logic produces also a ZIP file, but on Android its 5 KB smaller then on iOS. But when I open now the zip file on MacOs I'm getting following issue:

image

-> Funny enough I can open this file on Android!

One test was now to create bigger chunk-sized files so I set 1000 entries each file, and I just got 2 files: Beanconqueror.json Beanconqueror_Brews_1.json

-> Then iOS ZIP file was generated, and can be opend on IOS then.

I've digged a bit deeper and tried different parameters, and found out when I remove the compression on iOS:

new ZipWriter(zipFileWriter, { level: 0 });

Everything works fine!

Also to mention: When I do this on Chrome on a Mac, the ZIP file works (with the 3 entries) When I do this on Safari on the same Mac, the ZIP file is corrupt (with the 3 entries)

The code logic you can find here: https://github.com/graphefruit/Beanconqueror/blob/c4eec36d537f7912328e23074b631ee56e576d99/src/services/uiExportImportHelper.ts#L48

Hope you can help me! Would be awesome if I can enable compression again.

"@zip.js/zip.js": "^2.7.14", "typescript": "^4.9.4",

Thank you so far & Keep up the great work Lars

gildas-lormeau commented 1 year ago

Thank you for the detailed info and the kind words, could you tell me if setting the option useCompressionStream to false (see https://gildas-lormeau.github.io/zip.js/api/interfaces/Configuration.html#useCompressionStream) helps to fix the bug? If this is the case, then it's a bug in WebKit.

graphefruit commented 1 year ago

Thanks for the fast response @gildas-lormeau. Could you give me a helping hand how to initialise the configuration and pass then this option on my typescript/angular setup so its realy taken into account.

Sorry feeling a bit dumb to not understand it how to do :< Thanks Lars

gildas-lormeau commented 1 year ago

No problem ;). Please try to execute this code after the import of zip.js and before using it in your code: zip.configure({ useCompressionStream: false }) if you your import looks like this import * as zip from ..., or configure({ useCompressionStream: false }) if you your import looks like this import { configure, ZipWriter, ... } from ....

graphefruit commented 1 year ago

With the useCompressionStream set to false its working! Is there any other issues correlating when doing this for iOS? Else I'd implement it in the next update, after I've already sent on patch out.

Maybe also a good hint in the Readme specially for Safari/iOS/Cordova, because this issue does not always exist, but just in some cases like I wrote above.

Thank you for this very fast support & feedback & help! Have a great cup of ☕ Lars

gildas-lormeau commented 1 year ago

If you want to see this bug fixed, it would be better to report it to Apple because they are the author of this bug. If you can, please report it here: https://bugs.webkit.org/. Maybe I will document that useCompressionStream should be set to false on Safari because there are more bugs than features in the CompressionStream API that Apple implemented.

gildas-lormeau commented 1 year ago

FYI @AshleyScirra

graphefruit commented 1 year ago

Got it! Thanks !

Even so the question: Do you know if there are other issues when I don't use the 'UseCompressionStream' for iOS or restrictions for some apis/solutions inside this library?

Else this ticket would be closed for me so! Thanks again :)

gildas-lormeau commented 1 year ago

The only issue is that the compression is probably a bit slower when the option is set to false.