mooncas

    A portable content-addressed storage kernel for MoonBit

    cas
    storage
    sha256
    deduplication
    Download zip
    Version
    0.1.0
    License
    Apache-2.0
    Last updated
    15 hours ago
    Downloads
    2

    #MoonCAS

    MoonCAS is a small, pure-MoonBit content-addressed storage kernel. It turns bytes into SHA-256 identifiers, deduplicates equal content, verifies imported blobs, tracks live references, collects unreachable data, and splits large objects into independently reusable chunks.

    The current MVP is deliberately backend-neutral and ships an in-memory store. The abstraction is intended to sit below build caches, package registries, artifact managers, and reproducible pipelines.

    #Highlights

    • Portable SHA-256 implementation with standard test vectors
    • Idempotent put, get, has, and delete operations
    • Expected-digest verification for safe imports
    • Reference counting, protected deletion, and garbage collection
    • Fixed-size chunk manifests with cross-object deduplication and owned references
    • Tests and CI for the Wasm, Wasm-GC, and JavaScript backends

    #Run

    moon test --deny-warn moon run cmd/main

    #Library example

    ///|
    test {
    let store = @mooncas.MemoryStore::new()
    let id = store.put(b"hello")
    assert_true(store.has(id))
    assert_true(store.verify(id))
    }

    #Scope

    This release is a verifiable in-memory reference implementation. Filesystem, HTTP/S3-compatible backends, persisted manifests, and concurrent access are roadmap items rather than claims of the current MVP. The project complements object-store clients by defining content identity, integrity, chunking, reachability, and collection semantics.

    Licensed under Apache-2.0.

    ChunkedBlob

    pub struct ChunkedBlob {
    chunks : Array[Digest]
    length : Int
    }

    A logical blob split into independently deduplicated chunks.

    ChunkedBlob::chunk_count

    fn ChunkedBlob::chunk_count(self : ChunkedBlob) -> Int

    ChunkedBlob::length

    fn ChunkedBlob::length(self : ChunkedBlob) -> Int

    Digest

    pub struct Digest {
    hex : String
    }

    A SHA-256 content identifier encoded as lowercase hexadecimal.

    Digest::to_string

    fn Digest::to_string(self : Digest) -> String

    MemoryStore

    pub struct MemoryStore {
    blobs :
    HashMap
    [String, Bytes]
    pins :
    HashMap
    [String, Int]
    }

    An in-memory content-addressed blob store for tests and ephemeral caches.

    MemoryStore::collect

    fn MemoryStore::collect(self : MemoryStore) -> Int

    Delete every unpinned blob and return the number collected.

    MemoryStore::delete

    fn MemoryStore::delete(self : MemoryStore, id : Digest) -> Bool

    Delete an unpinned blob. Returns false when live references still exist.

    MemoryStore::get

    fn MemoryStore::get(self : MemoryStore, id : Digest) -> Bytes?

    MemoryStore::get_chunked

    fn MemoryStore::get_chunked(self : MemoryStore, manifest : ChunkedBlob) -> Bytes?

    Reassemble a chunked blob, returning None if any chunk is unavailable.

    MemoryStore::has

    fn MemoryStore::has(self : MemoryStore, id : Digest) -> Bool

    MemoryStore::length

    fn MemoryStore::length(self : MemoryStore) -> Int

    MemoryStore::new

    MemoryStore::pin

    fn MemoryStore::pin(self : MemoryStore, id : Digest) -> Bool

    Add a live reference. Returns false when the blob is unknown.

    MemoryStore::pin_chunked

    fn MemoryStore::pin_chunked(self : MemoryStore, manifest : ChunkedBlob) -> Bool

    Add one live reference for every chunk in a manifest.

    MemoryStore::put

    fn MemoryStore::put(self : MemoryStore, data : Bytes) -> Digest

    Store bytes and return their SHA-256 content identifier.

    MemoryStore::put_chunked

    fn MemoryStore::put_chunked(self : MemoryStore, data : Bytes, chunk_size? : Int) -> ChunkedBlob

    Split a blob into fixed-size chunks and store each chunk by digest. Every chunk is pinned once for the lifetime of the returned manifest.

    MemoryStore::put_verified

    fn MemoryStore::put_verified(self : MemoryStore, expected : Digest, data : Bytes) -> Bool

    Store data only when it matches an expected digest.

    MemoryStore::unpin

    fn MemoryStore::unpin(self : MemoryStore, id : Digest) -> Unit

    Release one live reference without allowing a negative count.

    MemoryStore::unpin_chunked

    fn MemoryStore::unpin_chunked(self : MemoryStore, manifest : ChunkedBlob) -> Unit

    Release the references owned by a chunk manifest.

    MemoryStore::verify

    fn MemoryStore::verify(self : MemoryStore, id : Digest) -> Bool

    Re-hash a stored blob to detect accidental or hostile corruption.

    digest

    fn digest(data : Bytes) -> Digest

    Compute a deterministic SHA-256 digest without platform-specific APIs.

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io