A small embeddable ipfs implementation compatible with libipld and with a concurrent garbage collector. It supports * node discovery via mdns * provider discovery via kademlia * exchange blocks via bitswap
The ipld-block-builder
can be used for using the store effectively. It also supports
* creating encrypted/private block stores for sensitive data
* caching of native data types to maximize performance
ipld-collections
provide high level multiblock abstractions using the ipld-block-builder
.
```rust use ipfsembed::{Config, Store}; use ipldblock_builder::{BlockBuilder, Codec}; use libipld::DagCbor;
struct Identity { id: u64, name: String, age: u8, }
async fn main() -> Result<(), Box
let identity = Identity {
id: 0,
name: "David Craven".into(),
age: 26,
};
let cid = builder.insert(&identity).await?;
let identity2 = builder.get(&cid).await?;
assert_eq!(identity, identity2);
println!("identity cid is {}", cid);
Ok(())
} ```
```rust // #roots = {} #live = {} let a = builder.insert(&ipld!({ "a": [] })).await?; // #roots = {a} #live = {a} let b = builder.insert(&ipld!({ "b": [&a] })).await?; // #roots = {a, b} #live = {a, b}
// block `b` contains a reference to block `a`, so the
// garbage collector won't remove it until block `b` gets
// unpinned
builder.unpin(&a).await?;
// #roots = {b} #live = {a, b}
let c = builder.insert(&ipld!({ "c": [&a] })).await?;
// #roots = {b, c} #live = {a, b, c}
// the backing storage is content addressed, but inserting
// a block multiple times increases the ref count.
let c2 = builder.insert(&ipld!({ "c": [&a] })).await?;
// #roots = {b, c, c} #live = {a, b, c}
builder.unpin(&b).await?;
// #roots = {b, c} #live = {a, c}
builder.unpin(&c2).await?;
// #roots = {c} #live = {a, c}
builder.unpin(&c).await?;
// #roots = {} #live = {}
```
```rust use ipfsembed::{Config, Store}; use ipldcollections::List;
async fn main() -> Result<(), Box
let mut list = List::new(store, 64, 256).await?;
// push: 1024xi128; n: 4; width: 256; size: 4096
for i in 0..1024 {
list.push(i as i64).await?;
}
Ok(())
} ```
MIT OR Apache-2.0