zlibCompress function

Uint8List zlibCompress(
  1. Uint8List data
)

data compressed as a complete zlib (RFC 1950) stream — the two-byte header, one final DEFLATE block, and the trailing Adler-32 _adler32 computes over the uncompressed bytes, which every real decoder checks even though this package's own zlibInflate does not.

Implementation

Uint8List zlibCompress(Uint8List data) {
  final deflated = _deflate(data);
  final out = BytesBuilder();
  out.add(const <int>[0x78, 0x9C]); // CMF/FLG: deflate, 32K window, level 2
  out.add(deflated);
  final adler = _adler32(data);
  out.add(<int>[
    (adler >> 24) & 0xFF,
    (adler >> 16) & 0xFF,
    (adler >> 8) & 0xFF,
    adler & 0xFF,
  ]);
  return out.toBytes();
}