0

I am trying to decode the bytes using GZipDecoder().decodeBytes from the archive package and I am getting 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() from the Utf package.

Version

  • Platform: Android
  • Flutter: 2.10.4
  • archive: ^3.3.0

Do let me know if more info is required. Any suggestion or help will be appreciated!


@MarkAdler Then it's not gzip input.

The steps are overall steps as well from picking the file to reading it that I am using. Thanks to MarkAdler for his comment!:

  1. Convert the file into Unint8List by reading the file with var bytes = File(_path).readAsBytesSync()
  2. Decoding the Utfle16 bytes to Utf8 bytes by Utf16leBytesToCodeUnitsDecoder(bytes)
  3. Finally using GZipDecoder().decodeBytes which throws the error.
  • 1
    Then it's not gzip input. – Mark Adler Apr 16 '22 at 14:52
  • @MarkAdler Thanks for your comment on this. I tried to determine if that's the case by looking the using the `file -i sample.csv.gz` in Linux terminal. The repose was: ``` sample.csv.gz: application/gzip; charset=binary ``` Since the actual implementation is done on the Flutter application. The steps are: 1) Convert the file into `Unint8List` by reading the file with `var bytes = File(_path).readAsBytesSync()` 2) Decoding the Utfle16 bytes to Utf8 bytes by `Utf16leBytesToCodeUnitsDecoder(bytes)` 3) Finally using `GZipDecoder().decodeBytes` which throws the error. – Yogesh Choudhary Apr 16 '22 at 18:25
  • Hope this information is useful in understanding the problem better. I am putting in the question as well to provide the info in better formatting. You can be right even. Please let me know if there is any other way I can verify the input – Yogesh Choudhary Apr 16 '22 at 18:29
  • 1
    Why are you doing UTF conversions? You have read the bytes as bytes. Feed those directly to the gzip decoder. – Mark Adler Apr 16 '22 at 18:41
  • @MarkAdler Your final comment helped me. Thanks a lot. I changed the order of the instructions. 1) read the bytes 2) Passed the bytes as input to gzip encoder 3) performed the conversion to UTF-8. To answer the question you asked. Because the data is in UTF-16LE, I am unable to parse the data into appropriate types. That is the reason I had to do conversation. Or at least I believe so. Since it worked this way for me. – Yogesh Choudhary Apr 17 '22 at 07:49
  • But the thing that I am still not able to understand is the reason. Why it was not working when conversion is performed first. Also, for the past 3 months or so I have been using the earlier mentioned code and things worked as intended without any issue. Can you think of the possible reasons for this behaviour? – Yogesh Choudhary Apr 17 '22 at 07:54
  • Now why are you doing step 3?! (Conversion to UTF-8.) That can prevent you from decompressing the gzip stream at the other end. Leave binary data alone. Stop trying to corrupt it with unicode conversions. – Mark Adler Apr 17 '22 at 16:10
  • @MarkAdler I am doing step 3 on the decompressed bytes that I received from step 2. Please let me if it can still corrupt the data in some form. Coming to the question as to why I am doing the conversion. I believe [UTF-16LE txt file decode as String in Flutter (dart)](https://stackoverflow.com/questions/57943867/utf-16le-txt-file-decode-as-string-in-flutter-dart) question is able to explain the outcome in a better way if I don't do the conversion. – Yogesh Choudhary Apr 18 '22 at 21:11
  • While going through the responses to the shared question, I liked the idea of directly reading the `UTF-16LE` file as a `String` in dart. And since the file I am using is `UTF-16LE` that shouldn't be the problem but I don't why it just didn't worked in my situation. I will try to do a bit more study on this perhaps! – Yogesh Choudhary Apr 18 '22 at 21:15

0 Answers0