Skip to content

Commit

Permalink
fix(delta): fix bug where we would exit before writing the last chunk
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdickinson committed Jan 22, 2019
1 parent eff4c6d commit 1442539
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/delta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,18 @@ fn read_varint(base_offset: usize, bytes: &[u8]) -> (usize, usize) {
impl std::io::Read for DeltaDecoderStream {
fn read(&mut self, mut buf: &mut [u8]) -> std::io::Result<usize> {
let mut written = 0;
while self.index < self.instructions.len() {
loop {
let (next_state, exhausted) = match &self.state {
DeltaDecoderState::Done => {
if self.written != self.output_size {
return Err(std::io::ErrorKind::WriteZero.into())
}
return Ok(0)
return Ok(written)
},

DeltaDecoderState::NextCommand => {
if self.index == self.instructions.len() {
if self.index >= self.instructions.len() {
self.written += written;
(DeltaDecoderState::Done, false)
} else {
let cmd = self.instructions[self.index];
Expand Down Expand Up @@ -150,7 +152,6 @@ impl std::io::Read for DeltaDecoderStream {
let extent = state.extent - wrote;
let offset = state.offset + wrote;
written += wrote;

if extent == 0 {
(DeltaDecoderState::NextCommand, false)
} else {
Expand Down

0 comments on commit 1442539

Please sign in to comment.