Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐎 Add ChunkExt::write_chunk_in_async, SealedEntryExt::write_in_async for reduce copy #1322

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions lib/src/archive/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,7 @@ impl<W: AsyncWrite + Unpin> Archive<W> {
/// This API is unstable.
#[inline]
pub async fn add_entry_async(&mut self, entry: impl Entry) -> io::Result<usize> {
let mut bytes = Vec::new();
entry.write_in(&mut bytes)?;
self.inner.write_all(&bytes).await?;
Ok(bytes.len())
entry.write_in_async(&mut self.inner).await
}

/// Write an end marker to finalize the archive.
Expand Down
14 changes: 14 additions & 0 deletions lib/src/chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ pub(crate) trait ChunkExt: Chunk {
Ok(self.bytes_len())
}

#[cfg(feature = "unstable-async")]
#[inline]
async fn write_chunk_in_async<W: futures_io::AsyncWrite + std::marker::Unpin>(
&self,
writer: &mut W,
) -> io::Result<usize> {
use futures_util::AsyncWriteExt;
writer.write_all(&self.length().to_be_bytes()).await?;
writer.write_all(&self.ty().0).await?;
writer.write_all(self.data()).await?;
writer.write_all(&self.crc().to_be_bytes()).await?;
Ok(self.bytes_len())
}

/// Convert the provided `Chunk` instance into a `Vec<u8>`.
///
/// # Returns
Expand Down
Loading
Loading