open static method

Future<WebIndexedDbBytesFile> open(
  1. String path, {
  2. bool create = true,
  3. bool readOnly = false,
  4. int chunkSize = kIdbDefaultChunkSize,
  5. String databaseName = kIdbDatabaseName,
  6. String storeName = kIdbStoreName,
})

Opens or creates path in the shared IndexedDB store.

Implementation

static Future<WebIndexedDbBytesFile> open(
  String path, {
  bool create = true,
  bool readOnly = false,
  int chunkSize = kIdbDefaultChunkSize,
  String databaseName = kIdbDatabaseName,
  String storeName = kIdbStoreName,
}) async {
  final normalized = normalizeLogicalPath(path);
  if (chunkSize < kIdbMinChunkSize || chunkSize > kIdbMaxChunkSize) {
    throw RangeError.range(
      chunkSize,
      kIdbMinChunkSize,
      kIdbMaxChunkSize,
      'chunkSize',
    );
  }
  final store = await _IdbStore.open(databaseName, storeName);
  final metaBytes = await store.get(idbMetaKey(normalized));
  final meta = metaBytes == null ? null : decodeIdbMeta(metaBytes);
  if (meta == null) {
    if (!create || readOnly) {
      throw WebIndexedDbException(
        'NotFoundError',
        'No IndexedDB metadata for $normalized',
        path: normalized,
      );
    }
    final file = WebIndexedDbBytesFile._(
      path: normalized,
      readOnly: readOnly,
      chunkSize: chunkSize,
      store: store,
      logicalLength: 0,
      exists: false,
    );
    await file._persistMeta();
    file._exists = true;
    return file;
  }
  return WebIndexedDbBytesFile._(
    path: normalized,
    readOnly: readOnly,
    chunkSize: meta.chunkSize,
    store: store,
    logicalLength: meta.logicalLength,
    exists: true,
  );
}