Skip to content

createFileStore

Creates a file store on a named Cache API cache: keep a computed set of files (a bake, a download, extracted layers) under a key and a version, and read it back later, even offline. Cache entries are keyed by made-up URLs, so nothing is ever fetched.

Outside a browser (no caches), put stores nothing and get always misses, so a caller works without a cache, only slower.

Available since v3.1.10

import { createFileStore } from '@helpers4/browser';
// or, from the all-in-one package (same code, one install):
import { createFileStore } from 'helpers4/browser';
createFileStore(name: string): FileStore
ParameterTypeDescription
namestringThe name of the cache, shared by every store with that name

FileStore — The FileStore

Files go under a key and a version; a new version is a miss.

const store = createFileStore('bakes');
await store.put('design-1', { 'a.png': blob, 'index.json': '{}' }, 'v3');
const files = await store.get('design-1', 'v3'); // => { 'a.png': Blob, 'index.json': Blob }

A set of files kept in the browser’s Cache API under a key, created by createFileStore.

interface FileStore {
  delete(key: string): Promise<boolean>;
  get(key: string, version?: string): Promise<Record<string, Blob> | undefined>;
  put(key: string, files: Record<string, FileContent>, version?: string): Promise<boolean>;
}

What createFileStore accepts as a file’s content.

type FileContent = Blob | BufferSource | string

View source on GitHub