This Rust crate provides an implementation of UnixFs files. WNFS uses the UnixFs file encoding purely to chunk big byte arrays into multiple blocks and produce a single CID for them to link to from WNFS structures.
This crate is a fork from beetle (previously "iroh")'s iroh-unixfs crate.
Major changes relative to that implementation include:
- Removed prost code generation, instead it's some hard-coded structs with prost annotations
- Removed support for any UnixFs structures other than files (no directories, directory shards or symlinks)
- Removed parallelization for hashing to make the crate async runtime-independent (so it can be used in wasm with wasm-bindgen-futures!)
- Doesn't hard-code use of SHA-256 anymore
- Integrated with the wnfs-common
BlockStore
trait
Usage
use FileBuilder;
use MemoryBlockStore;
use AsyncReadExt;
// Where data is stored
let store = & new;
// Encoding byte arrays, getting a CID
let data = vec!; // 1MiB of ones
let root_cid = new
.content_bytes
.build?
.store
.await?;
// Taking a CID, reading back a byte array:
let file = load.await?;
println!;
let mut buffer = Vec new;
let mut reader = file.into_content_reader?;
reader.read_to_end.await?;
// buffer now has 1 million ones
// You can also seek
use AsyncSeekExt;
use SeekFrom;
let mut reader = file.into_content_reader?;
reader.seek.await?;
let mut slice = ;
reader.read_exact.await?;
// slice now has 10_000 ones