Struct tokio::fs::File
[−]
[src]
pub struct File { /* fields omitted */ }
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) -> Result<Async<u64>, Error>
[src]
pub fn poll_seek(&mut self, pos: SeekFrom) -> Result<Async<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 poll_sync_all(&mut self) -> Result<Async<()>, Error>
[src]
pub fn poll_sync_all(&mut self) -> Result<Async<()>, 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) -> Result<Async<()>, Error>
[src]
pub fn poll_sync_data(&mut self) -> Result<Async<()>, 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) -> Result<Async<()>, Error>
[src]
pub fn poll_set_len(&mut self, size: u64) -> Result<Async<()>, 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 poll_metadata(&mut self) -> Result<Async<Metadata>, Error>
[src]
pub fn poll_metadata(&mut self) -> Result<Async<Metadata>, Error>
Queries metadata about the underlying file.
pub fn poll_try_clone(&mut self) -> Result<Async<File>, Error>
[src]
pub fn poll_try_clone(&mut self) -> Result<Async<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
) -> Result<Async<()>, Error>
[src]
pub fn poll_set_permissions(
&mut self,
perm: Permissions
) -> Result<Async<()>, 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.
ⓘImportant traits for &'a Filepub fn into_std(self) -> File
[src]
pub fn into_std(self) -> File
Destructures the tokio_fs::File
into a [std::fs::File
][std].
Panics
This function will panic if [shutdown
] has been called.
Trait Implementations
impl Read for File
[src]
impl Read for File
fn read(&mut self, buf: &mut [u8]) -> Result<usize, Error>
[src]
fn read(&mut self, buf: &mut [u8]) -> Result<usize, Error>
Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more
unsafe fn initializer(&self) -> Initializer
[src]
unsafe fn initializer(&self) -> Initializer
read_initializer
)Determines if this Read
er can work with buffers of uninitialized memory. Read more
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
1.0.0[src]
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
Read all bytes until EOF in this source, placing them into buf
. Read more
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
1.0.0[src]
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
Read all bytes until EOF in this source, appending them to buf
. Read more
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
1.6.0[src]
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
Read the exact number of bytes required to fill buf
. Read more
ⓘImportant traits for &'a mut Rfn by_ref(&mut self) -> &mut Self
1.0.0[src]
fn by_ref(&mut self) -> &mut Self
Creates a "by reference" adaptor for this instance of Read
. Read more
ⓘImportant traits for Bytes<R>fn bytes(self) -> Bytes<Self>
1.0.0[src]
fn bytes(self) -> Bytes<Self>
Transforms this Read
instance to an [Iterator
] over its bytes. Read more
ⓘImportant traits for Chars<R>fn chars(self) -> Chars<Self>
[src]
fn chars(self) -> Chars<Self>
🔬 This is a nightly-only experimental API. (io
)
the semantics of a partial read/write of where errors happen is currently unclear and may change
Transforms this Read
instance to an [Iterator
] over [char
]s. Read more
ⓘImportant traits for Chain<T, U>fn chain<R>(self, next: R) -> Chain<Self, R> where
R: Read,
1.0.0[src]
fn chain<R>(self, next: R) -> Chain<Self, R> where
R: Read,
Creates an adaptor which will chain this stream with another. Read more
ⓘImportant traits for Take<T>fn take(self, limit: u64) -> Take<Self>
1.0.0[src]
fn take(self, limit: u64) -> Take<Self>
Creates an adaptor which will read at most limit
bytes from it. Read more
impl Write for File
[src]
impl Write for File
fn write(&mut self, buf: &[u8]) -> Result<usize, Error>
[src]
fn write(&mut self, buf: &[u8]) -> Result<usize, Error>
Write a buffer into this object, returning how many bytes were written. Read more
fn flush(&mut self) -> Result<(), Error>
[src]
fn flush(&mut self) -> Result<(), Error>
Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
1.0.0[src]
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Attempts to write an entire buffer into this write. Read more
fn write_fmt(&mut self, fmt: Arguments) -> Result<(), Error>
1.0.0[src]
fn write_fmt(&mut self, fmt: Arguments) -> Result<(), Error>
Writes a formatted string into this writer, returning any error encountered. Read more
ⓘImportant traits for &'a mut Rfn by_ref(&mut self) -> &mut Self
1.0.0[src]
fn by_ref(&mut self) -> &mut Self
Creates a "by reference" adaptor for this instance of Write
. Read more
impl Debug for File
[src]
impl Debug for File
fn fmt(&self, __arg_0: &mut Formatter) -> Result<(), Error>
[src]
fn fmt(&self, __arg_0: &mut Formatter) -> Result<(), Error>
Formats the value using the given formatter. Read more
impl Drop for File
[src]
impl Drop for File
impl AsyncRead for File
[src]
impl AsyncRead for File
unsafe fn prepare_uninitialized_buffer(&self, &mut [u8]) -> bool
[src]
unsafe fn prepare_uninitialized_buffer(&self, &mut [u8]) -> bool
Prepares an uninitialized buffer to be safe to pass to read
. Returns true
if the supplied buffer was zeroed out. Read more
fn poll_read(&mut self, buf: &mut [u8]) -> Result<Async<usize>, Error>
[src]
fn poll_read(&mut self, buf: &mut [u8]) -> Result<Async<usize>, Error>
Attempt to read from the AsyncRead
into buf
. Read more
fn read_buf<B>(&mut self, buf: &mut B) -> Result<Async<usize>, Error> where
B: BufMut,
[src]
fn read_buf<B>(&mut self, buf: &mut B) -> Result<Async<usize>, Error> where
B: BufMut,
Pull some bytes from this source into the specified Buf
, returning how many bytes were read. Read more
fn framed<T>(self, codec: T) -> Framed<Self, T> where
Self: AsyncWrite,
T: Decoder + Encoder,
[src]
fn framed<T>(self, codec: T) -> Framed<Self, T> where
Self: AsyncWrite,
T: Decoder + Encoder,
: Use tokio_codec::Decoder::framed instead
Provides a Stream
and Sink
interface for reading and writing to this Io
object, using Decode
and Encode
to read and write the raw data. Read more
fn split(self) -> (ReadHalf<Self>, WriteHalf<Self>) where
Self: AsyncWrite,
[src]
fn split(self) -> (ReadHalf<Self>, WriteHalf<Self>) where
Self: AsyncWrite,
Helper method for splitting this read/write object into two halves. Read more
impl AsyncWrite for File
[src]
impl AsyncWrite for File
fn shutdown(&mut self) -> Result<Async<()>, Error>
[src]
fn shutdown(&mut self) -> Result<Async<()>, Error>
Initiates or attempts to shut down this writer, returning success when the I/O connection has completely shut down. Read more
fn poll_write(&mut self, buf: &[u8]) -> Result<Async<usize>, Error>
[src]
fn poll_write(&mut self, buf: &[u8]) -> Result<Async<usize>, Error>
Attempt to write bytes from buf
into the object. Read more
fn poll_flush(&mut self) -> Result<Async<()>, Error>
[src]
fn poll_flush(&mut self) -> Result<Async<()>, Error>
Attempt to flush the object, ensuring that any buffered data reach their destination. Read more
fn write_buf<B>(&mut self, buf: &mut B) -> Result<Async<usize>, Error> where
B: Buf,
[src]
fn write_buf<B>(&mut self, buf: &mut B) -> Result<Async<usize>, Error> where
B: Buf,
Write a Buf
into this value, returning how many bytes were written. Read more