compressStringAsync method
Compresses the given string data asynchronously.
Returns the compressed data as a base64-encoded string.
For large strings (above _asyncThreshold
), this is done in a separate isolate
to avoid blocking the main thread.
Implementation
Future<String> compressStringAsync(String data) async {
try {
return await IsolateRunner.runWithThreshold<_CompressionMessage, String>(
function: _compressInIsolate,
message: _CompressionMessage(
data: data,
level: _level,
),
dataSize: data.length,
asyncThreshold: _asyncThreshold,
);
} catch (e) {
_log.warning('Failed to compress string asynchronously: $e');
// Return the original data if compression fails
return data;
}
}