compressToBase64Sync static method

String? compressToBase64Sync(
  1. String? input
)

Synchronously produces ASCII UTF-16 strings representing the original / string encoded in Base64 from input. Can be decompressed with decompressFromBase64.

This works by using only 6bits of storage per character. The strings produced are therefore 166% bigger than those produced by compress.

Implementation

static String? compressToBase64Sync(String? input) {
  final res = _compress(input, 6, (a) => _keyStrBase64[a]);
  if (res == null) return null;
  switch (res.length % 4) {
    case 0:
      return res;
    case 1:
      return res + "===";
    case 2:
      return res + "==";
    case 3:
      return res + "=";
  }
  return null;
}