Struct FsBlobStore

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

An abstraction over a blob storage in a file system directory.

Implementations§

Source§

impl FsBlobStore

Source

pub fn new(basedir: impl AsRef<Path>) -> Result<Self, Error>

Create a new file system-backed blob storage engine.

The basedir is where the blobs and temporary files will be stored. The caller must ensure that either basedir is absolute, or that the path remains valid throughout the object’s lifetime.

If the basedir does not exist, it will automatically be created if the mkbasedir feature is enabled.

§Errors

If mkbasedir feature is enabled, Error::IO indicates that the base directory can not be created.

Source

pub fn with_minsize( basedir: impl AsRef<Path>, minsize: usize, ) -> Result<Self, Error>

This function serves the purpose as FsBlobStore::new(), but will enable support for storing small files in memory, rather than be written to disk.

§Notes

If support for storing small files in memory is enabled, “files” that will fall into this category will not actually be stored in the file system, and thus will neither be enumerable or read.

The calling application must maintain its own databasse for such cases.

Source

pub fn have(&self, hash: &[u8]) -> Result<bool, Error>

Check if content for a hash exists in store.

§Errors

Error::IO indicates that it was not possible to determine whether the file exists.

Source

pub fn reader(&self, hash: &[u8]) -> Result<impl Read, Error>

Get a reader for a blob.

§Errors

Error::IO means the file could not be opened.

Source

pub fn writer(&self) -> Result<TmpFile<ContentHash, Error>, Error>

Return a TmpFile writer for writing to temporary file.

If the caller wishes to keep the file it must call TmpFile::persist(). Dropping the TmpFile, without persisting it, will remove the temporary file.

§Errors

std::io::Error indicates that the temporary file could not be created.

Source

pub fn rm(&self, hash: &[u8]) -> Result<(), Error>

Remove a blob, by its hash, from the blob store.

§Errors

std::io::Error indicates the file could not be removed.

§Panics

If the hash is not 32 bytes long this method will panic.

Source

pub fn enumerate(&self) -> (Receiver<ContentHash, ()>, JoinHandle<()>)

Available on crate feature enumerate only.

Get a list of all hashes in the fs blob store.

On success, returns an object that will stream the records in an unspecified order.

§Caveat

This method exists, despite it being incongruous with the overall philosophy of the blob store. The application should maintain a separate database of the blob hashes stored in the FsBlobStore, and enumerations of hashes should be performed in the database instead.

Enumerating the FsBlobStore is potentially slow. Its use should be limited to infrequent integrity checks.

This method will launch a background thread which lives as long as it performs its work. It is inadvisable to allow end users to trigger this method to be run.

Source

pub fn get_fname(&self, hash: &[u8]) -> Result<PathBuf, Error>

Available on crate feature get-fname only.

Get complete filename of an existing blob.

Returns Ok(PathBuf) containing the path to the content, if it exists.

§Caveat

The use of this method is strongly discouraged. Use FsBlobStore::have() to check if a blob exists in the datastore, FsBlobStore::reader() to read a blob, and FsBlobStore::rm() to remove a blob.

§Errors

std::io::Error indicates the file doesn’t exists or its metadata could not be read.

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.