Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions playground/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ document.querySelector('.main')?.addEventListener('click', async () => {
if (!db) {
// @ts-expect-error no types
const root = await window.showDirectoryPicker()
// const root = await navigator.storage.getDirectory()
// db = await initSQLite(useIdbMemoryStorage('test.db', { url }))
db = await initSQLite(useFsHandleStorage('test.db', root, { url }))
// db = await initSQLite(useIdbStorage('test.db', { url }))
}
await runSQL(db.run)
await runSQL((await initSQLite(useMemoryStorage({ url: syncUrl }))).run)
// await runSQL((await initSQLite(useMemoryStorage({ url: syncUrl }))).run)
await db.close()
})
document.querySelector('.import')?.addEventListener('click', async () => {
await db?.close()
Expand Down Expand Up @@ -145,7 +147,7 @@ document.querySelector('.importW')?.addEventListener('click', async () => {
}
})
document.querySelector('.clear')?.addEventListener('click', async () => {
await db?.close()
await db?.close().catch()
const root = await navigator.storage.getDirectory()
for await (const [name] of root.entries()) {
await root.removeEntry(name, { recursive: true })
Expand Down
8 changes: 7 additions & 1 deletion src/vfs/class/OPFSAnyContextVFS.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,13 @@ export class OPFSAnyContextVFS extends WebLocksMixin(FacadeVFS) {
try {
const file = this.mapIdToFile.get(fileId)

console.time('[read]')
if (file.writable) {
console.timeLog('[read]', 'start close writable')
await file.writable.close()
file.writable = null
file.blob = null
console.timeLog('[read]', 'end close writable')
}
if (!file.blob) {
file.blob = await file.fileHandle.getFile()
Expand All @@ -177,8 +180,10 @@ export class OPFSAnyContextVFS extends WebLocksMixin(FacadeVFS) {

if (bytesRead < pData.byteLength) {
pData.fill(0, bytesRead)
console.timeEnd('[read]')
return VFS.SQLITE_IOERR_SHORT_READ
}
console.timeEnd('[read]')
return VFS.SQLITE_OK
} catch (e) {
this.lastError = e
Expand All @@ -196,13 +201,14 @@ export class OPFSAnyContextVFS extends WebLocksMixin(FacadeVFS) {
try {
const file = this.mapIdToFile.get(fileId)

console.time('[write]')
if (!file.writable) {
file.writable = await file.fileHandle.createWritable({ keepExistingData: true })
}
await file.writable.seek(iOffset)
await file.writable.write(pData.subarray())
file.blob = null

console.timeEnd('[write]')
return VFS.SQLITE_OK
} catch (e) {
this.lastError = e
Expand Down