- Notifications
You must be signed in to change notification settings - Fork0
Extend tokio fs to be compatible with native and wasm
utooland/tokio-fs-ext
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Tokio-fs-ext is a Rust library that provides atokio::fs compatible API for both native and WebAssembly environments on web browsers.
The standardtokio::fs module in the Tokio runtime is a powerful tool for asynchronous file system operations. However, it relies on blockingsyscalls an 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 withtokio::fs but works seamlessly in WebAssembly. It provides a consistent interface for file system operations, regardless of the target platform.
- A
tokio::fs-like API. - Re-export
tokio::fson native platforms, and use implementations byOPFSonwasm32-unknown-unknownplatform. - Implementedfutures::io::traits.
- Asynchronous file operations for non-blocking applications.
use tokio_fs_extas fs;use std::io;use futures::io::AsyncReadExt;asyncfnfoo() -> io::Result<()>{ fs::write("hello.txt","Hello").await?;{letmut file = fs::File::open("hello.txt").await?;letmut vec =Vec::new(); file.read_to_end(&mut vec).await?;} fs::remove_file("hello.txt").await?;Ok(())}
- The implements for WebAssembly can only be used in
DedicatedWorkerGlobalScope.
# test nativecargotest# test wasmbrew install --cask chromedrivercargotest --target wasm32-unknown-unknown# test wasm in interactive modebrew install wasm-packwasm-packtest --chrome
About
Extend tokio fs to be compatible with native and wasm
Topics
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Contributors3
Uh oh!
There was an error while loading.Please reload this page.