Skip to content

Commit

Permalink
Fixed empty Vec in BufferedChunk
Browse files Browse the repository at this point in the history
  • Loading branch information
ph0llux committed May 27, 2024
1 parent 5b7f47c commit c44afb2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
15 changes: 12 additions & 3 deletions src/lib/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
pub mod zffwriter;
/// provides [ZffReader](crate::io::zffreader::ZffReader) and some helper functions to read zff containers.
pub mod zffreader;
/// TODO
/// provides [ZffStreamer] which implements the [Read](std::io::Read) trait to obtain a Read-Stream for a zff container.
pub mod zffstreamer;

// - STD
Expand Down Expand Up @@ -83,6 +83,16 @@ pub(crate) struct BufferedChunk {
pub error_flag: bool,
}

impl BufferedChunk {
pub fn with_chunksize(chunk_size: usize) -> BufferedChunk {
Self {
buffer: vec![0; chunk_size],
bytes_read: 0,
error_flag: false,
}
}
}

// returns the buffer with the read bytes and the number of bytes which was read.
pub(crate) fn buffer_chunk<R>(
input: &mut R,
Expand All @@ -91,7 +101,7 @@ pub(crate) fn buffer_chunk<R>(
where
R: Read,
{
let mut buffered_chunk = BufferedChunk::default();
let mut buffered_chunk = BufferedChunk::with_chunksize(chunk_size);
let mut interrupt_retries = 0;

while (buffered_chunk.bytes_read as usize) < chunk_size {
Expand Down Expand Up @@ -124,7 +134,6 @@ where
}
buffered_chunk.bytes_read += r as u64;
}

if buffered_chunk.bytes_read as usize != chunk_size {
buffered_chunk.buffer = buffered_chunk.buffer[..buffered_chunk.bytes_read as usize].to_vec();
}
Expand Down
4 changes: 0 additions & 4 deletions src/lib/io/zffwriter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,6 @@ impl<R: Read> ZffWriter<R> {
};
}
},
ZffErrorKind::InterruptedInputStream => {
//todo: should be handled in any way...
break;
},
_ => return Err(e),
},
};
Expand Down

0 comments on commit c44afb2

Please sign in to comment.