pub struct File { /* private fields */ }
Expand description
A reference to the remote file.
Cloning File
instance would return a new one that shares the same
underlying file handle as the existing File instance, while reads, writes
and seeks can be performed independently.
If you want a file that implements tokio::io::AsyncRead
and
tokio::io::AsyncWrite
, checkout TokioCompatFile
.
Implementations§
Source§impl File
impl File
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.
§Precondition
Require extension fsync
You can check it with Sftp::support_fsync
.
§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.
NOTE that the returned buffer might be smaller than n
.
Sourcepub async fn write(&mut self, buf: &[u8]) -> Result<usize, Error>
pub async fn write(&mut self, buf: &[u8]) -> Result<usize, Error>
Write data into the file.
NOTE that this API might only write part of the buf
.
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.
NOTE that this API might only write part of the buf
.
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.
NOTE that this API might only write part of the buf
.
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 write_all_vectorized(
&mut self,
bufs: &mut [IoSlice<'_>],
) -> Result<(), Error>
pub async fn write_all_vectorized( &mut self, bufs: &mut [IoSlice<'_>], ) -> Result<(), Error>
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.
You can check it with Sftp::support_copy
.
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.
You can check it with Sftp::support_copy
.
If the extension is not supported by the server, this function
would fail with Error::UnsupportedExtension
.
Sourcepub fn as_mut_file(&mut self) -> &mut File
pub fn as_mut_file(&mut self) -> &mut File
No-op to be compatible with TokioCompatFile::as_mut_file
Trait Implementations§
Source§impl AsyncSeek for File
impl AsyncSeek for File
Source§impl From<File> for TokioCompatFile
impl From<File> for TokioCompatFile
Source§impl From<TokioCompatFile> for File
impl From<TokioCompatFile> for File
Source§fn from(file: TokioCompatFile) -> Self
fn from(file: TokioCompatFile) -> Self
Auto Trait Implementations§
impl Freeze for File
impl !RefUnwindSafe for File
impl Send for File
impl Sync for File
impl Unpin for File
impl !UnwindSafe for File
Blanket Implementations§
Source§impl<S> AsyncSeekExt for S
impl<S> AsyncSeekExt for S
Source§fn seek(&mut self, pos: SeekFrom) -> Seek<'_, Self>where
Self: Unpin,
fn seek(&mut self, pos: SeekFrom) -> Seek<'_, Self>where
Self: Unpin,
Source§fn rewind(&mut self) -> Seek<'_, Self>where
Self: Unpin,
fn rewind(&mut self) -> Seek<'_, Self>where
Self: Unpin,
Source§fn stream_position(&mut self) -> Seek<'_, Self>where
Self: Unpin,
fn stream_position(&mut self) -> Seek<'_, Self>where
Self: Unpin,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)