https://github.com/utooland/tokio-fs-ext
Extend tokio fs to be compatible with native and wasm
https://github.com/utooland/tokio-fs-ext
browserfs filesystem opfs rust tokio wasm
Last synced: 5 months ago
JSON representation
Extend tokio fs to be compatible with native and wasm
- Host: GitHub
- URL: https://github.com/utooland/tokio-fs-ext
- Owner: utooland
- Created: 2025-07-25T02:55:43.000Z (11 months ago)
- Default Branch: master
- Last Pushed: 2026-02-07T17:06:12.000Z (5 months ago)
- Last Synced: 2026-02-08T00:07:23.274Z (5 months ago)
- Topics: browserfs, filesystem, opfs, rust, tokio, wasm
- Language: Rust
- Homepage: https://docs.rs/tokio-fs-ext
- Size: 293 KB
- Stars: 9
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# tokio-fs-ext
[](https://crates.io/crates/tokio-fs-ext)
[](https://docs.rs/tokio-fs-ext)
Tokio-fs-ext is a Rust library that provides a `tokio::fs` compatible API for both native and WebAssembly environments on web browsers.
## Overview
The standard `tokio::fs` module in the Tokio runtime is a powerful tool for asynchronous file system operations. However, it relies on `syscalls` and I/O operations that are executed on a dedicated thread pool. This design is not suitable for WebAssembly environments where threading and direct file system access are restricted.
This library aims to bridge that gap by offering an API that is compatible with `tokio::fs` but works seamlessly in WebAssembly. It provides a consistent interface for file system operations, regardless of the target platform.
## Features
- A `tokio::fs`-like API.
- Re-export `tokio::fs` on native platforms, and use implementations by [`OPFS`](https://developer.mozilla.org/en-US/docs/Web/API/File_System_API/Origin_private_file_system) on `wasm32-unknown-unknown` platform.
- Implemented [futures::io::traits](https://docs.rs/futures/0.3.31/futures/io/index.html#traits).
- Asynchronous file operations for non-blocking applications.
## Usage
```rust
use tokio_fs_ext as fs;
use std::io;
use futures::io::AsyncReadExt;
async fn foo() -> io::Result<()> {
fs::write("hello.txt", "Hello").await?;
{
let mut file = fs::File::open("hello.txt").await?;
let mut vec = Vec::new();
file.read_to_end(&mut vec).await?;
}
fs::remove_file("hello.txt").await?;
Ok(())
}
```
## Clarification
- The implements for WebAssembly can only be used in [`DedicatedWorkerGlobalScope`](https://developer.mozilla.org/en-US/docs/Web/API/DedicatedWorkerGlobalScope).
## Contributing
## Testing
```bash
# test native
cargo test
# test wasm
brew install --cask chromedriver
cargo test --target wasm32-unknown-unknown
# test wasm in interactive mode
brew install wasm-pack
wasm-pack test --chrome
```