import 'dart:convert'; | |
import 'package:archive/archive.dart'; | |
class GZipUtils { | |
/// http://www.txtwizard.net/compression | |
/// string -> bytes -> gzip bytes -> base64 string | |
static String encode(String str) { | |
List<int> stringBytes = utf8.encode(str); | |
List<int> gzipBytes = new GZipEncoder().encode(stringBytes); | |
String base64String = base64.encode(gzipBytes); | |
return base64String; | |
} | |
/// string <-- bytes <- gzip bytes <- base64 | |
static String decode(String encodedString) { | |
var decodeBase64 = base64.decode(encodedString); | |
List<int> gzipBytes = new List<int>.from(decodeBase64); | |
List<int> listInt = new GZipDecoder().decodeBytes(gzipBytes); | |
String origin = utf8.decode(listInt); | |
return origin; | |
} | |
} |
Không có nhận xét nào:
Đăng nhận xét