From e60649dfc0d60ea6f36e5f87180109b52b5c5d44 Mon Sep 17 00:00:00 2001 From: Stephen Akinyemi Date: Mon, 23 May 2022 18:38:37 +0100 Subject: [PATCH] Fix packages docs --- Cargo.lock | 4 +- README.md | 115 ++++++++++++++++++++++------------------- crates/fs/Cargo.toml | 2 +- crates/fs/README.md | 115 ++++++++++++++++++++++------------------- crates/wasm/Cargo.toml | 2 +- crates/wasm/README.md | 12 +++-- 6 files changed, 137 insertions(+), 113 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c3725cd9..2573ae96 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1540,7 +1540,7 @@ dependencies = [ [[package]] name = "wasm-wnfs" -version = "0.1.5" +version = "0.1.6" dependencies = [ "anyhow", "async-trait", @@ -1665,7 +1665,7 @@ checksum = "d19538ccc21819d01deaf88d6a17eae6596a12e9aafdbb97916fb49896d89de9" [[package]] name = "wnfs" -version = "0.1.5" +version = "0.1.6" dependencies = [ "anyhow", "async-recursion", diff --git a/README.md b/README.md index 81802f04..9ed62e9f 100644 --- a/README.md +++ b/README.md @@ -47,21 +47,26 @@ Creating a new public directory. ```rust use wnfs::{PublicDirectory, Id}; + +use async_std::main; use chrono::Utc; -let dir = PublicDirectory::new(Utc::now()); -println!("id = {}", dir.get_id()); +#[async_std::main] +async fn main() { + 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. +The in-memory files and directories you create with `wnfs` will need to be sealed and stored somewhere. For that, a type 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. ```rust -use wnfs::{PublicDirectory, MemoryBlockStore, ipld::Cid}; -use chrono::Utc; +use wnfs::{MemoryBlockStore, PublicDirectory, OpResult, ipld::Cid}; -let dir = PublicDirectory::new(Utc::now()); -let store = MemoryBlockStore::default(); +use async_std::main; +use chrono::Utc; +use std::rc::Rc; // ... ``` @@ -71,51 +76,57 @@ Each fs operation returns a possibly updated root directory that subsequent chan ```rust // ... - -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(); +#[async_std::main] +async fn main() { + let time = Utc::now(); + let dir = Rc::new(PublicDirectory::new(time)); + let store = MemoryBlockStore::default(); + + // 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(), "dogs".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(); + + println!("Files in /pictures: {:#?}", result); +} ``` ## Building the Project diff --git a/crates/fs/Cargo.toml b/crates/fs/Cargo.toml index 7036cb01..7a529647 100644 --- a/crates/fs/Cargo.toml +++ b/crates/fs/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wnfs" -version = "0.1.5" +version = "0.1.6" description = "WebNative filesystem core implementation" keywords = ["wnfs", "webnative", "ipfs", "decentralisation"] categories = [ diff --git a/crates/fs/README.md b/crates/fs/README.md index 5f1a2cce..a5f0c2e6 100644 --- a/crates/fs/README.md +++ b/crates/fs/README.md @@ -45,21 +45,26 @@ Creating a new public directory. ```rust use wnfs::{PublicDirectory, Id}; + +use async_std::main; use chrono::Utc; -let dir = PublicDirectory::new(Utc::now()); -println!("id = {}", dir.get_id()); +#[async_std::main] +async fn main() { + 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. +The in-memory files and directories you create with `wnfs` will need to be sealed and stored somewhere. For that, a type 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. ```rust -use wnfs::{PublicDirectory, MemoryBlockStore, ipld::Cid}; -use chrono::Utc; +use wnfs::{MemoryBlockStore, PublicDirectory, OpResult, ipld::Cid}; -let dir = PublicDirectory::new(Utc::now()); -let store = MemoryBlockStore::default(); +use async_std::main; +use chrono::Utc; +use std::rc::Rc; // ... ``` @@ -69,51 +74,57 @@ Each fs operation returns a possibly updated root directory that subsequent chan ```rust // ... - -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(); +#[async_std::main] +async fn main() { + let time = Utc::now(); + let dir = Rc::new(PublicDirectory::new(time)); + let store = MemoryBlockStore::default(); + + // 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(), "dogs".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(); + + println!("Files in /pictures: {:#?}", result); +} ``` ## Building the Project diff --git a/crates/wasm/Cargo.toml b/crates/wasm/Cargo.toml index 4b2c5d63..9b13451a 100644 --- a/crates/wasm/Cargo.toml +++ b/crates/wasm/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wasm-wnfs" -version = "0.1.5" +version = "0.1.6" description = "WebNative Filesystem API (WebAssembly)" keywords = ["wnfs", "webnative", "ipfs", "decentralisation"] categories = [ diff --git a/crates/wasm/README.md b/crates/wasm/README.md index 8f656fd2..a4dd26d0 100644 --- a/crates/wasm/README.md +++ b/crates/wasm/README.md @@ -15,16 +15,16 @@ The core of this project is a WebAssembly binary compiled from the [Rust source Creating a new public directory. -```ts +```js import { PublicDirectory } from "wnfs"; const time = new Date(); const dir = new PublicDirectory(time); ``` -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 interface like [this one](https://github.com/WebNativeFileSystem/rs-wnfs/blob/8bb0fbb457051295f1ed4a4707dc230c04612658/crates/wasm/examples/graph/src/blockstore.ts#L9-L29) can be used. +The in-memory files and directories you create with `wnfs` will need to be sealed and stored somewhere. For that, an type that implements the BlockStore interface like [this one](https://github.com/WebNativeFileSystem/rs-wnfs/blob/8bb0fbb457051295f1ed4a4707dc230c04612658/crates/wasm/examples/graph/src/blockstore.ts#L9-L29) can be used. -```ts +```js import { MemoryBlockStore } from "./store"; import { PublicDirectory } from "wnfs"; @@ -39,7 +39,7 @@ The WNFS API is immutable, therefore, we need to keep track of the updated root Each fs operation returns a possibly updated root directory that subsequent changes can be applied on. -```ts +```js // ... // Create a /pictures/cats directory. @@ -61,7 +61,7 @@ var { rootDir } = await rootDir.write( ); // Create and add a file to /pictures/dogs directory. -var { rootDir } = await root.write( +var { rootDir } = await rootDir.write( ["pictures", "dogs", "billie.jpeg"], cid, time, @@ -73,6 +73,8 @@ var { rootDir } = await rootDir.rm(["pictures", "cats"], store); // List all files in /pictures directory. var { result } = await rootDir.ls(["pictures"], store); + +console.log("Files in /pictures directory:", result); ``` ## Setting up the Project