Thanks to visit codestin.com
Credit goes to lib.rs

#tokio-fs #tokio #opfs #wasm

tokio-fs-ext

Extend tokio fs to be compatible with native and wasm

54 releases (7 breaking)

Uses new Rust 2024

new 0.7.1 Jan 16, 2026
0.6.10 Dec 31, 2025
0.6.4 Nov 5, 2025
0.3.0 Jul 31, 2025

#406 in Filesystem

Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App

3,157 downloads per month
Used in opfs-project

MIT license

85KB
2K SLoC

tokio-fs-ext

Crates.io Docs.rs

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 on wasm32-unknown-unknown platform.
  • Implemented futures::io::traits.
  • Asynchronous file operations for non-blocking applications.

Usage

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

Contributing

Testing

# 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

Dependencies

~2.5–7.5MB
~106K SLoC