Downloading chunks now does not copy the chunks, but writes them straight to disk. (Still reads into a buffer first though, but does not allocate on every chunk)

This commit is contained in:
Igor Katson 2021-06-28 16:37:15 +01:00
parent fab43a8d23
commit 14b62b45c5
7 changed files with 96 additions and 109 deletions

View file

@ -340,12 +340,15 @@ impl<'a> FileOps<'a> {
return Ok(());
}
pub fn write_chunk(
pub fn write_chunk<ByteBuf>(
&self,
who_sent: PeerHandle,
data: &Piece<ByteString>,
data: &Piece<ByteBuf>,
chunk_info: &ChunkInfo,
) -> anyhow::Result<()> {
) -> anyhow::Result<()>
where
ByteBuf: AsRef<[u8]>,
{
let mut buf = data.block.as_ref();
let mut absolute_offset = self.lengths.chunk_absolute_offset(&chunk_info);