wnfs 0.1.5

WebNative filesystem core implementation
Documentation

This crate is a Rust implementation of the primitives for creating and manipulating IPLD graphs that encode WNFS.

A goal of the project is to be easily compiled to WebAssembly to be used in the browsers or other environments.

Outline

Usage

Creating a new public directory.

use wnfs::{PublicDirectory, Id};
use chrono::Utc;

let dir = PublicDirectory::new(Utc::now());
println!("id = {}", dir.get_id());

The in-memory files and directories you create with wnfs will need to be sealed and stored somewhere. For that, an object that implements the BlockStore trait like this one can be used.

use wnfs::{PublicDirectory, MemoryBlockStore, ipld::Cid};
use chrono::Utc;

let dir = PublicDirectory::new(Utc::now());
let store = MemoryBlockStore::default();

// ...

The WNFS API is immutable, therefore, we need to keep track of the updated root directory after every change.

Each fs operation returns a possibly updated root directory that subsequent changes can be applied on.

// ...

let dir = Rc::new(dir);

// Create a /pictures/cats directory.
let OpResult { root_dir, .. } = dir
    .mkdir(&["pictures".into(), "cats".into()], time, &store)
    .await
    .unwrap();

// Get a sample CIDv1.
let cid = Cid::default();

// Add a file to /pictures/cats.
let OpResult { root_dir, .. } = root_dir
    .write(
        &["pictures".into(), "cats".into(), "tabby.png".into()],
        cid,
        time,
        &store,
    )
    .await
    .unwrap();

// Create and add a file to /pictures/dogs directory.
let OpResult { root_dir, .. } = root_dir
    .write(
        &["pictures".into(), "cats".into(), "billie.jpeg".into()],
        cid,
        time,
        &store,
    )
    .await
    .unwrap();

// Delete /pictures/cats directory.
let OpResult { root_dir, .. } = root_dir
    .rm(&["pictures".into(), "cats".into()], &store)
    .await
    .unwrap();

// List all files in /pictures directory.
let OpResult { result, .. } = root_dir
    .ls(&["pictures".into()], &store)
    .await
    .unwrap();

Building the Project

  • Build project

    cargo build --release
    

Testing the Project

  • Run tests

    cargo test --release