Skip to content

contentAddressedStore(options): ContentAddressedStore

Defined in: packages/cas/src/content-addressed-store.ts:115

Create a store that names each artifact by the hash of its framed bytes.

Content addressing gives three properties a plain blob key cannot. Writing the same artifact twice stores one copy, because identical bytes produce one address. Reading an address cannot return different content later without failing, because the bytes are re-hashed before decoding. And an address is portable across processes and machines that share the hash function, which is why the hash is injected rather than chosen here.

A hash collision — two artifacts, one address — is detected rather than served: add compares the stored bytes with the ones it was about to write, and reports ADDRESS_COLLISION instead of returning an address whose content is the other artifact. That check costs one read on the duplicate path, which is the price of not depending on the hash being collision-free.

ContentAddressedStoreOptions

The backend, the hash, and the artifact family’s magic.

ContentAddressedStore

A store whose every failure carries a code from CAS_ERROR_CODES.

With INVALID_ARTIFACT when options.magic is not four bytes, since no artifact of this family could ever be valid.