vunt
v1.0.2
Published
A browser-first, content-addressed chunk store with a simple API and GC, designed to run without a build step and verified via Cypress E2E tests. The store is now OPFS-backed for persistence in modern browsers.
Downloads
9
Readme
vunt
A browser-first, content-addressed chunk store with a simple API and GC, designed to run without a build step and verified via Cypress E2E tests. The store is now OPFS-backed for persistence in modern browsers.
- No build/transpile: native ESM, modern browsers
- Persistent storage: OPFS (Origin Private File System)
- Tests: Cypress
- Hashing: Web Crypto SHA-256 (64-hex digest)
See chunk-store-prd.md for the full PRD.
Quick start
Prereqs: Node 18+ and pnpm.
pnpm i
pnpm dev # serves the demo at http://localhost:3000
# In another terminal
pnpm cy:open # interactive
# or
pnpm cy:run # headlessDemo: using the API in the browser
Open http://localhost:3000. The demo page lets you:
- Create a store
- Put text and see the resulting hash
- Check
has(hash)andget(hash) - Run a GC cycle: beginGCCycle -> markReachable -> sweep
- Inspect
getStats()
The page imports the library directly:
<script type="module">
import { createChunkStore, enc, dec } from "../index.js";
// ...
</script>Library API
The interface follows the PRD. The implementation is browser-native and OPFS-backed for persistence.
interface ChunkStore {
// Core operations
put(data: Uint8Array): Promise<string>; // returns sha256 hex
get(hash: string): Promise<Uint8Array | null>;
has(hash: string): Promise<boolean>;
// Garbage collection
beginGCCycle(): Promise<void>;
markReachable(hash: string): Promise<void>;
sweep(): Promise<void>;
// Management
close(): Promise<void>;
getStats(): Promise<StoreStats>;
}
interface StoreStats {
totalChunks: number;
totalSize: number;
segmentCount: number;
cacheHitRate: number;
}
interface ChunkStoreConfig {
name: string;
segmentSize?: number;
cacheSize?: number;
writeBufferSize?: number;
hashAlgorithm?: "sha256" | "blake3"; // currently only sha256 is implemented
}
// Factory
function createChunkStore(config?: ChunkStoreConfig): Promise<ChunkStore>;Examples
Basic put/get
import { createChunkStore, enc, dec } from "vunt";
const store = await createChunkStore({ name: "demo" });
const hash = await store.put(enc("hello vunt"));
console.log("hash:", hash); // 64-hex sha256
const data = await store.get(hash);
console.log("value:", data ? await dec(data) : null);Existence check
const ok = await store.has(hash);
console.log("has?", ok);GC cycle (mark-and-sweep)
await store.beginGCCycle();
await store.markReachable(hash); // mark the chunk you want to keep
await store.sweep(); // unmarked chunks are removedStats and teardown
const stats = await store.getStats();
console.log(stats); // { totalChunks, totalSize, segmentCount, cacheHitRate }
await store.close();Project structure
src/index.js— public exports; OPFS-backed store under the PRD APIsrc/webapp/index.html— demo UI to explore APIsrc/webapp/server.js— ESM static dev server (http://localhost:3000)cypress/— E2E tests;basic.cy.jsruns the demo app flowchunk-store-prd.md— Product Requirements Documentdirectory.md— Repo map and developer guide
Notes and constraints
- Browser-first, no bundler: public modules must be loadable directly by the browser (ESM only)
- Hashing: Web Crypto SHA-256; BLAKE3 may be considered later
- Storage: OPFS-backed segments with in-memory index and simple GC rewrite
Types
This library is authored in plain JavaScript and ships TypeScript type declarations only. No runtime build step is required.
- Types output:
dist/types/index.d.ts - Entry points: ESM at
src/index.js, types viapackage.json#typesandexportsmap
Usage:
import {
createChunkStore,
enc,
dec,
type ChunkStore,
type ChunkStoreConfig,
} from "vunt";
const cfg: ChunkStoreConfig = { name: "demo" };
const store: ChunkStore = await createChunkStore(cfg);Roadmap
- MVP: OPFS segments + in-memory index;
put/get/haspersistently — DONE - GC: mark-and-sweep across segments; compaction; index persistence (basic GC rewrite present; index persistence TBD)
- Performance: write batching, LRU cache, Bloom filter for
has - Reliability: WAL, crash recovery, checksums
License
ISC
