use crate::fs::{Fd, Metadata};
use crate::wasi::wasi_snapshot_preview1::WasiSnapshotPreview1;
use crate::Result;
use crate::WasiCtx;
use std::io;
pub struct File<'ctx> {
ctx: &'ctx WasiCtx,
fd: Fd,
}
impl<'ctx> File<'ctx> {
pub unsafe fn from_raw_wasi_fd(ctx: &'ctx WasiCtx, fd: Fd) -> Self {
Self { ctx, fd }
}
pub fn sync_all(&self) -> Result<()> {
self.ctx.fd_sync(self.fd)?;
Ok(())
}
pub fn sync_data(&self) -> Result<()> {
self.ctx.fd_datasync(self.fd)?;
Ok(())
}
pub fn set_len(&self, size: u64) -> Result<()> {
self.ctx.fd_filestat_set_size(self.fd, size)?;
Ok(())
}
pub fn metadata(&self) -> Result<Metadata> {
Ok(Metadata {})
}
}
impl<'ctx> Drop for File<'ctx> {
fn drop(&mut self) {
let _ = self.ctx.fd_close(self.fd);
}
}
impl<'ctx> io::Read for File<'ctx> {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
let mut nread = 0;
unimplemented!("File::read");
Ok(nread)
}
}