decompressText static method
Decompresses a Base64-encoded gzipped string back to its original form.
This method reverses the compressText operation by:
- Decoding the Base64 string to bytes
- Decompressing the gzipped bytes
- Decoding the UTF-8 bytes back to a string
Returns null if:
- The input
compressedBase64is empty - The input is not valid Base64
- The decoded data is not valid gzip
- An error occurs during decompression
Example:
final original = Base64Utils.decompressText(compressedString);
See also:
- compressText to create compressed strings
Implementation
static String? decompressText(String? compressedBase64) {
if (compressedBase64 == null || compressedBase64.isEmpty) {
return null;
}
try {
final Uint8List decodedBase64 = base64.decode(compressedBase64);
final List<int> decodedGzip = io.gzip.decode(decodedBase64);
return utf8.decode(decodedGzip);
} on FormatException {
// Invalid Base64 format
return null;
} on Exception {
return null;
}
}