tokio-fs-ext 0.7.3

Extend tokio fs to be compatible with native and wasm
Documentation
use std::{io, path::Path};

use js_sys::Uint8Array;
use wasm_bindgen::JsCast;
use wasm_bindgen_futures::JsFuture;
use web_sys::File as JsFile;

use super::opfs::{get_fs_handle, CreateFileMode, opfs_err};

pub async fn read(path: impl AsRef<Path>) -> io::Result<Vec<u8>> {
    let handle = get_fs_handle(path, CreateFileMode::NotCreate).await?;

    let file: JsFile = JsFuture::from(handle.get_file())
        .await
        .map_err(opfs_err)?
        .unchecked_into();

    let array_buffer = JsFuture::from(file.array_buffer())
        .await
        .map_err(opfs_err)?;

    Ok(Uint8Array::new(&array_buffer).to_vec())
}