compressData static method

Uint8List compressData(
  1. dynamic data
)

Compress data using gzip format

Takes raw data (as String or Uint8List) and returns gzip-compressed bytes

Implementation

static Uint8List compressData(dynamic data) {
  List<int> rawBytes;

  if (data is String) {
    rawBytes = utf8.encode(data);
  } else if (data is Uint8List) {
    rawBytes = data;
  } else if (data is List<int>) {
    rawBytes = data;
  } else {
    throw ArgumentError('Data must be String, Uint8List, or List<int>');
  }

  final codec = GZipCodec();
  final compressed = codec.encode(rawBytes);

  return Uint8List.fromList(compressed);
}