tokio_fs_ext/fs/wasm/write.rs
1use std::{io, path::Path};
2
3use futures::io::AsyncSeekExt;
4
5use super::OpenOptions;
6
7pub async fn write(path: impl AsRef<Path>, content: impl AsRef<[u8]>) -> io::Result<()> {
8 let mut file = OpenOptions::new()
9 .create(true)
10 .truncate(true)
11 .write(true)
12 .open(path)
13 .await?;
14
15 file.seek(io::SeekFrom::Start(0)).await?;
16
17 file.write_with_buf(content.as_ref())?;
18
19 file.sync_data().await?;
20
21 Ok(())
22}