Struct rstr::BlobStore[][src]

pub struct BlobStore { /* fields omitted */ }
Expand description

Struct for interacting with the blob store

Implementations

Creates a new instance of the BlobStore struct used to interact with the blob store. If the specified blob store root path does not exists, it tries to create it.

Errors

It errors if the specified path is not a directory or if it does not exist and cannot be created.

Examples

use rstr::BlobStore;

let blob_store = BlobStore::new("../tests/test_data_store");
assert!(blob_store.is_ok());

let blob_store = BlobStore::new("../tests/test_file.txt");
assert!(blob_store.is_err());

Returns an instance of the hasher used to compute the blob reference for a file

Examples

use rstr::BlobStore;
use sha2::{Digest, Sha256};

let mut hasher = BlobStore::hasher();
hasher.update(b"hello world");
let result = hasher.finalize();
assert_eq!(format!("{:x}", result), "b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9")

Add a file to the blob store given a path.

Examples

use rstr::{BlobStore, BlobRef};
use std::path::PathBuf;
let blob_store = BlobStore::new("../tests/test_data_store/").unwrap();

let blob_ref: BlobRef = blob_store.add("../tests/test_file.txt").unwrap();
assert!(blob_store.exists(&blob_ref));
assert_eq!(blob_ref.reference(), "f29bc64a9d3732b4b9035125fdb3285f5b6455778edca72414671e0ca3b2e0de");

Given a list of paths to files/directories it adds them to the blob store. In the case of a directory it adds all the files in its children recursively.

The function iterates over all paths in parallel and adds each file to the blob store.

It returns two vectors: one containing the paths to the files that were successfully added together with their generated BlobRef and the other containing the list of paths that errored together with the error.

Examples

use rstr::{BlobStore, BlobRef};

let blob_store = BlobStore::new("../tests/test_data_store").unwrap();

let paths = [Path::new("../tests/test_file.txt")];
let threads: u8 = 8;
let (blob_refs_with_paths, errors) = blob_store.add_files(&paths[..], threads);
let blob_refs: Vec<BlobRef> = blob_refs_with_paths.into_iter().map(|(_, b)| b).collect();

assert_eq!(blob_refs[0].reference(), "f29bc64a9d3732b4b9035125fdb3285f5b6455778edca72414671e0ca3b2e0de")

Given a BlobRef it retrieves the associated file and returns it as a byte-array.

Examples

use rstr::{BlobStore, BlobRef};

let blob_store = BlobStore::new("../tests/test_data_store").unwrap();
let reference = "f29bc64a9d3732b4b9035125fdb3285f5b6455778edca72414671e0ca3b2e0de";
let blob_ref = BlobRef::new(reference).unwrap();

let content = blob_store.get(&blob_ref).unwrap();

assert_eq!(content, &[
    84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 116, 101, 115, 116, 32, 102, 105, 108,
    101, 46,
]);

Returns true if there is a file associated with the BlobRef in the blob store

Examples

use rstr::{BlobStore, BlobRef};

let blob_store = BlobStore::new("../tests/test_data_store/").unwrap();
let blob_ref = BlobRef::new("f29bc64a9d3732b4b9035125fdb3285f5b6455778edca72414671e0ca3b2e0de").unwrap();

assert!(blob_store.exists(&blob_ref))

Given a BlobRef it deletes the corresponding blob from the blob store

Examples

let blob_store = BlobStore::new("/path/to/blob/store").unwrap();

let blob_ref = BlobRef::new("b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9").unwrap();
assert!(blob_store.exists(&blob_ref));

blob_store.delete(&blob_ref);
assert!(!blob_store.exists(&blob_ref));

Errors

See fs::remove_dir_all.

Given a BlobRef returns the metadata relative to the referenced blob. For more details on the metadata returned see BlobMetadata.

The mime type is inferred from the file’s magic number as a string. It defaults to “application/octet-stream” if it cannot determine the type. We use the tree_magic_mini crate to infer the mime type.

Errors

Will return an error if the file cannot be found/opened or if std::fs::metadata fails.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Converts self into T using Into<T>. Read more

Converts self into a target type. Read more

Causes self to use its Binary implementation when Debug-formatted.

Causes self to use its Display implementation when Debug-formatted. Read more

Causes self to use its LowerExp implementation when Debug-formatted. Read more

Causes self to use its LowerHex implementation when Debug-formatted. Read more

Causes self to use its Octal implementation when Debug-formatted.

Causes self to use its Pointer implementation when Debug-formatted. Read more

Causes self to use its UpperExp implementation when Debug-formatted. Read more

Causes self to use its UpperHex implementation when Debug-formatted. Read more

Performs the conversion.

Performs the conversion.

Pipes by value. This is generally the method you want to use. Read more

Borrows self and passes that borrow into the pipe function. Read more

Mutably borrows self and passes that borrow into the pipe function. Read more

Borrows self, then passes self.borrow() into the pipe function. Read more

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more

Borrows self, then passes self.as_ref() into the pipe function.

Mutably borrows self, then passes self.as_mut() into the pipe function. Read more

Borrows self, then passes self.deref() into the pipe function.

Mutably borrows self, then passes self.deref_mut() into the pipe function. Read more

Pipes a value into a function that cannot ordinarily be called in suffix position. Read more

Pipes a trait borrow into a function that cannot normally be called in suffix position. Read more

Pipes a trait mutable borrow into a function that cannot normally be called in suffix position. Read more

Pipes a trait borrow into a function that cannot normally be called in suffix position. Read more

Pipes a trait mutable borrow into a function that cannot normally be called in suffix position. Read more

Pipes a dereference into a function that cannot normally be called in suffix position. Read more

Pipes a mutable dereference into a function that cannot normally be called in suffix position. Read more

Pipes a reference into a function that cannot ordinarily be called in suffix position. Read more

Pipes a mutable reference into a function that cannot ordinarily be called in suffix position. Read more

Should always be Self

Immutable access to a value. Read more

Mutable access to a value. Read more

Immutable access to the Borrow<B> of a value. Read more

Mutable access to the BorrowMut<B> of a value. Read more

Immutable access to the AsRef<R> view of a value. Read more

Mutable access to the AsMut<R> view of a value. Read more

Immutable access to the Deref::Target of a value. Read more

Mutable access to the Deref::Target of a value. Read more

Calls .tap() only in debug builds, and is erased in release builds.

Calls .tap_mut() only in debug builds, and is erased in release builds. Read more

Calls .tap_borrow() only in debug builds, and is erased in release builds. Read more

Calls .tap_borrow_mut() only in debug builds, and is erased in release builds. Read more

Calls .tap_ref() only in debug builds, and is erased in release builds. Read more

Calls .tap_ref_mut() only in debug builds, and is erased in release builds. Read more

Calls .tap_deref() only in debug builds, and is erased in release builds. Read more

Calls .tap_deref_mut() only in debug builds, and is erased in release builds. Read more

Provides immutable access for inspection. Read more

Calls tap in debug builds, and does nothing in release builds.

Provides mutable access for modification. Read more

Calls tap_mut in debug builds, and does nothing in release builds.

Provides immutable access to the reference for inspection.

Calls tap_ref in debug builds, and does nothing in release builds.

Provides mutable access to the reference for modification.

Calls tap_ref_mut in debug builds, and does nothing in release builds.

Provides immutable access to the borrow for inspection. Read more

Calls tap_borrow in debug builds, and does nothing in release builds.

Provides mutable access to the borrow for modification.

Calls tap_borrow_mut in debug builds, and does nothing in release builds. Read more

Immutably dereferences self for inspection.

Calls tap_deref in debug builds, and does nothing in release builds.

Mutably dereferences self for modification.

Calls tap_deref_mut in debug builds, and does nothing in release builds. Read more

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

Attempts to convert self into T using TryInto<T>. Read more

Attempts to convert self into a target type. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.