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]
pub fn open<P>(path: P) -> OpenFuture<P> where
P: AsRef<Path> + Send + 'static,
[src]
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]
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]
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]
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) -> Result<Async<()>, Error>
[src]
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]
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]
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]
Queries metadata about the underlying file.
pub fn poll_metadata(&mut self) -> Result<Async<Metadata>, Error>
[src]
Queries metadata about the underlying file.
pub fn poll_try_clone(&mut self) -> Result<Async<File>, Error>
[src]
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]
&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]
Destructures the tokio_fs::File
into a std::fs::File
.
Panics
This function will panic if shutdown
has been called.
Trait Implementations
impl Debug for File
[src]
fn fmt(&self, __arg_0: &mut Formatter) -> Result<(), Error>
[src]
Formats the value using the given formatter. Read more
impl Write for File
[src]
fn write(&mut self, buf: &[u8]) -> Result<usize, Error>
[src]
Write a buffer into this object, returning how many bytes were written. Read more
fn flush(&mut self) -> Result<(), Error>
[src]
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]
Attempts to write an entire buffer into this write. Read more
fn write_fmt(&mut self, fmt: Arguments) -> Result<(), Error>
1.0.0[src]
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]
Creates a "by reference" adaptor for this instance of Write
. Read more
impl Read for File
[src]
fn read(&mut self, buf: &mut [u8]) -> Result<usize, Error>
[src]
Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more
unsafe fn initializer(&self) -> Initializer
[src]
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]
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]
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]
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]
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]
Transforms this Read
instance to an [Iterator
] over its bytes. Read more
ⓘImportant traits for Chars<R>fn chars(self) -> Chars<Self>
[src]
🔬 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]
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]
Creates an adaptor which will read at most limit
bytes from it. Read more
impl AsyncRead for File
[src]
unsafe fn prepare_uninitialized_buffer(&self, &mut [u8]) -> bool
[src]
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]
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]
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]
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]
Self: AsyncWrite,
Helper method for splitting this read/write object into two halves. Read more
impl Drop for File
[src]
impl AsyncWrite for File
[src]
fn shutdown(&mut self) -> Result<Async<()>, Error>
[src]
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]
Attempt to write bytes from buf
into the object. Read more
fn poll_flush(&mut self) -> Result<Async<()>, Error>
[src]
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]
B: Buf,
Write a Buf
into this value, returning how many bytes were written. Read more