Skip to content

Commit 299cd5b

Browse files
committed
Ensure reader buffer is flushed when extracting reader
After the decoder stream has yielded all of the uncompressed data, it is possible for the input stream to still not be fully consumed. This means if we extract the inner stream at this point, it will not be pointing to the end of the compressed data. From the [zstd documentation](https://facebook.github.io/zstd/zstd_manual.html#Chapter9) for `ZSTD_decompressStream`: > But if `output.pos == output.size`, there might be some data left within internal buffers. > In which case, call ZSTD_decompressStream() again to flush whatever remains in the buffer. This is only necessary if the caller wants the stream back, so at that point we can force an additional call to `ZSTD_decompressStream` by reading to a zero-length buffer.
1 parent 3ae7ad6 commit 299cd5b

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/stream/zio/reader.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,13 @@ impl<R, D> Reader<R, D> {
6363
}
6464

6565
/// Returns the inner reader.
66-
pub fn into_inner(self) -> R {
66+
pub fn into_inner(mut self) -> R
67+
where
68+
R: BufRead,
69+
D: Operation,
70+
{
71+
// Ensure the input buffers have been flushed by reading to a zero-length buffer.
72+
let _ = self.read(&mut [0; 0]);
6773
self.reader
6874
}
6975

0 commit comments

Comments
 (0)