generateBackupCompressed method

Future<Uint8List> generateBackupCompressed({
  1. String keyToString(
    1. K key
    )?,
  2. Object? valueToJson(
    1. T value
    )?,
})

Generates a compressed binary backup (Uint8List) of all key-value pairs in the box.

  • keyToString: Optional function to convert each key of type K to a String. If not provided, key.toString() is used.
  • valueToJson: Optional function to convert each value of type T to a JSON-serializable object. If not provided, the value is used as-is (must be directly encodable by jsonEncode).

Returns a Future that completes with the compressed binary data representing all box entries.

Throws BoxNotInitializedException if the box is not initialized. Throws any exception thrown by generateBackupJson or the compression process.

Implementation

Future<Uint8List> generateBackupCompressed({
  String Function(K key)? keyToString,
  Object? Function(T value)? valueToJson,
}) async {
  // Generate a JSON string backup of the box contents.
  final json = await generateBackupJson(
    keyToString: keyToString,
    valueToJson: valueToJson,
  );
  // Compress the JSON string to a Uint8List using the shrink package.
  return json.shrink();
}