A VFS implementation based on the file system access API without shared workers.
The file system access API provides synchronous access to opened files. These need to be opened first however, and that process is asynchronous. SQLite, being a C library, expects synchronous access to the file system. WasmVfs is a workaround for this problem that relies on a pair of workers that together make asynchronous APIs synchronous.
- One worker is responsible for hosting the database. This worker installs a WasmVfs on the registered SQLite instance. The worker uses WasmVfs.createOptions to obtain an options object containing shared array buffers for efficient communication.
- Another worker is hosting the file system. This is asynchronous, but by
using
Atomics
APIs and the shared array buffers, the database worker can access the file system synchronously.
The second worker is implemented by VfsWorker. Note that WasmVfs is only
available in browsing contexts where shared array buffers and atomics are
available.
For an automatic feature detection and logic to pick a suitable
implementation based on browser features, consider using a package like
sqlite3_web
(or sqlite_async
for cross-platform support).
- Inheritance
Constructors
- WasmVfs({Random? random, required WorkerOptions workerOptions, String chroot = '/', String vfsName = 'dart-sqlite3-vfs'})
Properties
- chroot → String
-
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- name → String
-
The name of this virtual file system.
finalinherited
- pathContext → Context
-
final
- random → Random
-
finalinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- serializer → MessageSerializer
-
final
- synchronizer → RequestResponseSynchronizer
-
final
Methods
-
close(
) → void -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
xAccess(
String path, int flags) → int -
Check whether a file can be accessed.
override
-
xCurrentTime(
) → DateTime -
Returns the current time.
inherited
-
xDelete(
String path, int syncDir) → void -
Delete a file.
override
-
xFullPathName(
String path) → String -
Resolves a
path
name supplied by the user into a path that can be used by the other methods of this VFS.override -
xOpen(
Sqlite3Filename path, int flags) → XOpenResult -
Opens a file, returning supported flags and a file instance.
override
-
xRandomness(
Uint8List target) → void -
Fill the
target
with random bytes.inherited -
xSleep(
Duration duration) → void -
Sleeps for the passed
duration
.override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
-
no setter
Static Methods
-
createOptions(
{String root = 'pkg_sqlite3_db/'}) → WorkerOptions - Creates WorkerOptions that can be sent to an VfsWorker instance which is responsible for hosting the file system on the other end.