make<K1, V1> static method
Create a PersistentMap with K1
for keys and V1
for values,
with file
being the database file, and create
specifying
whether to create a new file if it doesn't exist. If file
already exists, the file will not be overwritten, but rather opened.
The serializers for the keys and values must be provided when calling
this function. If file
contains and incompatible database, behavior
is unspecified.
Implementation
static PersistentMap<K1, V1> make<K1, V1>(
final File file,
final Uint8List Function(K1) keySerializer,
final K1 Function(Uint8List) keyDeserializer,
final Uint8List Function(V1) valueSerializer,
final V1 Function(Uint8List) valueDeserializer,
{bool create = false,
bool Function(V1, V1)? comparator}) {
late final RandomAccessFile _random;
if (file.existsSync()) {
_random = file.openSync(mode: FileMode.append);
} else if (create) {
file.createSync(recursive: true);
_random = file.openSync(mode: FileMode.write);
} else {
throw StateError('File does not exist and create flag not specified.');
}
DBM dbm = HashDBM(_random);
return PersistentMap<K1, V1>(
dbm, keySerializer, keyDeserializer, valueSerializer, valueDeserializer,
valueComparator: comparator);
}