restoreBackupCompressed method

Future<void> restoreBackupCompressed(
  1. Uint8List data, {
  2. required K stringToKey(
    1. String key
    ),
  3. required T jsonToValue(
    1. dynamic json
    ),
})

Restores the box contents from a compressed binary backup (Uint8List).

  • data: The compressed binary data representing the backup, as produced by generateBackupCompressed.
  • stringToKey: Function to convert each string key in the JSON to a key of type K.
  • jsonToValue: Function to convert each JSON value to a value of type T.

This method will:

  1. Decompress the binary data to obtain the JSON string.
  2. Decode the JSON and convert each key and value using the provided functions.
  3. Clear the box and insert all restored entries.

Returns a Future that completes when the restore operation is finished.

Throws BoxNotInitializedException if the box is not initialized. Throws FormatException if the decompressed data is not valid JSON. Throws any exception thrown by restoreBackupJson or the decompression process.

Implementation

Future<void> restoreBackupCompressed(
  Uint8List data, {
  required K Function(String key) stringToKey,
  required T Function(dynamic json) jsonToValue,
}) async {
  await ensureInitialized();
  final json = data.restoreText();
  return restoreBackupJson(
    json,
    stringToKey: stringToKey,
    jsonToValue: jsonToValue,
  );
}