Skip to content

Commit

Permalink
Fix some examples to use read_to_end
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcrichton committed May 24, 2021
1 parent c378248 commit 19708cf
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions examples/deflateencoder-read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ fn main() {

// Return a vector containing the Defalte compressed version of hello world
fn deflateencoder_read_hello_world() -> io::Result<Vec<u8>> {
let mut ret_vec = [0; 100];
let mut result = 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())
deflater.read_to_end(&mut result)?;
Ok(result)
}
6 changes: 3 additions & 3 deletions examples/gzencoder-read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ fn main() {

// Return a vector containing the GZ compressed version of hello world
fn gzencoder_read_hello_world() -> io::Result<Vec<u8>> {
let mut ret_vec = [0; 100];
let mut result = Vec::new();
let c = b"hello world";
let mut z = GzEncoder::new(&c[..], Compression::fast());
let count = z.read(&mut ret_vec)?;
Ok(ret_vec[0..count].to_vec())
z.read_to_end(&mut ret_vec)?;
Ok(result)
}
6 changes: 3 additions & 3 deletions examples/zlibencoder-read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn main() {
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 result = Vec::new();
z.read_to_end(&mut result)?;
Ok(result)
}

0 comments on commit 19708cf

Please sign in to comment.