项目作者: scttnlsn

项目描述 :
Content addressable blob store
高级语言: Rust
项目地址: git://github.com/scttnlsn/blobstore.git
创建时间: 2018-02-15T02:07:58Z
项目社区:https://github.com/scttnlsn/blobstore

开源协议:

下载


blobstore

Travis CI Status
crates.io

A content addressable store for arbitrary blobs.

Usage

Add the following to your Cargo.toml file:

  1. [dependencies]
  2. blobstore = "*"

and import into your code:

  1. extern crate blobstore;

Example

  1. extern crate blobstore;
  2. use blobstore::BlobStore;
  3. let mut data = "foo".as_bytes();
  4. let store = BlobStore::new("./store".to_string());
  5. // this will accept any `std::io::Read` type
  6. let hash = store.put(&mut data).unwrap();
  7. // hash is a SHA256 of the content
  8. assert_eq!(hash, "2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae");
  9. let mut value = String::new();
  10. store.get(hash.as_ref()).unwrap().read_to_string(&mut value).unwrap();
  11. assert_eq!(value, "foo");
  12. store.remove(hash.as_ref()).unwrap();
  13. fs::remove_dir_all(store.path).unwrap();

API

BlobStore implements the following trait:

  1. trait Store {
  2. fn put(&self, item: &mut std::io::Read) -> Result<String, std::io::Error>;
  3. fn get(&self, hash: &str) -> Result<stf::fs::File, std::io::Error>;
  4. fn remove(&self, hash: &str) -> Result<(), std::io::Error>;
  5. }