Skip to content

Commit 1a0daec

Browse files
authored
Merge pull request rust-lang#408 from marxin/document-read-after-end
docs: Document expected behavior when Read is done for ZLIB and DEFLATE decoders
2 parents d3bea90 + f37b1b0 commit 1a0daec

File tree

6 files changed

+30
-0
lines changed

6 files changed

+30
-0
lines changed

src/deflate/bufread.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ impl<W: BufRead + Write> Write for DeflateEncoder<W> {
127127
/// This structure implements a [`Read`] interface. When read from, it reads
128128
/// compressed data from the underlying [`BufRead`] and provides the uncompressed data.
129129
///
130+
/// After reading a single member of the DEFLATE data this reader will return
131+
/// Ok(0) even if there are more bytes available in the underlying reader.
132+
/// If you need the following bytes, call `into_inner()` after Ok(0) to
133+
/// recover the underlying reader.
134+
///
130135
/// [`Read`]: https://doc.rust-lang.org/std/io/trait.Read.html
131136
/// [`BufRead`]: https://doc.rust-lang.org/std/io/trait.BufRead.html
132137
///

src/deflate/read.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,12 @@ impl<W: Read + Write> Write for DeflateEncoder<W> {
123123
/// This structure implements a [`Read`] interface. When read from, it reads
124124
/// compressed data from the underlying [`Read`] and provides the uncompressed data.
125125
///
126+
/// After reading a single member of the DEFLATE data this reader will return
127+
/// Ok(0) even if there are more bytes available in the underlying reader.
128+
/// `DeflateDecoder` may have read additional bytes past the end of the DEFLATE data.
129+
/// If you need the following bytes, wrap the `Reader` in a `std::io::BufReader`
130+
/// and use `bufread::DeflateDecoder` instead.
131+
///
126132
/// [`Read`]: https://doc.rust-lang.org/std/io/trait.Read.html
127133
///
128134
/// # Examples

src/deflate/write.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ impl<W: Read + Write> Read for DeflateEncoder<W> {
172172
/// This structure implements a [`Write`] and will emit a stream of decompressed
173173
/// data when fed a stream of compressed data.
174174
///
175+
/// After decoding a single member of the DEFLATE data this writer will return the number of bytes up to
176+
/// to the end of the DEFLATE member and subsequent writes will return Ok(0) allowing the caller to
177+
/// handle any data following the DEFLATE member.
178+
///
175179
/// [`Write`]: https://doc.rust-lang.org/std/io/trait.Read.html
176180
///
177181
/// # Examples

src/zlib/bufread.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ impl<R: BufRead + Write> Write for ZlibEncoder<R> {
132132
/// This structure implements a [`Read`] interface. When read from, it reads
133133
/// compressed data from the underlying [`BufRead`] and provides the uncompressed data.
134134
///
135+
/// After reading a single member of the ZLIB data this reader will return
136+
/// Ok(0) even if there are more bytes available in the underlying reader.
137+
/// If you need the following bytes, call `into_inner()` after Ok(0) to
138+
/// recover the underlying reader.
139+
///
135140
/// [`Read`]: https://doc.rust-lang.org/std/io/trait.Read.html
136141
/// [`BufRead`]: https://doc.rust-lang.org/std/io/trait.BufRead.html
137142
///

src/zlib/read.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,12 @@ impl<W: Read + Write> Write for ZlibEncoder<W> {
129129
/// This structure implements a [`Read`] interface. When read from, it reads
130130
/// compressed data from the underlying [`Read`] and provides the uncompressed data.
131131
///
132+
/// After reading a single member of the ZLIB data this reader will return
133+
/// Ok(0) even if there are more bytes available in the underlying reader.
134+
/// `ZlibDecoder` may have read additional bytes past the end of the ZLIB data.
135+
/// If you need the following bytes, wrap the `Reader` in a `std::io::BufReader`
136+
/// and use `bufread::ZlibDecoder` instead.
137+
///
132138
/// [`Read`]: https://doc.rust-lang.org/std/io/trait.Read.html
133139
///
134140
/// # Examples

src/zlib/write.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,10 @@ impl<W: Read + Write> Read for ZlibEncoder<W> {
180180
/// This structure implements a [`Write`] and will emit a stream of decompressed
181181
/// data when fed a stream of compressed data.
182182
///
183+
/// After decoding a single member of the ZLIB data this writer will return the number of bytes up to
184+
/// to the end of the ZLIB member and subsequent writes will return Ok(0) allowing the caller to
185+
/// handle any data following the ZLIB member.
186+
///
183187
/// [`Write`]: https://doc.rust-lang.org/std/io/trait.Write.html
184188
///
185189
/// # Examples

0 commit comments

Comments
 (0)