Struct tokio_fs::file::File [−][src]
A reference to an open file on the filesystem.
This is a specialized version of std::fs::File
for usage from the
Tokio runtime.
An instance of a File
can be read and/or written depending on what options
it was opened with. Files also implement Seek to alter the logical cursor
that the file contains internally.
Files are automatically closed when they go out of scope.
Methods
impl File
[src]
[−]
impl File
pub fn open<P>(path: P) -> OpenFuture<P> where
P: AsRef<Path> + Send + 'static,
[src]
[−]
pub fn open<P>(path: P) -> OpenFuture<P> where
P: AsRef<Path> + Send + 'static,
Attempts to open a file in read-only mode.
See OpenOptions
for more details.
Errors
OpenFuture
results in an error if called from outside of the Tokio
runtime or if the underlying open
call results in an error.
pub fn create<P>(path: P) -> CreateFuture<P> where
P: AsRef<Path> + Send + 'static,
[src]
[−]
pub fn create<P>(path: P) -> CreateFuture<P> where
P: AsRef<Path> + Send + 'static,
Opens a file in write-only mode.
This function will create a file if it does not exist, and will truncate it if it does.
See OpenOptions
for more details.
Errors
CreateFuture
results in an error if called from outside of the Tokio
runtime or if the underlying create
call results in an error.
pub fn poll_seek(&mut self, pos: SeekFrom) -> Poll<u64, Error>
[src]
[−]
pub fn poll_seek(&mut self, pos: SeekFrom) -> Poll<u64, Error>
Seek to an offset, in bytes, in a stream.
A seek beyond the end of a stream is allowed, but implementation defined.
If the seek operation completed successfully, this method returns the
new position from the start of the stream. That position can be used
later with SeekFrom::Start
.
Errors
Seeking to a negative offset is considered an error.
pub fn seek(self, pos: SeekFrom) -> SeekFuture
[src]
[−]
pub fn seek(self, pos: SeekFrom) -> SeekFuture
Seek to an offset, in bytes, in a stream.
Similar to poll_seek
, but returning a Future
.
This method consumes the File
and returns it back when the future
completes.
pub fn poll_sync_all(&mut self) -> Poll<(), Error>
[src]
[−]
pub fn poll_sync_all(&mut self) -> Poll<(), Error>
Attempts to sync all OS-internal metadata to disk.
This function will attempt to ensure that all in-core data reaches the filesystem before returning.
pub fn poll_sync_data(&mut self) -> Poll<(), Error>
[src]
[−]
pub fn poll_sync_data(&mut self) -> Poll<(), Error>
This function is similar to poll_sync_all
, except that it may not
synchronize file metadata to the filesystem.
This is intended for use cases that must synchronize content, but don't need the metadata on disk. The goal of this method is to reduce disk operations.
Note that some platforms may simply implement this in terms of poll_sync_all
.
pub fn poll_set_len(&mut self, size: u64) -> Poll<(), Error>
[src]
[−]
pub fn poll_set_len(&mut self, size: u64) -> Poll<(), Error>
Truncates or extends the underlying file, updating the size of this file to become size.
If the size is less than the current file's size, then the file will be shrunk. If it is greater than the current file's size, then the file will be extended to size and have all of the intermediate data filled in with 0s.
Errors
This function will return an error if the file is not opened for writing.
pub fn metadata(self) -> MetadataFuture
[src]
[−]
pub fn metadata(self) -> MetadataFuture
Queries metadata about the underlying file.
pub fn poll_metadata(&mut self) -> Poll<Metadata, Error>
[src]
[−]
pub fn poll_metadata(&mut self) -> Poll<Metadata, Error>
Queries metadata about the underlying file.
pub fn poll_try_clone(&mut self) -> Poll<File, Error>
[src]
[−]
pub fn poll_try_clone(&mut self) -> Poll<File, Error>
Create a new File
instance that shares the same underlying file handle
as the existing File
instance. Reads, writes, and seeks will affect both
File instances simultaneously.
pub fn poll_set_permissions(&mut self, perm: Permissions) -> Poll<(), Error>
[src]
[−]
pub fn poll_set_permissions(&mut self, perm: Permissions) -> Poll<(), Error>
Changes the permissions on the underlying file.
Platform-specific behavior
This function currently corresponds to the fchmod
function on Unix and
the SetFileInformationByHandle
function on Windows. Note that, this
may change in the future.
Errors
This function will return an error if the user lacks permission change attributes on the underlying file. It may also return an error in other os-specific unspecified cases.
pub fn into_std(self) -> StdFile
[src]
[−]
pub fn into_std(self) -> StdFile
Destructures the tokio_fs::File
into a [std::fs::File
][std].
Panics
This function will panic if [shutdown
] has been called.
Trait Implementations
impl Debug for File
[src]
[+]
impl Debug for File
impl Read for File
[src]
[+]
impl Read for File
impl AsyncRead for File
[src]
[+]
impl AsyncRead for File
impl Write for File
[src]
[+]
impl Write for File
impl AsyncWrite for File
[src]
[+]
impl AsyncWrite for File
impl Drop for File
[src]
[+]
impl Drop for File