Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
graphefruit opened this issue Jun 29, 2023 · 8 comments
Closed

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

graphefruit opened this issue Jun 29, 2023 · 8 comments

Comments

@graphefruit
Copy link

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
Copy link
Owner

gildas-lormeau commented Jun 29, 2023

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
Copy link
Author

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
Copy link
Owner

gildas-lormeau commented Jun 30, 2023

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
Copy link
Author

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
Copy link
Owner

gildas-lormeau commented Jun 30, 2023

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
Copy link
Owner

FYI @AshleyScirra

@graphefruit
Copy link
Author

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
Copy link
Owner

gildas-lormeau commented Jun 30, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants