You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.1 KiB
JavaScript
37 lines
1.1 KiB
JavaScript
import { openDB } from 'indexed-pdb'
|
|
|
|
export const DB_NAME = "/com.nesbox.tic/TIC-80";
|
|
export const DB_STORE = "FILE_DATA";
|
|
|
|
export function filename_from_key (key) {
|
|
if (key.startsWith(DB_NAME+"/")) { return key.substr((DB_NAME+"/").length); }
|
|
}
|
|
|
|
export async function load_key (key) {
|
|
const db = await openDB(DB_NAME),
|
|
objectStore = db.transaction([DB_STORE], "readonly").objectStore(DB_STORE);
|
|
return await objectStore.get(key);
|
|
}
|
|
|
|
export async function save_key (key, item) {
|
|
const db = await openDB(DB_NAME),
|
|
objectStore = db.transaction([DB_STORE], "readwrite").objectStore(DB_STORE);
|
|
return await objectStore.put(item, key);
|
|
}
|
|
|
|
export async function save_cart(filename, cart, mode) {
|
|
return await save_key(DB_NAME+"/"+filename, {timestamp: new Date(), contents: cart.tobuffer(), mode: mode});
|
|
}
|
|
|
|
export function compareBuffers (a, b) {
|
|
var ad = new DataView(a.buffer),
|
|
bd = new DataView(b.buffer);
|
|
if (ad.byteLength != bd.byteLength) { return false; }
|
|
for (var i=0; i<ad.byteLength; i++) {
|
|
if (ad.getUint8(i, 1) != bd.getUint8(i, 1)) { return false;}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
|