buckethead.files.store¶
Content-addressable blob store backed by one R2 object per blob.
buckethead.files.store
¶
FileStore: content-addressable blob store backed by S3-compatible storage.
Metadata lives in the caller's sqlite3.Connection; bytes live as one object
per blob under a configurable prefix in the BucketClient's bucket. The
filestore table is created on FileStore construction, so it's always
present once the store exists.
See plan/build-plan.md — Phase 10 and issue #3 for the design decisions.
FileStore
¶
FileStore(
conn: Connection,
bucket_client: BucketClient,
prefix: str = "files/",
)
Bases: Interface
Content-addressable blob store. Owns the filestore table and a
prefix in R2. Note: the table name predates the bh_ prefix
convention documented in Interface — grandfathered in.
Source code in src/buckethead/files/store.py
put
¶
put(
data: bytes | Path,
*,
filename: str | None = None,
mime: str | None = None,
metadata: dict[str, str] | None = None,
) -> str
Upload; returns the bh-key (SHA-256 hex of contents).
If the bh-key already exists in both tiers, this is a pure no-op — any new metadata passed in is ignored. If the R2 object exists but the SQLite row is missing (e.g., crashed mid-put), the row is filled in with the arguments from this call.
Source code in src/buckethead/files/store.py
metadata
¶
Return the stored metadata for bh_key, or None if absent.
gc
¶
Reconcile R2 objects under prefix against SQLite rows.
- Orphans (R2 object with no SQLite row) younger than
grace_secondsare skipped (covers in-flight puts). - Older orphans are deleted from R2.
- Dangling rows (SQLite row whose R2 object is gone) are counted but not auto-deleted — a human decides.