#content-addressable #store #deprecated #file

已撤回 blob-store

已弃用:使用 'blobstore' 代替

使用旧的 Rust 2015

0.1.1 2018年2月15日
0.1.0 2018年2月15日

#31#content-addressable

26 每月下载量

MIT/Apache

1KB

blobstore

Travis CI Status crates.io

一个用于任意块的基于内容地址的存储。

用法

将以下内容添加到您的 Cargo.toml 文件中

[dependencies]
blobstore = "*"

并将导入到您的代码中

extern crate blobstore;

示例

extern crate blobstore;

use blobstore::BlobStore;

let mut data = "foo".as_bytes();
let store = BlobStore::new("./store".to_string());

// this will accept any `std::io::Read` type
let hash = store.put(&mut data).unwrap();

// hash is a SHA256 of the content
assert_eq!(hash, "2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae");

let mut value = String::new();
store.get(hash.as_ref()).unwrap().read_to_string(&mut value).unwrap();

assert_eq!(value, "foo");

store.remove(hash.as_ref()).unwrap();

fs::remove_dir_all(store.path).unwrap();

API

BlobStore 实现以下特质

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

无运行时依赖