@bytecask/core

中文文档
2026.7.5发布于 2026/07/17AGPL-3.0-onlyTypeScriptES Module构建来源已验证近 30 天下载 1.2万

Browser-native content-addressed binary blob store — BLAKE3 addressing, tiered storage adapters (OPFS via worker, IndexedDB, memory), dedup, refcount, GC.

原始使用文档
文档目录12 节
  1. What It Is
  2. Highlights
  3. Installation
  4. Quick Start
  5. Storage Backends
  6. Lifecycle Models
  7. Main API
  8. Browser Support
  9. Related Packages
  10. Documentation
  11. Security
  12. License

@bytecask/core

Browser-native, content-addressed blob storage.

Store binary data in IndexedDB, OPFS, or memory behind one typed API with BLAKE3 addressing, deduplication, lifecycle accounting, and recovery tools.

pnpm add @bytecask/core

npm downloads license TypeScript

Quick Start · Backends · API · Browser Support · Documentation


What It Is

@bytecask/core is the framework-neutral Bytecask storage engine. It accepts Blob, Uint8Array, or streamed bytes and returns a lowercase BLAKE3 content hash. Identical content is stored once, while lifecycle metadata determines whether the object is live, collectible, or missing.

It providesIt deliberately leaves to the host
Content-addressed binary storageRecords and relational data
IndexedDB, OPFS, and memory adaptersUser authorization and synchronization
Deduplication, references, GC, reconciliationSigning and publisher identity
Quota and integrity errorsThe only copy of irreplaceable data
Portable blobs/<hash> packingProduct-specific attachment workflows

Highlights

  • BLAKE3 content identity: stable hashes support deduplication and portable manifests.
  • IndexedDB-first persistence: broad cross-browser storage without a database dependency.
  • Optional OPFS streaming: worker-backed large-file I/O is loaded only when selected.
  • Explicit lifecycle models: use refcounts or reconcile against a canonical host manifest.
  • Failure-aware writes: partial objects are removed after quota, metadata, integrity, or streaming failures.
  • ESM and TypeScript: typed public exports with no top-level browser-global access, so importing during SSR is safe.

Installation

Install the core package for IndexedDB, memory, and automatic backend selection:

pnpm add @bytecask/core

Add the worker package only when using OPFS:

pnpm add @bytecask/core @bytecask/worker

Quick Start

import { createBlobStore } from '@bytecask/core'

const store = await createBlobStore({ backend: 'idb' })
const hash = await store.put(new Blob(['hello, Bytecask']))

console.log(hash) // lowercase BLAKE3 hex

const blob = await store.getBlob(hash)
const bytes = await store.get(hash)

await store.close()

Automatic selection tries IndexedDB, then OPFS, then memory and exposes the result as store.backend. Force a persistent backend for archives that must never degrade to session memory.

Storage Backends

BackendSelectionPersistenceBest fit
IndexedDBDefault persistent tierBrowser-managed, evictableGeneral files and attachments
OPFSExplicit or automatic fallbackBrowser-managed, evictableStreaming and large binary objects
MemoryExplicit or final fallbackSession onlyTests, previews, and ephemeral data
const store = await createBlobStore({
  backend: 'idb',
  idb: { databaseName: 'archive-blobs' },
  metadata: { databaseName: 'archive-metadata' },
  verifyOnRead: true,
})

const persistenceGranted = await store.requestPersistence()
const report = await store.reconcile(liveAttachmentHashes)

A forced backend rejects when unavailable. It never silently changes the requested durability model.

Lifecycle Models

Choose one authority per store:

  1. Store-managed: put() creates a reference; balance ownership with ref() and unref(), then collect with gc().
  2. Host-managed: retain hashes in a canonical manifest and call reconcile(liveHashes) to repair metadata and identify missing or unreferenced bytes.

Do not maintain independent refcount systems for the same archive.

Main API

ExportPurpose
createBlobStore(options)Select or force a storage backend
put, get, getBlob, has, deleteStore and retrieve bytes by hash
ref, unref, gcStore-managed lifecycle accounting
reconcile(liveHashes)Repair state from a host-authoritative manifest
subscribe(listener)Observe local byte-store mutation outcomes
estimate, requestPersistenceObserve browser storage and persistence
packBlobs, unpackBlobsMove portable blobs/<hash> entries
BytecaskError, QuotaError, IntegrityErrorHandle typed storage failures
const unsubscribe = store.subscribe((event) => {
  if (event.type === 'put') {
    console.log(event.hash, event.refcount)
  }
})

The change feed is store-level and local to the BlobStore instance. It emits Bytecask byte/lifecycle outcomes, not host record semantics or cross-tab sync messages.

Browser Support

  • IndexedDB behavior is tested in Chromium, Firefox, and Playwright WebKit.
  • OPFS worker behavior is tested in Chromium and Firefox.
  • Memory storage works in browser and JavaScript test environments.
  • The package is ESM-only and targets modern browsers.

Playwright WebKit is an engine proxy, not Apple's shipping Safari binary. Treat browser storage as a rebuildable local copy because persistence requests reduce eviction risk but cannot eliminate it.

PackagePurpose
@bytecask/workerOptional OPFS worker and streaming I/O
@bytecask/reactOptional React provider and hooks

Documentation

Security

Bytecask verifies content identity, not publisher identity. Verify signed containers or shards before hydrating untrusted bytes. Report vulnerabilities through the project's security policy, not a public issue.

License

AGPL-3.0-only. See LICENSE.

版本与发布记录

@bytecask/core 共发布 3 个版本,首次发布于 2026/07/15;过去 12 个月发布了 3 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
2026.7.5latest2026/07/173 个月前
2026.7.42026/07/153 个月前
2026.7.22026/07/153 个月前

关于 @bytecask/core 的常见问题

@bytecask/core 是什么?

Browser-native content-addressed binary blob store — BLAKE3 addressing, tiered storage adapters (OPFS via worker, IndexedDB, memory), dedup, refcount, GC.

如何安装 @bytecask/core?

在项目目录运行 npm install @bytecask/core,或使用 pnpm add / yarn add / bun add。

@bytecask/core 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@bytecask/core 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@bytecask/core 可以商用吗?

@bytecask/core 使用 AGPL-3.0-only 许可。最严格的 Copyleft:除分发外,通过网络向用户提供基于它的服务也需要开源对应源码。闭源 SaaS 使用前务必评估。以上为概括,不构成法律意见,请以许可原文为准。

@bytecask/core 的下载量有多少?

根据 npm 官方下载统计,@bytecask/core 在 2026/10/09 – 2026/11/07 这 30 天内被下载 12,109 次,日均约 404 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@bytecask/core 还在维护吗?

最新版本 2026.7.5 发布于 2026/07/17(3 个月前);至今共发布 3 个版本,其中过去 12 个月发布了 3 个;首次发布于 2026/07/15。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。