Skip to content

Commit

Permalink
fix: store chunk in any case
Browse files Browse the repository at this point in the history
  • Loading branch information
rklaehn committed Oct 25, 2022
1 parent 4f36f1a commit 330e7b6
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions iroh-resolver/src/unixfs_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -649,30 +649,28 @@ fn add_blocks_to_store_chunked<S: Store>(
let mut chunk = Vec::new();
let mut chunk_size = 0u64;
const MAX_CHUNK_SIZE: u64 = 1024 * 1024 * 16;
let t = stream! {
stream! {
while let Some(block) = blocks.next().await {
let block = block?;
let block_size = block.data().len() as u64;
let cid = *block.cid();
let raw_data_size = block.raw_data_size();
tracing::info!("adding chunk of {} bytes", chunk_size);
if chunk_size + block_size > MAX_CHUNK_SIZE {
tracing::info!("adding chunk of {} bytes", chunk_size);
store.put_many(chunk.clone()).await?;
chunk.clear();
chunk_size = 0;
} else {
chunk.push(block);
chunk_size += block_size;
}
chunk.push(block);
chunk_size += block_size;
yield Ok(AddEvent::ProgressDelta {
cid,
size: raw_data_size,
});
}
// make sure to also send the last chunk!
store.put_many(chunk).await?;
};
t
}
}

fn _add_blocks_to_store_single<S: Store>(
Expand Down

0 comments on commit 330e7b6

Please sign in to comment.