Skip to content

Commit e8a7aad

Browse files
committed
Unconditionally store array buffers
1 parent 234df84 commit e8a7aad

File tree

1 file changed

+1
-48
lines changed

1 file changed

+1
-48
lines changed

sqlite3/lib/src/wasm/vfs/indexed_db.dart

+1-48
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,6 @@ class AsynchronousIndexedDbFileSystem {
4646
web.IDBDatabase? _database;
4747
final String _dbName;
4848

49-
/// Whether to store chunks as [web.Blob]s instead of array buffers.
50-
///
51-
/// It seems like loading blobs concurrently may be more efficient, but not
52-
/// all browsers support storing blobs in IndexedDB. We support both blobs
53-
/// and array buffers on the read path. For writes, we run a feature detection
54-
/// after opening the file system to determine whether to store blobs.
55-
bool _storeBlobs = true;
56-
5749
AsynchronousIndexedDbFileSystem(this._dbName);
5850

5951
bool get _isClosed => _database == null;
@@ -87,44 +79,6 @@ class AsynchronousIndexedDbFileSystem {
8779
final openFuture = openRequest.completeOrBlocked<web.IDBDatabase>();
8880
completer.complete(openFuture);
8981
_database = await completer.future;
90-
91-
_storeBlobs = await _supportsStoringBlobs();
92-
}
93-
94-
/// Probes whether the IndexedDB implementation supports storing [web.Blob]
95-
/// instances.
96-
///
97-
/// Safari in private windows does not support storing blobs, but allows
98-
/// storing array buffers directly. Our read paths support reading blobs and
99-
/// array buffers, so we use this to determine which format to use for writes.
100-
Future<bool> _supportsStoringBlobs() async {
101-
final transaction =
102-
_database!.transaction([_blocksStore.toJS].toJS, 'readwrite');
103-
104-
web.Blob blob;
105-
106-
try {
107-
final blocks = transaction.objectStore(_blocksStore);
108-
109-
final request = blocks.add(
110-
web.Blob([Uint8List(4096).buffer.toJS].toJS),
111-
['test'.toJS].toJS,
112-
);
113-
final key = await request.complete();
114-
115-
blob = await blocks.get(key).complete<web.Blob>();
116-
} on Object {
117-
return false;
118-
} finally {
119-
transaction.abort();
120-
}
121-
122-
try {
123-
await blob.byteBuffer();
124-
return true;
125-
} on Object {
126-
return false;
127-
}
12882
}
12983

13084
void close() {
@@ -314,8 +268,7 @@ class AsynchronousIndexedDbFileSystem {
314268
.openCursor(web.IDBKeyRange.only([fileId.toJS, blockStart.toJS].toJS))
315269
.complete<web.IDBCursorWithValue?>();
316270

317-
final value =
318-
_storeBlobs ? web.Blob([block.toJS].toJS) : block.buffer.toJS;
271+
final value = block.buffer.toJS;
319272

320273
if (cursor == null) {
321274
// There isn't, let's write a new block

0 commit comments

Comments
 (0)