Skip to content

Commit

Permalink
Fix packages docs
Browse files Browse the repository at this point in the history
  • Loading branch information
appcypher committed May 23, 2022
1 parent 17382a7 commit e60649d
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 113 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.

115 changes: 63 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
// ...
```

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion crates/fs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 = [
Expand Down
115 changes: 63 additions & 52 deletions crates/fs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
// ...
```

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion 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.5"
version = "0.1.6"
description = "WebNative Filesystem API (WebAssembly)"
keywords = ["wnfs", "webnative", "ipfs", "decentralisation"]
categories = [
Expand Down
12 changes: 7 additions & 5 deletions crates/wasm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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.
Expand All @@ -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,
Expand All @@ -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
Expand Down

0 comments on commit e60649d

Please sign in to comment.