pub struct TokioCompatFile<'s> { /* private fields */ }
Expand description

File that implements AsyncRead, AsyncBufRead, AsyncSeek and AsyncWrite, which is compatible with tokio::fs::File.

Implementations

Create a TokioCompatFile.

Return the inner File.

Flush the write buffer, wait for the status report and send the close request if this is the last reference.

Cancel Safety

This function is cancel safe.

Return capacity of the internal buffer

Note that if there are pending requests, then the actual capacity might be more than the returned value.

Reserve the capacity of the internal buffer for at least cap bytes.

Shrink the capacity of the internal buffer to at most cap bytes.

This function is a low-level call.

It needs to be paired with the consume method or TokioCompatFile::consume_and_return_buffer to function properly.

When calling this method, none of the contents will be “read” in the sense that later calling read may return the same contents.

As such, you must consume the corresponding bytes using the methods listed above.

An empty buffer returned indicates that the stream has reached EOF.

This function does not change the offset into the file.

This can be used together with AsyncBufRead implementation for TokioCompatFile or TokioCompatFile::fill_buf or TokioCompatFile::read_into_buffer to avoid copying data.

Return empty Bytes on EOF.

This function does change the offset into the file.

  • amt - Amount of data to read into the buffer.

This function is a low-level call.

It needs to be paired with the consume method or TokioCompatFile::consume_and_return_buffer to function properly.

When calling this method, none of the contents will be “read” in the sense that later calling read may return the same contents.

As such, you must consume the corresponding bytes using the methods listed above.

An empty buffer returned indicates that the stream has reached EOF.

This function does not change the offset into the file.

  • amt - Amount of data to read into the buffer.

This function is a low-level call.

It needs to be paired with the consume method or TokioCompatFile::consume_and_return_buffer to function properly.

When calling this method, none of the contents will be “read” in the sense that later calling read may return the same contents.

As such, you must consume the corresponding bytes using the methods listed above.

An empty buffer returned indicates that the stream has reached EOF.

This function does not change the offset into the file.

Methods from Deref<Target = File<'s>>

Return the underlying sftp.

Change the metadata of a file or a directory.

Cancel Safety

This function is cancel safe.

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.

Cancel Safety

This function is cancel safe.

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.

Cancel Safety

This function is cancel safe.

Changes the permissions on the underlying file.

Cancel Safety

This function is cancel safe.

Queries metadata about the underlying file.

  • n - number of bytes to read in

If the File has reached EOF or n == 0, then None is returned.

Write data into the file.

Write from multiple buffer at once.

Zero copy write.

  • n - number of bytes to read in.

If n == 0 or EOF is reached, then buffer is returned unchanged.

Cancel Safety

This function is cancel safe.

Write entire buf.

Cancel Safety

This function is cancel safe.

Write entire buf.

Cancel Safety

This function is cancel safe.

Write entire buf.

Cancel Safety

This function is cancel safe.

Return the offset of the file.

Copy n bytes of data from self to dst.

The server MUST copy the data exactly as if the data is copied using a series of read and write.

There are no protocol restictions on this operation; however, the server MUST ensure that the user does not exceed quota, etc. The server is, as always, free to complete this operation out of order if it is too large to complete immediately, or to refuse a request that is too large.

After a successful function call, the offset of self and dst are increased by n.

Precondition

Requires extension copy_data. For openssh-portable, this is available from V_9_0_P1.

If the extension is not supported by the server, this function would fail with Error::UnsupportedExtension.

Copy data from self to dst until EOF is encountered.

The server MUST copy the data exactly as if the data is copied using a series of read and write.

There are no protocol restictions on this operation; however, the server MUST ensure that the user does not exceed quota, etc. The server is, as always, free to complete this operation out of order if it is too large to complete immediately, or to refuse a request that is too large.

After a successful function call, the offset of self and dst are unchanged.

Precondition

Requires extension copy_data. For openssh-portable, this is available from V_9_0_P1.

If the extension is not supported by the server, this function would fail with Error::UnsupportedExtension.

Trait Implementations

Attempts to return the contents of the internal buffer, filling it with more data from the inner reader if it is empty. Read more
Tells this buffer that amt bytes have been consumed from the buffer, so they should no longer be returned in calls to poll_read. Read more
Attempts to read from the AsyncRead into buf. Read more
Attempts to seek to an offset, in bytes, in a stream. Read more
Waits for a seek operation to complete. Read more

TokioCompatFile::poll_write only writes data to the buffer.

TokioCompatFile::poll_write and TokioCompatFile::poll_write_vectored would send at most one sftp request.

It is perfectly safe to buffer requests and send them in one go, since sftp v3 guarantees that requests on the same file handler is processed sequentially.

NOTE that these writes cannot be cancelled.

One maybe obvious note when using append-mode:

make sure that all data that belongs together is written to the file in one operation.

This can be done by concatenating strings before passing them to AsyncWrite::poll_write or AsyncWrite::poll_write_vectored and calling AsyncWrite::poll_flush on TokioCompatFile when the message is complete.

Calling AsyncWrite::poll_flush on TokioCompatFile would wait on writes in the order they are sent.

Attempt to write bytes from buf into the object. Read more
Attempts to flush the object, ensuring that any buffered data reach their destination. Read more
Initiates or attempts to shut down this writer, returning success when the I/O connection has completely shut down. Read more
Like poll_write, except that it writes from a slice of buffers. Read more
Determines if this writer has an efficient poll_write_vectored implementation. Read more

Creates a new TokioCompatFile instance that shares the same underlying file handle as the existing File instance.

Reads, writes, and seeks can be performed independently.

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
The resulting type after dereferencing.
Dereferences the value.
Mutably dereferences the value.
Converts to this type from the input type.
Converts to this type from the input type.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Reads all bytes into buf until the delimiter byte or EOF is reached. Read more
Reads all bytes until a newline (the 0xA byte) is reached, and append them to the provided buffer. Read more
Returns a stream of the contents of this reader split on the byte byte. Read more
Returns the contents of the internal buffer, filling it with more data from the inner reader if it is empty. Read more
Tells this buffer that amt bytes have been consumed from the buffer, so they should no longer be returned in calls to read. Read more
Returns a stream over the lines of this reader. This method is the async equivalent to BufRead::lines. Read more
Creates a new AsyncRead instance that chains this stream with next. Read more
Pulls some bytes from this source into the specified buffer, returning how many bytes were read. Read more
Pulls some bytes from this source into the specified buffer, advancing the buffer’s internal cursor. Read more
Reads the exact number of bytes required to fill buf. Read more
Reads an unsigned 8 bit integer from the underlying reader. Read more
Reads a signed 8 bit integer from the underlying reader. Read more
Reads an unsigned 16-bit integer in big-endian order from the underlying reader. Read more
Reads a signed 16-bit integer in big-endian order from the underlying reader. Read more
Reads an unsigned 32-bit integer in big-endian order from the underlying reader. Read more
Reads a signed 32-bit integer in big-endian order from the underlying reader. Read more
Reads an unsigned 64-bit integer in big-endian order from the underlying reader. Read more
Reads an signed 64-bit integer in big-endian order from the underlying reader. Read more
Reads an unsigned 128-bit integer in big-endian order from the underlying reader. Read more
Reads an signed 128-bit integer in big-endian order from the underlying reader. Read more
Reads an 32-bit floating point type in big-endian order from the underlying reader. Read more
Reads an 64-bit floating point type in big-endian order from the underlying reader. Read more
Reads an unsigned 16-bit integer in little-endian order from the underlying reader. Read more
Reads a signed 16-bit integer in little-endian order from the underlying reader. Read more
Reads an unsigned 32-bit integer in little-endian order from the underlying reader. Read more
Reads a signed 32-bit integer in little-endian order from the underlying reader. Read more
Reads an unsigned 64-bit integer in little-endian order from the underlying reader. Read more
Reads an signed 64-bit integer in little-endian order from the underlying reader. Read more
Reads an unsigned 128-bit integer in little-endian order from the underlying reader. Read more
Reads an signed 128-bit integer in little-endian order from the underlying reader. Read more
Reads an 32-bit floating point type in little-endian order from the underlying reader. Read more
Reads an 64-bit floating point type in little-endian order from the underlying reader. Read more
Reads all bytes until EOF in this source, placing them into buf. Read more
Reads all bytes until EOF in this source, appending them to buf. Read more
Creates an adaptor which reads at most limit bytes from it. Read more
Creates a future which will seek an IO object, and then yield the new position in the object and the object itself. Read more
Creates a future which will rewind to the beginning of the stream. Read more
Creates a future which will return the current seek position from the start of the stream. Read more
Writes a buffer into this writer, returning how many bytes were written. Read more
Like write, except that it writes from a slice of buffers. Read more
Writes a buffer into this writer, advancing the buffer’s internal cursor. Read more
Attempts to write an entire buffer into this writer. Read more
Attempts to write an entire buffer into this writer. Read more
Writes an unsigned 8-bit integer to the underlying writer. Read more
Writes an unsigned 8-bit integer to the underlying writer. Read more
Writes an unsigned 16-bit integer in big-endian order to the underlying writer. Read more
Writes a signed 16-bit integer in big-endian order to the underlying writer. Read more
Writes an unsigned 32-bit integer in big-endian order to the underlying writer. Read more
Writes a signed 32-bit integer in big-endian order to the underlying writer. Read more
Writes an unsigned 64-bit integer in big-endian order to the underlying writer. Read more
Writes an signed 64-bit integer in big-endian order to the underlying writer. Read more
Writes an unsigned 128-bit integer in big-endian order to the underlying writer. Read more
Writes an signed 128-bit integer in big-endian order to the underlying writer. Read more
Writes an 32-bit floating point type in big-endian order to the underlying writer. Read more
Writes an 64-bit floating point type in big-endian order to the underlying writer. Read more
Writes an unsigned 16-bit integer in little-endian order to the underlying writer. Read more
Writes a signed 16-bit integer in little-endian order to the underlying writer. Read more
Writes an unsigned 32-bit integer in little-endian order to the underlying writer. Read more
Writes a signed 32-bit integer in little-endian order to the underlying writer. Read more
Writes an unsigned 64-bit integer in little-endian order to the underlying writer. Read more
Writes an signed 64-bit integer in little-endian order to the underlying writer. Read more
Writes an unsigned 128-bit integer in little-endian order to the underlying writer. Read more
Writes an signed 128-bit integer in little-endian order to the underlying writer. Read more
Writes an 32-bit floating point type in little-endian order to the underlying writer. Read more
Writes an 64-bit floating point type in little-endian order to the underlying writer. Read more
Flushes this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
Shuts down the output stream, ensuring that the value can be dropped cleanly. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.