-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(memfs): finish importFromZip logic
- Loading branch information
Showing
6 changed files
with
146 additions
and
63 deletions.
There are no files selected for viewing
Binary file modified
BIN
+297 Bytes
(120%)
packages/extensions/js-runner-and-debugger/assets/demo.zip
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
packages/extensions/js-runner-and-debugger/src/web/utils/indexed-db.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
export class IndexedDBWrapper { | ||
private dbName: string; | ||
private storeName: string; | ||
private db: IDBDatabase | null = null; | ||
|
||
constructor(dbName: string, storeName: string) { | ||
this.dbName = dbName; | ||
this.storeName = storeName; | ||
} | ||
|
||
async open(): Promise<void> { | ||
return new Promise((resolve, reject) => { | ||
const request = indexedDB.open(this.dbName); | ||
request.onupgradeneeded = () => { | ||
const db = request.result; | ||
if (!db.objectStoreNames.contains(this.storeName)) { | ||
db.createObjectStore(this.storeName); | ||
} | ||
}; | ||
request.onsuccess = () => { | ||
this.db = request.result; | ||
resolve(); | ||
}; | ||
request.onerror = () => { | ||
reject(request.error); | ||
}; | ||
}); | ||
} | ||
|
||
async put(key: string, value: any): Promise<void> { | ||
return new Promise((resolve, reject) => { | ||
if (!this.db) throw new Error('Database not opened yet'); | ||
const transaction = this.db.transaction(this.storeName, 'readwrite'); | ||
const store = transaction.objectStore(this.storeName); | ||
const request = store.put(value, key); | ||
request.onsuccess = () => resolve(); | ||
request.onerror = () => reject(request.error); | ||
}); | ||
} | ||
|
||
async get(key: string): Promise<any> { | ||
return new Promise((resolve, reject) => { | ||
if (!this.db) throw new Error('Database not opened yet'); | ||
const transaction = this.db.transaction(this.storeName, 'readonly'); | ||
const store = transaction.objectStore(this.storeName); | ||
const request = store.get(key); | ||
request.onsuccess = () => resolve(request.result); | ||
request.onerror = () => reject(request.error); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters