Skip to content
Permalink
Browse files

Renamed Hive.openBoxFromBytes()

  • Loading branch information...
leisim committed Nov 4, 2019
1 parent b234dec commit 5eaa460cad33e79ecc229237cd04ae3ecbffbe66
Showing with 11 additions and 10 deletions.
  1. +1 −0 CHANGELOG.md
  2. +3 −3 lib/src/hive.dart
  3. +4 −4 lib/src/hive_impl.dart
  4. +2 −2 test/hive_impl_test.dart
  5. +1 −1 test/hive_list_impl_test.dart
@@ -3,6 +3,7 @@
### Breaking changes
- Box names now have to be ASCII strings with a max length of 255 chars
- Removed the `Hive.path` getter
- Renamed `Hive.openBoxFromBytes()` to `Hive.openMemoryBox()`

### Enhancements
- Added `HiveList`s to support one-to-many relationships
@@ -23,9 +23,9 @@ abstract class HiveInterface implements TypeRegistry {
/// Opens an in-memory box from a list of bytes. It does not persist changes.
///
/// This is useful for opening boxes from an asset file.
Future<Box<E>> openBoxFromBytes<E>(
String name,
Uint8List bytes, {
Future<Box<E>> openMemoryBox<E>(
String name, {
Uint8List bytes,
List<int> encryptionKey,
KeyComparator keyComparator,
});
@@ -87,17 +87,17 @@ class HiveImpl extends TypeRegistryImpl implements HiveInterface {
}

@override
Future<Box<E>> openBoxFromBytes<E>(
String name,
Uint8List bytes, {
Future<Box<E>> openMemoryBox<E>(
String name, {
List<int> bytes = const [],
List<int> encryptionKey,
KeyComparator keyComparator,
}) async {
if (isBoxOpen(name)) {
return box(name);
} else {
var crypto = getCryptoHelper(encryptionKey);
var backend = StorageBackendMemory(bytes, crypto);
var backend = StorageBackendMemory(Uint8List.fromList(bytes), crypto);
var box = BoxImpl<E>(this, name, keyComparator, null, backend);
await box.initialize();
_boxes[name.toLowerCase()] = box;
@@ -95,8 +95,8 @@ void main() {
group('.openBoxFromBytes()', () {
test('opened box is returned if it exists', () async {
var hive = HiveImpl();
var testBox = await hive.openBoxFromBytes('testBox', frameBytes[0]);
var testBox2 = await hive.openBoxFromBytes('testBox', Uint8List(0));
var testBox = await hive.openMemoryBox('testBox', bytes: frameBytes[0]);
var testBox2 = await hive.openMemoryBox('testBox');
expect(testBox == testBox2, true);

await hive.close();
@@ -27,7 +27,7 @@ void main() {

test('returns the box', () async {
var hive = HiveImpl();
var box = await hive.openBoxFromBytes('someBox', Uint8List(0));
var box = await hive.openMemoryBox('someBox');
var hiveList = HiveListImpl.debug('someBox', [], hive);
expect(hiveList.box, box);
});

0 comments on commit 5eaa460

Please sign in to comment.
You can’t perform that action at this time.