Skip to main content

ContentStore

Struct ContentStore 

Source
pub struct ContentStore { /* private fields */ }
Expand description

An app’s handle to binary content: cheap to clone, passed to whatever needs it.

Everything here takes a reference (ContentRef) where it names content: a plain address, or a sealed reference, which reads through its key. What a store hands back for what it stored is the reference to keep: sealed when the store seals (Self::sealing).

Implementations§

Source§

impl ContentStore

Source

pub fn new(backend: impl ContentBackend + 'static) -> Self

Source

pub fn from_backend(backend: Arc<dyn ContentBackend>) -> Self

Source

pub fn sealing(self) -> Self

This store, sealing what it stores: each item under a key of its own, kept under the address of its ciphertext, and named by a reference that carries the key. The key derives from the members’ content secret and the bytes when the backend holds one (ContentBackend::content_secret), and is fresh otherwise. The store a record’s content travels through seals, so the record’s readers alone open it.

Source

pub fn unsealed(self) -> Self

This store, keeping what it stores under its own address, unsealed: for code that must name content alike wherever it runs (an action applying on every replica). Sealed references still read.

Source

pub fn memory() -> Self

Source

pub fn in_dir(root: impl Into<PathBuf>) -> Self

Source

pub fn local_for_app() -> Self

The store an app keeps on this machine when the launcher handed it no device content store (tilo_content_device::for_app prefers that one): the session’s shared directory when the host names one (SHARED_STORE_ENV), otherwise, where files have no native path (a browser page), the profile’s app files (FilesBackend), otherwise tilo/content in the user’s data directory. Content an earlier version kept in the cache directory (tilo/blobs) still reads. With no usable directory at all, content is kept in memory.

Source

pub fn page_files() -> Self

Where files have no native path (a browser page): content in the profile’s app files, which outlive the page, so an upload a page stored is still here after a reload. Every app of the profile shares the one store, as native apps share tilo/content. The page holds those files in memory, so the store is bounded: an item or store past the bound is refused, never dropped, and nothing collects what the page stored on its own. A page whose host loaded no app files keeps content in memory, under the same bounds, as a tab alone can.

This is the store a page host lends each window it opens, as the framework’s native process host lends tilo_content_device::for_app’s: a window keeps content in the store its host lent it (cx.content()), never in one it opens itself.

Source

pub const fn seals(&self) -> bool

Whether this store seals what it keeps, so its writes go one at a time.

Source

pub fn put(&self, bytes: &[u8]) -> Result<String, ContentError>

Store bytes, returning the reference to keep: sealed when this store seals. The media type is sniffed from the content.

§Errors

See ContentBackend::put.

Source

pub fn put_public(&self, bytes: &[u8]) -> Result<String, ContentError>

Store bytes as they are, under their own address, even in a store that seals: content that is public by nature (an app’s surface, which whoever decides its changes reads).

§Errors

See ContentBackend::put.

Source

pub fn put_public_many( &self, items: &[&[u8]], ) -> Vec<Result<String, ContentError>>

Keep many items, answering each one’s address in order: Self::put_public for each, one store write where the backend can make it.

§Errors

Each item its own, as Self::put_public refuses it.

Source

pub fn put_as(&self, reference: &str, bytes: &[u8]) -> Result<(), ContentError>

Keep bytes as the content reference names: sealed under its key when it carries one, so a device that holds the bytes keeps exactly what the writer stored. Refused when bytes are not that content.

§Errors

ContentError::HashMismatch for other bytes, else see ContentBackend::put.

Source

pub fn put_reader( &self, reader: &mut dyn Read, mime: &str, ) -> Result<Stored, ContentError>

Store everything reader yields without holding it in memory: the device store sends it to the daemon one runtime_fs::blobs::MAX_PUT_CHUNK at a time. Stored::hash is the reference to keep, sealed when this store seals.

A sealing store with the members’ secret hashes the plaintext in a first pass and seals it in a second, and refuses it once it is past ContentBackend::max_item_bytes: a large item waits in a file beside the store’s own content (ContentBackend::scratch_dir) rather than whole in memory, and an oversized one is refused without being held at all.

§Errors

See ContentBackend::put, and ContentError::ItemTooLarge for an item past the store’s limit.

Source

pub fn put_inputs( &self, inputs: &ContentInputs, ) -> Result<BTreeMap<String, String>, ContentError>

Store every input inputs collected (an import’s images, say), answering the reference to keep for each input’s address: the address itself, or a sealed reference when this store seals, which the document naming the input names instead.

§Errors

The first refusal; inputs stored before it stay stored.

Source

pub fn reseal(&self, reference: &str) -> Option<String>

Store again, sealed, the plain content reference names, when this store seals and it is here: the sealed reference a record keeps in its place. None for a reference already sealed, a store that does not seal, or content not here yet. The plain copy stays until nothing references it (Self::collect_unreferenced), so a reader still holding the old reference reads it meanwhile.

Source

pub fn read(&self, reference: &str) -> Option<Vec<u8>>

The verified content reference names, opened when sealed, or None when it is not here (or not intact).

Source

pub fn open(&self, reference: &str) -> Option<ContentReader>

A streaming, verifying read of the content reference names, opened as it streams when sealed; see ContentReader. Content kept in parts (Self::put_parts) reads as the content its parts make, and is None until every part is here: each part not here is asked for at once.

Source

pub fn put_parts(&self, reader: &mut dyn Read) -> Result<Stored, ContentError>

Store everything reader yields a part at a time (list::PART_BYTES), never holding more than one part: content of any size, kept as items no larger than a part. Content that fits in one part is that one item; larger content is its parts and a list naming them, whose reference reads as the whole (Self::open). Each is sealed when this store seals.

§Errors

What storing a part or the list refused, or reading reader failed with.

Source

pub fn size(&self, reference: &str) -> Option<u64>

The length of the content reference names, when the store knows it without reading it: for sealed content, the plaintext its sealed bytes hold; for content kept in parts, what its parts make.

Source

pub fn read_range( &self, reference: &str, offset: u64, length: u64, ) -> Result<(u64, Vec<u8>), ContentError>

length bytes of the content reference names, from offset: the bytes read, and the content’s length. Reads only what it answers, so serving one piece of a large file does not read the file: sealed content opens from the chunk the piece begins in, and content kept in parts reads only the parts the piece is in.

§Errors

The content is not here, or cannot be read.

Source

pub fn has(&self, reference: &str) -> bool

Source

pub fn state(&self, reference: &str) -> ContentState

Source

pub fn shared(&self) -> bool

Whether content stored here reaches the app’s other devices and members; see ContentBackend::shared.

Source

pub fn workspace_scoped(&self) -> bool

Whether this store answers only for content readable in one workspace; see ContentBackend::workspace_scoped.

Source

pub fn scratch_dir(&self) -> Option<PathBuf>

A directory beside the content this store keeps, where a sealing write may keep the plaintext it hashes in a file rather than in memory; see ContentBackend::scratch_dir.

Source

pub fn for_one_workspace(self) -> Self

This store, declared as one workspace’s (Self::workspace_scoped): for a host that keeps a store for one workspace alone, so everything in it is that workspace’s (a test’s profile, one workspace’s headless drive).

Source

pub fn memory_in_workspace() -> Self

Content in memory, as one workspace’s store (Self::for_one_workspace): for tests of what a caller may name by reference.

Source

pub fn collect_unreferenced( &self, live: &BTreeSet<String>, ) -> Result<Collected, ContentError>

Remove every item not named in live, references or addresses; see ContentBackend::collect_unreferenced.

§Errors

See ContentBackend::collect_unreferenced.

Source

pub fn release(&self, reference: &str) -> Result<Collected, ContentError>

Remove the item reference names (ContentBackend::release).

§Errors

As ContentBackend::release.

Trait Implementations§

Source§

impl Clone for ContentStore

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl ContentSource for ContentStore

Source§

fn content(&self, hash: &str) -> Option<Cow<'_, [u8]>>

The bytes at hash, if this source has them.
Source§

impl Debug for ContentStore

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more