The Json response has an gzip encoded string.
var dataList = [
{"Data": "compressedata"},
{"Data": "compressedData"}
];
I tried so many methods to decompress the string but could not get the expected results. The final way tried was
List<int> res = base64.decode(base64.normalize(zipText));
print(utf8.decode(res));
where zipText is the String from json, which throws error
Unhandled Exception: FormatException: Unexpected extension byte (at offset 5)
Another way
Uint8List compressed = base64.decode(zipText);
var gzipBytes = new GZipDecoder().decodeBytes(compressed);
print(gzipBytes);
Throws error
Unhandled Exception: FormatException: Invalid GZip Signature flutter
Any help is really appreciated.
Base from the errors thrown, it looks like the issue came from the String that you're trying to decode. Were the data from the json response properly parsed to String? You may want to consider verifying if the "compressedData" from the json response is valid and can be decoded using gzip.
If the value on
zipTextdoes access data fromdataList- which is a List<Map<String, String>>. Make sure that you're able to access the "compressedData" byvar zipText = '${_dataList[index]['Data']}';Aside from that, you'd also need to decode the value from
GZipDecoder().decodeBytes(Uint8List)to String.Here's a simple sandbox that you can play with. The
decode(String)method in this sample uses the code snippet you've provided.