encodeAsync static method
Same as encode, but encodes in the compressionIsolatePool (a
background Isolate) if bytes is large for level
(see isolateMinLength).
Returns null if the encoding fails in the Isolate (logged).
Implementation
static FutureOr<Uint8List?> encodeAsync(
Uint8List bytes, {
int level = defaultLevel,
}) {
if (bytes.length < isolateMinLength(level)) {
return encode(bytes, level: level);
}
return compressionIsolatePool
.run(() => encode(bytes, level: level))
.then<Uint8List?>(
(encoded) => encoded,
onError: (Object e, StackTrace s) {
_log.severe(
"GZip encoding failed (${bytes.length} bytes, level: $level)",
e,
s,
);
return null;
},
);
}