diff --git a/examples/deflateencoder-read.rs b/examples/deflateencoder-read.rs index d22777f51..47e478453 100644 --- a/examples/deflateencoder-read.rs +++ b/examples/deflateencoder-read.rs @@ -12,9 +12,9 @@ fn main() { // Return a vector containing the Defalte compressed version of hello world fn deflateencoder_read_hello_world() -> io::Result> { - 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) } diff --git a/examples/gzencoder-read.rs b/examples/gzencoder-read.rs index a9657aca1..3191356db 100644 --- a/examples/gzencoder-read.rs +++ b/examples/gzencoder-read.rs @@ -12,9 +12,9 @@ fn main() { // Return a vector containing the GZ compressed version of hello world fn gzencoder_read_hello_world() -> io::Result> { - 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) } diff --git a/examples/zlibencoder-read.rs b/examples/zlibencoder-read.rs index b0ae50a97..779eb1d31 100644 --- a/examples/zlibencoder-read.rs +++ b/examples/zlibencoder-read.rs @@ -15,7 +15,7 @@ fn main() { fn open_hello_world() -> std::io::Result> { 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) }