decompressText static method

String? decompressText(
  1. String? compressedBase64
)

Decompresses a Base64-encoded gzipped string back to its original form.

This method reverses the compressText operation by:

  1. Decoding the Base64 string to bytes
  2. Decompressing the gzipped bytes
  3. Decoding the UTF-8 bytes back to a string

Returns null if:

  • The input compressedBase64 is 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:

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;
  }
}