brendan-duncan / archive

Dart library to encode and decode various archive and compression formats, such as Zip, Tar, GZip, ZLib, and BZip2.
MIT License
400 stars 139 forks source link

How to handle Exception: `ArchiveException('Invalid GZip Signature')` #206

Closed zexross closed 2 years ago

zexross commented 2 years ago

I was trying to decode the bytes using GZipDecoder().decodeBytes and I got this exception:

ArchiveException('Invalid GZip Signature')

How should I handle this exception? I am getting the List<int> data using a decoder method Utf16leBytesToCodeUnitsDecoder(zippedBytes).decodeRest().

Version Platform: Android Flutter: 2.10.4 archive: ^3.3.0

Do let me know if more info is required. Thank you!

zexross commented 2 years ago

Hi,

I am closing this issue as I was able to trace the reason for the Exception. It turned out that the conversion that I am doing before decompressing the data is corrupting the bytes. Hence, the algorithm is not able to identify the data as GZip input.

To solve the issue, I directly fed the file data to the GZipDecoder().decodeBytes and then performed the conversion. And things worked as expected. More can learn on this StackOverflow question: How to handle Exception: ArchiveException('Invalid GZip Signature')