forked from functionland/wnfs-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
5 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,15 @@ | ||
# wnfs-utils | ||
# wnfs-utils-web | ||
|
||
This library is used with wnfs-android to feed custom blockstore to wnfs-android (from Fula interface) | ||
This library is used with wnfslib-web to use wnfs on the browser. | ||
|
||
## Build and Use in TypeScript | ||
|
||
1. Build your WebAssembly module: | ||
1. Check the WebAssembly module: | ||
|
||
``` | ||
wasm-pack build --target web | ||
``` | ||
|
||
2. edit package name in pkg/package.json. Install the generated package in your Next.js project: | ||
2. Upload to GitHub | ||
|
||
``` | ||
npm install ../path/to/your/pkg | ||
``` | ||
|
||
3. Use in your React components: | ||
|
||
``` | ||
import { WasmPrivateDirectoryHelper } from 'wnfsutils'; | ||
import { FFIStore } from 'wnfs-wasm'; | ||
function MyComponent() { | ||
useEffect(() => { | ||
async function init() { | ||
// Create FFIStore implementation using wnfs-wasm | ||
const store = new FFIStore(); | ||
// Initialize helper | ||
const helper = new WasmPrivateDirectoryHelper(store); | ||
// Use methods | ||
try { | ||
const content = new TextEncoder().encode("Hello WNFS!"); | ||
await helper.write_file("/test.txt", content, Date.now()); | ||
const readContent = await helper.read_file("/test.txt"); | ||
console.log(new TextDecoder().decode(readContent)); | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
} | ||
init(); | ||
}, []); | ||
return <div>My WNFS Component</div>; | ||
} | ||
``` | ||
3. Create a release with the same version as in Cargo.toml |