0.1.7-alpha • Published 3 years ago

wnfs v0.1.7-alpha

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
3 years ago

Wasm WNFS

This package implements the primitives for creating and manipulating IPLD graphs that encode WNFS.

The core of this project is a WebAssembly binary compiled from the Rust source code.

Outline

Usage

Creating a new public directory.

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 type that implements the BlockStore interface like this one can be used.

import { MemoryBlockStore } from "./store";
import { PublicDirectory } from "wnfs";

const time = new Date();
const dir = new PublicDirectory(time);
const store = new MemoryBlockStore();

// ...

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.

// ...

// Create a /pictures/cats directory.
var { rootDir } = await dir.mkdir(["pictures", "cats"], time, store);

// Get a sample CIDv1.
const cid = Uint8Array.from([
  1, 112, 18, 32, 195, 196, 115, 62, 200, 175, 253, 6, 207, 158, 159, 245, 15,
  252, 107, 205, 46, 200, 90, 97, 112, 0, 75, 183, 9, 102, 156, 49, 222, 148,
  57, 26,
]);

// Add a file to /pictures/cats.
var { rootDir } = await rootDir.write(
  ["pictures", "cats", "tabby.png"],
  cid,
  time,
  store
);

// Create and add a file to /pictures/dogs directory.
var { rootDir } = await rootDir.write(
  ["pictures", "dogs", "billie.jpeg"],
  cid,
  time,
  store
);

// Delete /pictures/cats directory.
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

  • Install wasm-pack

    cargo install wasm-pack
  • Install dependencies

    yarn
  • Install playwright binaries

    npx playwright install
  • Build project

    wasm-pack build

Testing the Project

  • Run tests

    yarn playwright test

Publishing Package

  • Build the project

    rs-wnfs build --wasm
  • Publish from the pkg directory

    cd pkg
    npm publish
0.2.2

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.29-alpha1

2 years ago

0.1.28

2 years ago

0.1.27

2 years ago

0.1.21

3 years ago

0.1.22

2 years ago

0.1.23

2 years ago

0.1.24

2 years ago

0.1.26

2 years ago

0.1.20

3 years ago

0.1.14

3 years ago

0.1.15

3 years ago

0.1.16

3 years ago

0.1.17

3 years ago

0.1.18

3 years ago

0.1.19

3 years ago

0.1.10

3 years ago

0.1.11

3 years ago

0.1.12

3 years ago

0.1.13

3 years ago

0.1.7

3 years ago

0.1.7-alpha5

3 years ago

0.1.7-alpha3

3 years ago

0.1.7-alpha2

3 years ago

0.1.7-alpha

3 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago