huffDecode static method

String huffDecode(
  1. Uint8List data,
  2. int off,
  3. int len
)

Implementation

static String huffDecode(Uint8List data, int off, int len) {
  final out = StringBuffer();
  var code = 0;
  var bits = 0;
  for (var i = 0; i < len; i++) {
    final b = data[off + i] & 0xff;
    for (var j = 7; j >= 0; j--) {
      code = (code << 1) | ((b >> j) & 1);
      bits++;
      final sym = _huffDecode[(bits << 32) | code];
      if (sym != null) {
        if (sym == 256) {
          throw const FormatException('huffman EOS symbol');
        }
        out.writeCharCode(sym);
        code = 0;
        bits = 0;
      } else if (bits > 30) {
        throw const FormatException('huffman code too long');
      }
    }
  }
  return out.toString();
}