Skip to content

Commit

Permalink
Fix Read encoder examples
Browse files Browse the repository at this point in the history
The examples for the Read encoders previously used the read method to
read data. However, as pointed out in issue 158, this may only read
part of the data. Instead the read_to_end method should be used.

Fixes: rust-lang#355
  • Loading branch information
markgoddard committed Jun 27, 2023
1 parent f537522 commit 3281693
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/deflate/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ use crate::bufreader::BufReader;
/// #
/// // Return a vector containing the Deflate compressed version of hello world
/// fn deflateencoder_read_hello_world() -> io::Result<Vec<u8>> {
/// let mut ret_vec = [0;100];
/// let mut ret_vec = Vec::new();
/// let c = b"hello world";
/// let mut deflater = DeflateEncoder::new(&c[..], Compression::fast());
/// let count = deflater.read(&mut ret_vec)?;
/// Ok(ret_vec[0..count].to_vec())
/// let count = deflater.read_to_end(&mut ret_vec)?;
/// Ok(ret_vec)
/// }
/// ```
#[derive(Debug)]
Expand Down
6 changes: 3 additions & 3 deletions src/gz/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ use crate::Compression;
/// // Return a vector containing the GZ compressed version of hello world
///
/// fn gzencode_hello_world() -> io::Result<Vec<u8>> {
/// let mut ret_vec = [0;100];
/// let mut ret_vec = Vec::new();
/// let bytestring = b"hello world";
/// let mut gz = GzEncoder::new(&bytestring[..], Compression::fast());
/// let count = gz.read(&mut ret_vec)?;
/// Ok(ret_vec[0..count].to_vec())
/// let count = gz.read_to_end(&mut ret_vec)?;
/// Ok(ret_vec)
/// }
/// ```
#[derive(Debug)]
Expand Down
6 changes: 3 additions & 3 deletions src/zlib/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ use crate::bufreader::BufReader;
/// # fn open_hello_world() -> std::io::Result<Vec<u8>> {
/// let f = File::open("examples/hello_world.txt")?;
/// let mut z = ZlibEncoder::new(f, Compression::fast());
/// let mut buffer = [0;50];
/// let byte_count = z.read(&mut buffer)?;
/// # Ok(buffer[0..byte_count].to_vec())
/// let mut buffer = Vec::new();
/// let byte_count = z.read_to_end(&mut buffer)?;
/// # Ok(buffer)
/// # }
/// ```
#[derive(Debug)]
Expand Down

0 comments on commit 3281693

Please sign in to comment.