bytes static method

Future<Uint8List> bytes(
  1. Uint8List bytes
)

Asynchronously compresses a Uint8List using zlib compression or no compression (identity).

This function tries different compression levels to find the optimal compression:

  • No compression (identity) - used when compression would increase size
  • ZLIB compression with levels 4-9

The first byte of the resulting Uint8List indicates the compression method used, followed by the compressed data.

This method runs the compression in a separate isolate using compute to avoid blocking the main thread.

Returns a Future<Uint8List> containing the compressed data using the most efficient method for the input data. The compression is lossless - the original data can be fully restored.

Implementation

static Future<Uint8List> bytes(Uint8List bytes) {
  return compute(_shrinkBytesIsolate, bytes);
}