BackupCompressedExtension<K, T> extension
Extension providing compressed binary backup and restore capabilities for BoxInterface.
This extension enables any BoxInterface implementation to export its contents
as a compressed binary blob (using the shrink package) and to restore its state
from such a compressed backup. This is useful for efficient storage, transfer,
and backup of box data, especially when dealing with large datasets or when
minimizing storage footprint is important.
Example
// Export box contents to a compressed binary backup
final compressed = await box.generateBackupCompressed(
keyToString: (key) => key.toString(),
valueToJson: (value) => value.toJson(),
);
// Restore box contents from a compressed binary backup
await box.restoreBackupCompressed(
compressed,
stringToKey: (str) => int.parse(str),
jsonToValue: (json) => MyModel.fromJson(json),
);
Details
- The backup is first serialized to JSON (see generateBackupJson), then compressed
using the
shrinkpackage to produce a Uint8List. - The restore process decompresses the binary data back to a JSON string, then restores the box contents using restoreBackupJson.
- This approach is compatible with any box whose keys and values can be serialized to and from JSON.
See also:
- generateBackupJson and restoreBackupJson for JSON-based backup/restore.
- shrink for compression details.
- on
-
- BoxInterface<
K, T>
- BoxInterface<
Methods
-
generateBackupCompressed(
{String keyToString(K key)?, Object? valueToJson(T value)?}) → Future< Uint8List> -
Available on BoxInterface<
Generates a compressed binary backup (Uint8List) of all key-value pairs in the box.K, T> , provided by the BackupCompressedExtension extension -
restoreBackupCompressed(
Uint8List data, {required K stringToKey(String key), required T jsonToValue(dynamic json)}) → Future< void> -
Available on BoxInterface<
Restores the box contents from a compressed binary backup (Uint8List).K, T> , provided by the BackupCompressedExtension extension