Skip to content

Commit

Permalink
Fix README
Browse files Browse the repository at this point in the history
  • Loading branch information
appcypher committed May 20, 2022
1 parent 480cc12 commit 7db77df
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions crates/fs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "wnfs"
version = "0.1.1"
version = "0.1.2"
description = "WebNative filesystem core implementation"
keywords = ["wnfs", "webnative", "ipfs", "decentralisation"]
categories = [
Expand All @@ -12,7 +12,7 @@ categories = [
license-file = "../../LICENSE"
readme = "README.md"
edition = "2021"
repository = "https://github.com/fission-suite/rs-wnfs"
repository = "https://github.com/WebNativeFileSystem/rs-wnfs/tree/main/crates/fs"
homepage = "https://fission.codes"
authors = ["The Fission Authors"]

Expand Down
120 changes: 119 additions & 1 deletion crates/fs/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,122 @@
## The FileSystem
<div align="center">
<a href="https://github.com/WebNativeFileSystem" target="_blank">
<img src="https://raw.githubusercontent.com/WebNativeFileSystem/rs-wnfs/main/assets/logo.svg" alt="Fission Logo" width="100" height="100"></img>
</a>

<h1 align="center">WebNative FileSystem (WNFS)</h1>

<p>
<a href="https://crates.io/crates/wnfs">
<img src="https://img.shields.io/crates/v/wnfs?label=crates" alt="Concurrency Docs">
</a>
<a href="https://codecov.io/gh/WebNativeFileSystem/rs-wnfs">
<img src="https://codecov.io/gh/WebNativeFileSystem/rs-wnfs/branch/main/graph/badge.svg?token=95YHXFMFF4" alt="Code Coverage"/>
</a>
<a href="https://github.com/WebNativeFileSystem/rs-wnfs/actions?query=">
<img src="https://github.com/WebNativeFileSystem/rs-wnfs/actions/workflows/checks.yaml/badge.svg" alt="Build Status">
</a>
<a href="https://github.com/WebNativeFileSystem/rs-wnfs/blob/main/LICENSE">
<img src="https://img.shields.io/badge/License-Apache%202.0-blue.svg" alt="License">
</a>
<a href="https://docs.rs/wnfs">
<img src="https://img.shields.io/static/v1?label=Docs&message=docs.rs&color=blue" alt="Concurrency Docs">
</a>
<a href="https://discord.gg/zAQBDEq">
<img src="https://img.shields.io/static/v1?label=Discord&message=join%20us!&color=mediumslateblue" alt="Discord">
</a>
</p>
</div>

<div align="center"><sub>:warning: Work in progress :warning:</sub></div>

##

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](#usage)
- [Building the Project](#building-the-project)
- [Testing the Project](#testing-the-project)

## Usage

Creating a new public directory.

```rs
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](https://github.com/WebNativeFileSystem/rs-wnfs/blob/8bb0fbb457051295f1ed4a4707dc230c04612658/crates/fs/common/blockstore.rs#L42-L62) can be used.

```rs
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.

```rs
// ...

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

Expand Down
4 changes: 2 additions & 2 deletions crates/wasm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "wasm-wnfs"
version = "0.1.1"
version = "0.1.2"
description = "WebNative filesystem WebAssembly API"
keywords = ["wnfs", "webnative", "ipfs", "decentralisation"]
categories = [
Expand All @@ -12,7 +12,7 @@ categories = [
license-file = "LICENSE"
readme = "README.md"
edition = "2021"
repository = "https://github.com/fission-suite/rs-wnfs"
repository = "https://github.com/WebNativeFileSystem/rs-wnfs/tree/main/crates/wasm"
homepage = "https://fission.codes"
authors = ["The Fission Authors"]

Expand Down
9 changes: 9 additions & 0 deletions crates/wasm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ This package implements the primitives for creating and manipulating IPLD graphs

The core of this project is a WebAssembly binary compiled from the [Rust source code](https://github.com/WebNativeFileSystem/rs-wnfs/tree/main/crates/fs).

## Outline

- [Usage](#usage)
- [Building the Project](#building-the-project)
- [Testing the Project](#testing-the-project)
- [Publishing Package](#publishing-package)

## Usage

Creating a new public directory.
Expand Down Expand Up @@ -88,6 +95,8 @@ var { result } = await rootDir.ls(["pictures"], store);
wasm-pack build --target web
```

## Testing the Project

- Run tests

```bash
Expand Down

0 comments on commit 7db77df

Please sign in to comment.