pub trait FileExt {
Show 16 methods
fn read_vectored_at(
&self,
bufs: &mut [IoSliceMut<'_>],
offset: u64
) -> Result<usize>;
fn write_vectored_at(
&self,
bufs: &[IoSlice<'_>],
offset: u64
) -> Result<usize>;
fn tell(&self) -> Result<u64>;
fn fdstat_set_flags(&self, flags: u16) -> Result<()>;
fn fdstat_set_rights(&self, rights: u64, inheriting: u64) -> Result<()>;
fn advise(&self, offset: u64, len: u64, advice: u8) -> Result<()>;
fn allocate(&self, offset: u64, len: u64) -> Result<()>;
fn create_directory<P: AsRef<Path>>(&self, dir: P) -> Result<()>;
fn read_link<P: AsRef<Path>>(&self, path: P) -> Result<PathBuf>;
fn metadata_at<P: AsRef<Path>>(
&self,
lookup_flags: u32,
path: P
) -> Result<Metadata>;
fn remove_file<P: AsRef<Path>>(&self, path: P) -> Result<()>;
fn remove_directory<P: AsRef<Path>>(&self, path: P) -> Result<()>;
fn read_at(&self, buf: &mut [u8], offset: u64) -> Result<usize> { ... }
fn read_exact_at(&self, buf: &mut [u8], offset: u64) -> Result<()> { ... }
fn write_at(&self, buf: &[u8], offset: u64) -> Result<usize> { ... }
fn write_all_at(&self, buf: &[u8], offset: u64) -> Result<()> { ... }
}
Expand description
WASI-specific extensions to File
.
Required Methods
fn read_vectored_at(
&self,
bufs: &mut [IoSliceMut<'_>],
offset: u64
) -> Result<usize>
fn read_vectored_at(
&self,
bufs: &mut [IoSliceMut<'_>],
offset: u64
) -> Result<usize>
Reads a number of bytes starting from a given offset.
Returns the number of bytes read.
The offset is relative to the start of the file and thus independent from the current cursor.
The current file cursor is not affected by this function.
Note that similar to File::read_vectored
, it is not an error to
return with a short read.
Writes a number of bytes starting from a given offset.
Returns the number of bytes written.
The offset is relative to the start of the file and thus independent from the current cursor.
The current file cursor is not affected by this function.
When writing beyond the end of the file, the file is appropriately extended and the intermediate bytes are initialized with the value 0.
Note that similar to File::write_vectored
, it is not an error to return a
short write.
Returns the current position within the file.
This corresponds to the fd_tell
syscall and is similar to
seek
where you offset 0 bytes from the current position.
fn fdstat_set_flags(&self, flags: u16) -> Result<()>
fn fdstat_set_flags(&self, flags: u16) -> Result<()>
Adjust the flags associated with this file.
This corresponds to the fd_fdstat_set_flags
syscall.
Adjust the rights associated with this file.
This corresponds to the fd_fdstat_set_rights
syscall.
Provide file advisory information on a file descriptor.
This corresponds to the fd_advise
syscall.
Force the allocation of space in a file.
This corresponds to the fd_allocate
syscall.
Create a directory.
This corresponds to the path_create_directory
syscall.
Read the contents of a symbolic link.
This corresponds to the path_readlink
syscall.
Return the attributes of a file or directory.
This corresponds to the path_filestat_get
syscall.
Unlink a file.
This corresponds to the path_unlink_file
syscall.
Provided Methods
Reads a number of bytes starting from a given offset.
Returns the number of bytes read.
The offset is relative to the start of the file and thus independent from the current cursor.
The current file cursor is not affected by this function.
Note that similar to File::read
, it is not an error to return with a
short read.
Reads the exact number of byte required to fill buf
from the given offset.
The offset is relative to the start of the file and thus independent from the current cursor.
The current file cursor is not affected by this function.
Similar to Read::read_exact
but uses read_at
instead of read
.
Errors
If this function encounters an error of the kind
io::ErrorKind::Interrupted
then the error is ignored and the operation
will continue.
If this function encounters an “end of file” before completely filling
the buffer, it returns an error of the kind io::ErrorKind::UnexpectedEof
.
The contents of buf
are unspecified in this case.
If any other read error is encountered then this function immediately
returns. The contents of buf
are unspecified in this case.
If this function returns an error, it is unspecified how many bytes it has read, but it will never read more than would be necessary to completely fill the buffer.
Writes a number of bytes starting from a given offset.
Returns the number of bytes written.
The offset is relative to the start of the file and thus independent from the current cursor.
The current file cursor is not affected by this function.
When writing beyond the end of the file, the file is appropriately extended and the intermediate bytes are initialized with the value 0.
Note that similar to File::write
, it is not an error to return a
short write.
Attempts to write an entire buffer starting from a given offset.
The offset is relative to the start of the file and thus independent from the current cursor.
The current file cursor is not affected by this function.
This method will continuously call write_at
until there is no more data
to be written or an error of non-io::ErrorKind::Interrupted
kind is
returned. This method will not return until the entire buffer has been
successfully written or such an error occurs. The first error that is
not of io::ErrorKind::Interrupted
kind generated from this method will be
returned.
Errors
This function will return the first error of
non-io::ErrorKind::Interrupted
kind that write_at
returns.