compressString method

String compressString(
  1. String data
)

Compresses the given string data.

Returns the compressed data as a base64-encoded string. For small strings, this is done synchronously. For large strings (above _asyncThreshold), this is done in a separate isolate.

Implementation

String compressString(String data) {
  try {
    // For small strings, compress synchronously
    if (data.length < _asyncThreshold) {
      return _compressStringSync(data);
    }

    // For large strings, we should use the async version
    // But since this method is synchronous, we'll log a warning and still do it synchronously
    _log.warning(
        'Large string (${data.length} chars) being compressed synchronously. Consider using compressStringAsync for better performance.');
    return _compressStringSync(data);
  } catch (e) {
    _log.warning('Failed to compress string: $e');
    // Return the original data if compression fails
    return data;
  }
}