Skip to content

Commit

Permalink
Add sanity check to make sure we encode everything before writing
Browse files Browse the repository at this point in the history
  • Loading branch information
BuildKite committed Jan 3, 2025
1 parent 4ab2737 commit a9041e4
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion rs/compression/src/noc/noc.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fs::File;
use std::io::{BufWriter, Write};

use anyhow::Result;
use anyhow::{anyhow, Result};
use utils::io::wrap_write;
use utils::mem::get_ith_val_from_raw_ptr;

Expand Down Expand Up @@ -42,6 +42,13 @@ impl IntSeqEncoder for PlainEncoder {
total_bytes_written += wrap_write(writer, &val.to_le_bytes())?;
}

if total_bytes_written != self.len() {
return Err(anyhow!(
"Expected to write {} bytes but wrote {} bytes",
self.len(),
total_bytes_written
));
}
writer.flush()?;

Ok(total_bytes_written)
Expand Down

0 comments on commit a9041e4

Please sign in to comment.