Skip to content

Commit

Permalink
Rust: use std::io::Write::write_all to not have potential data loss.
Browse files Browse the repository at this point in the history
Closes #5530
  • Loading branch information
DavidSouther committed Nov 2, 2023
1 parent 6fffcc8 commit 2f98b73
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl<'a> ZipUpload<'a> {

let mut byte_count = 0_usize;
while let Some(bytes) = object.body.try_next().await? {
let bytes = self.zip.write(&bytes)?;
let bytes = self.zip.write_all(&bytes)?;
byte_count += bytes;
tracing::trace!("Intermediate read of {bytes} (total {byte_count})");
}
Expand Down
7 changes: 4 additions & 3 deletions rust_dev_preview/examples/s3/src/bin/get-object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ async fn get_object(client: Client, opt: Opt) -> Result<usize, anyhow::Error> {

let mut byte_count = 0_usize;
while let Some(bytes) = object.body.try_next().await? {
let bytes = file.write(&bytes)?;
byte_count += bytes;
trace!("Intermediate write of {bytes}");
let bytes_len = bytes.len();
file.write_all(&bytes)?;
trace!("Intermediate write of {bytes_len}");
byte_count += bytes_len;
}

Ok(byte_count)
Expand Down

0 comments on commit 2f98b73

Please sign in to comment.