Struct openssh_sftp_client::file::TokioCompatFile
source · [−]pub struct TokioCompatFile<'s> { /* private fields */ }
Expand description
File that implements AsyncRead
, AsyncBufRead
, AsyncSeek
and
AsyncWrite
, which is compatible with
tokio::fs::File
.
Implementations
sourceimpl<'s> TokioCompatFile<'s>
impl<'s> TokioCompatFile<'s>
sourcepub fn new(inner: File<'s>) -> Self
pub fn new(inner: File<'s>) -> Self
Create a TokioCompatFile
using DEFAULT_BUFLEN
.
sourcepub fn with_capacity(inner: File<'s>, buffer_len: NonZeroUsize) -> Self
pub fn with_capacity(inner: File<'s>, buffer_len: NonZeroUsize) -> Self
Create a TokioCompatFile
.
buffer_len
- buffer len to be used inAsyncBufRead
and the minimum length to read inAsyncRead
.
sourcepub fn into_inner(self) -> File<'s>
pub fn into_inner(self) -> File<'s>
Return the inner File
.
sourcepub async fn close(self) -> Result<(), Error>
pub async fn close(self) -> Result<(), Error>
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.
sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Return capacity of the internal buffer
Note that if there are pending requests, then the actual capacity might be more than the returned value.
sourcepub fn reserve(&mut self, new_cap: usize)
pub fn reserve(&mut self, new_cap: usize)
Reserve the capacity of the internal buffer for at least cap
bytes.
sourcepub fn shrink_to(&mut self, new_cap: usize)
pub fn shrink_to(&mut self, new_cap: usize)
Shrink the capacity of the internal buffer to at most cap
bytes.
sourcepub async fn fill_buf(&mut self) -> Result<(), Error>
pub async fn fill_buf(&mut self) -> Result<(), Error>
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.
sourcepub fn consume_and_return_buffer(&mut self, amt: usize) -> Bytes
pub fn consume_and_return_buffer(&mut self, amt: usize) -> Bytes
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.
sourcepub fn poll_read_into_buffer(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
amt: NonZeroU32
) -> Poll<Result<(), Error>>
pub fn poll_read_into_buffer(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
amt: NonZeroU32
) -> Poll<Result<(), Error>>
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.
sourcepub async fn read_into_buffer(&mut self, amt: NonZeroU32) -> Result<(), Error>
pub async fn read_into_buffer(&mut self, amt: NonZeroU32) -> Result<(), Error>
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>>
sourcepub async fn set_len(&mut self, size: u64) -> Result<(), Error>
pub async fn set_len(&mut self, size: u64) -> Result<(), 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.
Cancel Safety
This function is cancel safe.
sourcepub async fn sync_all(&mut self) -> Result<(), Error>
pub async fn sync_all(&mut self) -> Result<(), 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.
Cancel Safety
This function is cancel safe.
sourcepub async fn set_permissions(&mut self, perm: Permissions) -> Result<(), Error>
pub async fn set_permissions(&mut self, perm: Permissions) -> Result<(), Error>
sourcepub async fn metadata(&mut self) -> Result<MetaData, Error>
pub async fn metadata(&mut self) -> Result<MetaData, Error>
Queries metadata about the underlying file.
sourcepub async fn read(
&mut self,
n: u32,
buffer: BytesMut
) -> Result<Option<BytesMut>, Error>
pub async fn read(
&mut self,
n: u32,
buffer: BytesMut
) -> Result<Option<BytesMut>, Error>
n
- number of bytes to read in
If the File
has reached EOF or n == 0
, then None
is returned.
sourcepub async fn write_vectorized(
&mut self,
bufs: &[IoSlice<'_>]
) -> Result<usize, Error>
pub async fn write_vectorized(
&mut self,
bufs: &[IoSlice<'_>]
) -> Result<usize, Error>
Write from multiple buffer at once.
sourcepub async fn write_zero_copy(
&mut self,
bytes_slice: &[Bytes]
) -> Result<usize, Error>
pub async fn write_zero_copy(
&mut self,
bytes_slice: &[Bytes]
) -> Result<usize, Error>
Zero copy write.
sourcepub async fn read_all(
&mut self,
n: usize,
buffer: BytesMut
) -> Result<BytesMut, Error>
pub async fn read_all(
&mut self,
n: usize,
buffer: BytesMut
) -> Result<BytesMut, Error>
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.
sourcepub async fn copy_to(
&mut self,
dst: &mut Self,
n: NonZeroU64
) -> Result<(), Error>
pub async fn copy_to(
&mut self,
dst: &mut Self,
n: NonZeroU64
) -> Result<(), Error>
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
.
sourcepub async fn copy_all_to(&mut self, dst: &mut Self) -> Result<(), Error>
pub async fn copy_all_to(&mut self, dst: &mut Self) -> Result<(), Error>
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
sourceimpl AsyncBufRead for TokioCompatFile<'_>
impl AsyncBufRead for TokioCompatFile<'_>
sourceimpl AsyncRead for TokioCompatFile<'_>
impl AsyncRead for TokioCompatFile<'_>
sourceimpl AsyncSeek for TokioCompatFile<'_>
impl AsyncSeek for TokioCompatFile<'_>
sourceimpl AsyncWrite for TokioCompatFile<'_>
impl AsyncWrite for TokioCompatFile<'_>
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.
sourcefn poll_write(
self: Pin<&mut Self>,
_cx: &mut Context<'_>,
buf: &[u8]
) -> Poll<Result<usize>>
fn poll_write(
self: Pin<&mut Self>,
_cx: &mut Context<'_>,
buf: &[u8]
) -> Poll<Result<usize>>
buf
into the object. Read moresourcefn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
sourcefn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
sourcefn poll_write_vectored(
self: Pin<&mut Self>,
_cx: &mut Context<'_>,
bufs: &[IoSlice<'_>]
) -> Poll<Result<usize>>
fn poll_write_vectored(
self: Pin<&mut Self>,
_cx: &mut Context<'_>,
bufs: &[IoSlice<'_>]
) -> Poll<Result<usize>>
poll_write
, except that it writes from a slice of buffers. Read moresourcefn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
poll_write_vectored
implementation. Read moresourceimpl Clone for TokioCompatFile<'_>
impl Clone for TokioCompatFile<'_>
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.
sourceimpl<'s> Debug for TokioCompatFile<'s>
impl<'s> Debug for TokioCompatFile<'s>
sourceimpl<'s> Deref for TokioCompatFile<'s>
impl<'s> Deref for TokioCompatFile<'s>
sourceimpl DerefMut for TokioCompatFile<'_>
impl DerefMut for TokioCompatFile<'_>
sourceimpl<'s> From<File<'s>> for TokioCompatFile<'s>
impl<'s> From<File<'s>> for TokioCompatFile<'s>
sourceimpl<'s> From<TokioCompatFile<'s>> for File<'s>
impl<'s> From<TokioCompatFile<'s>> for File<'s>
sourcefn from(file: TokioCompatFile<'s>) -> Self
fn from(file: TokioCompatFile<'s>) -> Self
Auto Trait Implementations
impl<'s> !RefUnwindSafe for TokioCompatFile<'s>
impl<'s> Send for TokioCompatFile<'s>
impl<'s> Sync for TokioCompatFile<'s>
impl<'s> Unpin for TokioCompatFile<'s>
impl<'s> !UnwindSafe for TokioCompatFile<'s>
Blanket Implementations
sourceimpl<R> AsyncBufReadExt for Rwhere
R: AsyncBufRead + ?Sized,
impl<R> AsyncBufReadExt for Rwhere
R: AsyncBufRead + ?Sized,
sourcefn read_until(
&'a mut self,
byte: u8,
buf: &'a mut Vec<u8, Global>
) -> ReadUntil<'a, Self>where
Self: Unpin,
fn read_until(
&'a mut self,
byte: u8,
buf: &'a mut Vec<u8, Global>
) -> ReadUntil<'a, Self>where
Self: Unpin,
sourcefn read_line(&'a mut self, buf: &'a mut String) -> ReadLine<'a, Self>where
Self: Unpin,
fn read_line(&'a mut self, buf: &'a mut String) -> ReadLine<'a, Self>where
Self: Unpin,
sourcefn split(self, byte: u8) -> Split<Self>where
Self: Unpin,
fn split(self, byte: u8) -> Split<Self>where
Self: Unpin,
byte
. Read moresourcefn fill_buf(&mut self) -> FillBuf<'_, Self>where
Self: Unpin,
fn fill_buf(&mut self) -> FillBuf<'_, Self>where
Self: Unpin,
sourcefn lines(self) -> Lines<Self>
fn lines(self) -> Lines<Self>
BufRead::lines
. Read moresourceimpl<R> AsyncReadExt for Rwhere
R: AsyncRead + ?Sized,
impl<R> AsyncReadExt for Rwhere
R: AsyncRead + ?Sized,
sourcefn read(&'a mut self, buf: &'a mut [u8]) -> Read<'a, Self>where
Self: Unpin,
fn read(&'a mut self, buf: &'a mut [u8]) -> Read<'a, Self>where
Self: Unpin,
sourcefn read_buf<B>(&'a mut self, buf: &'a mut B) -> ReadBuf<'a, Self, B>where
Self: Unpin,
B: BufMut,
fn read_buf<B>(&'a mut self, buf: &'a mut B) -> ReadBuf<'a, Self, B>where
Self: Unpin,
B: BufMut,
sourcefn read_exact(&'a mut self, buf: &'a mut [u8]) -> ReadExact<'a, Self>where
Self: Unpin,
fn read_exact(&'a mut self, buf: &'a mut [u8]) -> ReadExact<'a, Self>where
Self: Unpin,
buf
. Read moresourcefn read_u8(&'a mut self) -> ReadU8<&'a mut Self>where
Self: Unpin,
fn read_u8(&'a mut self) -> ReadU8<&'a mut Self>where
Self: Unpin,
sourcefn read_i8(&'a mut self) -> ReadI8<&'a mut Self>where
Self: Unpin,
fn read_i8(&'a mut self) -> ReadI8<&'a mut Self>where
Self: Unpin,
sourcefn read_u16(&'a mut self) -> ReadU16<&'a mut Self>where
Self: Unpin,
fn read_u16(&'a mut self) -> ReadU16<&'a mut Self>where
Self: Unpin,
sourcefn read_i16(&'a mut self) -> ReadI16<&'a mut Self>where
Self: Unpin,
fn read_i16(&'a mut self) -> ReadI16<&'a mut Self>where
Self: Unpin,
sourcefn read_u32(&'a mut self) -> ReadU32<&'a mut Self>where
Self: Unpin,
fn read_u32(&'a mut self) -> ReadU32<&'a mut Self>where
Self: Unpin,
sourcefn read_i32(&'a mut self) -> ReadI32<&'a mut Self>where
Self: Unpin,
fn read_i32(&'a mut self) -> ReadI32<&'a mut Self>where
Self: Unpin,
sourcefn read_u64(&'a mut self) -> ReadU64<&'a mut Self>where
Self: Unpin,
fn read_u64(&'a mut self) -> ReadU64<&'a mut Self>where
Self: Unpin,
sourcefn read_i64(&'a mut self) -> ReadI64<&'a mut Self>where
Self: Unpin,
fn read_i64(&'a mut self) -> ReadI64<&'a mut Self>where
Self: Unpin,
sourcefn read_u128(&'a mut self) -> ReadU128<&'a mut Self>where
Self: Unpin,
fn read_u128(&'a mut self) -> ReadU128<&'a mut Self>where
Self: Unpin,
sourcefn read_i128(&'a mut self) -> ReadI128<&'a mut Self>where
Self: Unpin,
fn read_i128(&'a mut self) -> ReadI128<&'a mut Self>where
Self: Unpin,
sourcefn read_f32(&'a mut self) -> ReadF32<&'a mut Self>where
Self: Unpin,
fn read_f32(&'a mut self) -> ReadF32<&'a mut Self>where
Self: Unpin,
sourcefn read_f64(&'a mut self) -> ReadF64<&'a mut Self>where
Self: Unpin,
fn read_f64(&'a mut self) -> ReadF64<&'a mut Self>where
Self: Unpin,
sourcefn read_u16_le(&'a mut self) -> ReadU16Le<&'a mut Self>where
Self: Unpin,
fn read_u16_le(&'a mut self) -> ReadU16Le<&'a mut Self>where
Self: Unpin,
sourcefn read_i16_le(&'a mut self) -> ReadI16Le<&'a mut Self>where
Self: Unpin,
fn read_i16_le(&'a mut self) -> ReadI16Le<&'a mut Self>where
Self: Unpin,
sourcefn read_u32_le(&'a mut self) -> ReadU32Le<&'a mut Self>where
Self: Unpin,
fn read_u32_le(&'a mut self) -> ReadU32Le<&'a mut Self>where
Self: Unpin,
sourcefn read_i32_le(&'a mut self) -> ReadI32Le<&'a mut Self>where
Self: Unpin,
fn read_i32_le(&'a mut self) -> ReadI32Le<&'a mut Self>where
Self: Unpin,
sourcefn read_u64_le(&'a mut self) -> ReadU64Le<&'a mut Self>where
Self: Unpin,
fn read_u64_le(&'a mut self) -> ReadU64Le<&'a mut Self>where
Self: Unpin,
sourcefn read_i64_le(&'a mut self) -> ReadI64Le<&'a mut Self>where
Self: Unpin,
fn read_i64_le(&'a mut self) -> ReadI64Le<&'a mut Self>where
Self: Unpin,
sourcefn read_u128_le(&'a mut self) -> ReadU128Le<&'a mut Self>where
Self: Unpin,
fn read_u128_le(&'a mut self) -> ReadU128Le<&'a mut Self>where
Self: Unpin,
sourcefn read_i128_le(&'a mut self) -> ReadI128Le<&'a mut Self>where
Self: Unpin,
fn read_i128_le(&'a mut self) -> ReadI128Le<&'a mut Self>where
Self: Unpin,
sourcefn read_f32_le(&'a mut self) -> ReadF32Le<&'a mut Self>where
Self: Unpin,
fn read_f32_le(&'a mut self) -> ReadF32Le<&'a mut Self>where
Self: Unpin,
sourcefn read_f64_le(&'a mut self) -> ReadF64Le<&'a mut Self>where
Self: Unpin,
fn read_f64_le(&'a mut self) -> ReadF64Le<&'a mut Self>where
Self: Unpin,
sourcefn read_to_end(&'a mut self, buf: &'a mut Vec<u8, Global>) -> ReadToEnd<'a, Self>where
Self: Unpin,
fn read_to_end(&'a mut self, buf: &'a mut Vec<u8, Global>) -> ReadToEnd<'a, Self>where
Self: Unpin,
buf
. Read moresourcefn read_to_string(&'a mut self, dst: &'a mut String) -> ReadToString<'a, Self>where
Self: Unpin,
fn read_to_string(&'a mut self, dst: &'a mut String) -> ReadToString<'a, Self>where
Self: Unpin,
buf
. Read more