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
- Gzip is unavailable on the current platform (e.g., web)
- An error occurs during decompression
Example:
final original = Base64Utils.decompressText(compressedString);
See also:
compressTextto create compressed strings Audited: 2026-06-12 11:26 EDT
Implementation
@useResult
static String? decompressText(String? compressedBase64) {
if (compressedBase64 == null || compressedBase64.isEmpty) {
return null;
}
try {
final Uint8List decodedBase64 = base64.decode(compressedBase64);
final List<int>? decodedGzip = gzipDecode(decodedBase64);
if (decodedGzip == null) {
return null;
}
return utf8.decode(decodedGzip);
} on FormatException catch (e, stackTrace) {
// Structured log instead of debugPrint, so the stack trace is not printed
// to stdout; the caller still gets null as the failure signal.
log('Base64Utils.decompressText failed', error: e, stackTrace: stackTrace);
return null;
}
}