decode method
Decodes the input string using the codec's specific algorithm.
input
The encoded string to be decoded.
Returns the decoded plain text string.
Throws ArgumentError if the input is invalid for this codec. Throws FormatException if decoding fails due to format issues.
Implementation
@override
String decode(String input) {
if (input.isEmpty) {
throw ArgumentError('Input cannot be empty');
}
if (!isValidInput(input)) {
throw FormatException('Invalid Base64 input format for compressed data');
}
try {
final compressedBytes = base64.decode(input);
// Use GZipCodec from dart:io to decompress
final gzipCodec = GZipCodec();
final decompressed = gzipCodec.decode(compressedBytes);
return utf8.decode(decompressed);
} catch (e) {
throw FormatException('Failed to decompress input: $e');
}
}