It is mentioned in Baidu Encyclopedia

Gzip is an abbreviation for several file compression programs, usually the implementation of the GNU Project. Here Gzip stands for GNU Zip. It is also often used to refer to the file format gzip, which was written by Jean-Loup Gailly and Mark Adler

GZIP was first created by Jean-Loup Gailly and Mark Adler for file compression in THE UN ⅸ system. In Linux we often use files with the suffix.gz, which are in GZIP format. Nowadays, it has become a very popular data compression format, or file format, used on the Internet

In the current HTTP transmission protocol, GZIP is also used. Simply speaking, GZIP can compress the transmitted data to a certain extent, and then improve the transmission speed.

If you are interested, you can follow the public account Biglead to get the latest learning materials.

  • The Series of articles on Flutter from Entry to Mastery is here
  • Of course, it is also necessary to have the source code here
  • Github a bit slow might as well take a look at the source code cloud it
  • A series of learning tutorials is available here

Dart is fully adopted by Flutter. Within Dart, GZIP is also available.

import 'dart:convert';
import 'package:archive/archive.dart';
Copy the code

The test case

void main(a) {
  
  testWidgets('Counter increments smoke test', (WidgetTester tester) async {
    print("Gzip compression");

    // Raw string
    String myString = 'myString';
    // Gzip compressed text
    String zipString = gzipEncode(myString);

    print("Gzip encoding - $zipString");

    / / gzip decompression
    String zipString2 = gzipDencode(zipString);

    print("Gzip -$zipString2");
  });
}
Copy the code

The log console output is as followsGZIP compression


/ / / GZIP compression
String gzipEncode(String str) {
  // Let's switch
  List<int> stringBytes = utf8.encode(str);
  // Then use gzip to compress
  List<int> gzipBytes = new GZipEncoder().encode(stringBytes);
  // Then encode it for network transmission
  String compressedString = base64UrlEncode(gzipBytes);
  return compressedString;
}
Copy the code

GZIP decompression

/ / / GZIP decompression
String gzipDencode(String str) {
  // Let's decode it
  List<int> stringBytes = base64Url.decode(str);
  // Then use gzip to compress
  List<int> gzipBytes = new GZipDecoder().decodeBytes(stringBytes);
  // Then encode it again
  String compressedString = utf8.decode(gzipBytes);
  return compressedString;
}
Copy the code