open static method
Opens the logical file at path.
create: truecreates an empty file when the manifest is missing.readOnly: truerejects every mutating call with a StateError and impliescreate: false(matchingdart:io'sFileMode.read).chunkSizeapplies only to newly created files; an existing file keeps the chunk size recorded in its manifest.
Implementation
static Future<WebOpfsBytesFile> open(
String path, {
bool create = true,
bool readOnly = false,
int chunkSize = kDefaultChunkSize,
int? workers,
}) async {
final normalized = normalizeLogicalPath(path);
if (chunkSize < kMinChunkSize || chunkSize > kMaxChunkSize) {
throw RangeError.range(
chunkSize,
kMinChunkSize,
kMaxChunkSize,
'chunkSize',
);
}
final pool = await OpfsWorkerPool.instance(workers: workers);
final loaded = await _loadBestManifest(pool.manifest, normalized);
final WebManifestState manifest;
if (loaded == null) {
if (!create || readOnly) {
throw WebFileSystemException(
'NotFoundError',
'File does not exist',
path: normalized,
);
}
manifest = WebManifestState(path: normalized, chunkSize: chunkSize);
} else {
manifest = loaded.state;
}
final file = WebOpfsBytesFile._(
path: normalized,
readOnly: readOnly,
chunkSize: manifest.chunkSize,
pool: pool,
manifest: manifest,
slot: loaded?.slot ?? -1,
);
if (loaded == null) {
// Materialize the store directory and slot A so `create` is durable.
await file._persist();
}
return file;
}