FileKeyValueStore class final
A KeyValueStore in a directory of the file system (Dart VM: command-line tools, servers, Flutter desktop).
One file per key, named by the SHA-256 of the key, written atomically (a temporary file renamed over
the old one). Calls run one at a time, in order. An update whose transform returns the value it was
given writes nothing. A value over 16 MiB is refused with storage-error; an entry at a key's path
that is not a regular file (a directory, a pipe) counts as absent.
One process owns the directory. The first call takes an exclusive OS lock on
<directory>/.owner.lock and keeps it until close; while another process holds it every call
throws FirebaseInstallationsException('storage-error'). Two stores of one isolate on the same
directory are refused with a StateError, also when their first calls overlap; the directory is
free again when the close of its store completes. On Linux and macOS the OS lock does not separate isolates
of one process: do not give the same directory to stores in two isolates.
Permissions. The directory is created when missing. On Linux and macOS the first call runs
chmod 700 on it and checks that no other user can access it, else it throws storage-error. On
Windows use a directory in the user's profile (%APPDATA%\<app> or %LOCALAPPDATA%\<app>). The
files hold the installation's refresh token unencrypted: other programs of the same user can read it.
final FileKeyValueStore store = FileKeyValueStore(
'${Platform.environment['HOME']}/.config/my_tool/firebase',
);
- Implemented types
Constructors
- FileKeyValueStore(String directory, {InstallationsLogger? logger})
-
A store in
directory. Nothing is read or created until the first call. -
FileKeyValueStore.test(String directory, {InstallationsLogger? logger, Future<
ProcessResult> runCommand(String executable, List<String> arguments)?, DateTime clock()?}) -
Like the main constructor, with
runCommand(replacesProcess.run, used forchmodand the permission check) andclock(the time the stale-file rule compares with) for tests.
Properties
-
changes
→ Stream<
String> -
Keys changed by another writer where the storage can tell: IndexedDB emits; memory and file stores
never emit. A hint to read again; it carries no value.
no setteroverride
- directory → String
-
The directory of the store, as given to the constructor.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
close(
) → Future< void> -
Releases the store: calls made before it still run, then the OS lock is released and the directory
is free for another store. Every call of
closecompletes when that is done.override -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
read(
String key) → Future< String?> -
The value stored under
key, or null when there is none.override -
remove(
String key) → Future< void> -
Removes
key; nothing happens when it is absent.override -
toString(
) → String -
A string representation of this object.
inherited
-
update(
String key, String? transform(String? current)) → Future< String?> -
Reads
key, callstransformsynchronously, writes its result (null removes), returns it.override -
write(
String key, String value) → Future< void> -
Stores
valueunderkey, all or nothing.override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited