Dart - Compress -GZIP vs ZLIB
20201004
import 'dart:convert';
import 'dart:io';
void main() {
String data = '';
for (int i = 0; i < 100; i++) {
data = data + 'i love flutter\r\n';
}
List origin = utf8.encode(data);
List compress = GZIP.encode(origin);
List decompress = GZIP.decode(compress);
String decode = utf8.decode(decompress);
assert(data == decode);
print('origin size :${origin.length} bytes');
print('GZIP size: ${compress.length} bytes');
print('decompress size: ${decompress.length} bytes');
int encodeCompress(zipType) {
List compress = zipType.encode(origin);
int size = compress.length;
return size;
}
print('---- GZIP vs ZLIB -----');
print('GZIP size : ${encodeCompress(GZIP)}');
print('ZLIB size : ${encodeCompress(ZLIB)}');
}
Performing hot restart...
Syncing files to device iPhone 11 Pro...
Restarted application in 87ms.
flutter: origin size :1600 bytes
flutter: GZIP size: 50 bytes
flutter: decompress size: 1600 bytes
flutter: ---- GZIP vs ZLIB -----
flutter: GZIP size : 50
flutter: ZLIB size : 38
Comments
Post a Comment