Implementation
List<int> encode(List<int> data, {int? level, OutputStreamBase? output}) {
output = output ?? OutputStream(byteOrder: BIG_ENDIAN);
final cm = DEFLATE;
final cinfo = 7;
final cmf = (cinfo << 4) | cm;
output.writeByte(cmf);
final fdict = 0;
final flevel = 0;
var flag = ((flevel & 0x3) << 7) | ((fdict & 0x1) << 5);
var fcheck = 0;
final cmf256 = cmf * 256;
while ((cmf256 + (flag | fcheck)) % 31 != 0) {
fcheck++;
}
flag |= fcheck;
output.writeByte(flag);
final adler32 = getAdler32(data);
final input = InputStream(data, byteOrder: BIG_ENDIAN);
final compressed = Deflate.buffer(input, level: level).getBytes();
output.writeBytes(compressed);
output.writeUint32(adler32);
output.flush();
if (output is OutputStream) {
return output.getBytes();
}
return [];
}