6 releases
0.4.1 | Jul 17, 2020 |
---|---|
0.4.0 | Jul 14, 2020 |
0.3.0 | May 22, 2020 |
0.1.2 | May 15, 2020 |
#58 in #ipld
Used in 6 crates
(2 directly)
29KB
664 lines
ipld-block-builder
Getting started
use ipfs_embed::{Config, Store};
use ipld_block_builder::{BlockBuilder, Codec};
use libipld::DagCbor;
#[derive(Clone, DagCbor, Debug, Eq, PartialEq)]
struct Identity {
id: u64,
name: String,
age: u8,
}
#[async_std::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = Config::from_path("/tmp/db")?;
let store = Store::new(config)?;
let codec = Codec::new();
let builder = BlockBuilder::new(store, codec);
let identity = Identity {
id: 0,
name: "David Craven".into(),
age: 26,
};
let cid = builder.insert(&identity).await?;
let identity2 = builder.get(&cid).await?;
builder.unpin(cid).await?;
assert_eq!(identity, identity2);
println!("identity cid is {}", cid);
Ok(())
}
Encrypted private store
use ipld_block_builder::{BlockBuilder, Key, StrobeCodec};
let key = Key::from(b"private encryption key".to_vec());
let codec = StrobeCodec::new(key);
let builder = BlockBuilder::new_private(store, codec);
Caching
let codec = Codec::new();
let mut cache: Cache<_, _, String> = Cache::new(store, codec, size);
let cid = cache.insert("hello world".into()).await?;
cache.get(&cid).await?;
License
Dual licensed under MIT or Apache License (Version 2.0).
Dependencies
~7–16MB
~214K SLoC