Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor examlpe tweaks #282

Merged
merged 1 commit into from
Dec 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
target
Cargo.lock
examples/*.gz
.idea
4 changes: 2 additions & 2 deletions examples/gzbuilder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ use std::fs::File;
use std::io;
use std::io::prelude::*;

// Open file and debug print the contents compressed with gzip
// Compresses content of a text file into a gzip file
fn main() {
sample_builder().unwrap();
}

// GzBuilder opens a file and writes a sample string using Builder pattern
fn sample_builder() -> Result<(), io::Error> {
let f = File::create("examples/hello_world.gz")?;
let f = File::create("examples/hello_world.txt.gz")?;
let mut gz = GzBuilder::new()
.filename("hello_world.txt")
.comment("test file, please delete")
Expand Down
5 changes: 2 additions & 3 deletions examples/gzdecoder-bufread.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
extern crate flate2;

use flate2::bufread::GzDecoder;
use flate2::write::GzEncoder;
use flate2::Compression;
use flate2::{bufread, Compression};
use std::io;
use std::io::prelude::*;

Expand All @@ -17,7 +16,7 @@ fn main() {
// Uncompresses a Gz Encoded vector of bytes and returns a string or error
// Here &[u8] implements BufRead
fn decode_reader(bytes: Vec<u8>) -> io::Result<String> {
let mut gz = GzDecoder::new(&bytes[..]);
let mut gz = bufread::GzDecoder::new(&bytes[..]);
let mut s = String::new();
gz.read_to_string(&mut s)?;
Ok(s)
Expand Down
5 changes: 2 additions & 3 deletions examples/gzdecoder-read.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
extern crate flate2;

use flate2::read::GzDecoder;
use flate2::write::GzEncoder;
use flate2::Compression;
use flate2::{read, Compression};
use std::io;
use std::io::prelude::*;

Expand All @@ -17,7 +16,7 @@ fn main() {
// Uncompresses a Gz Encoded vector of bytes and returns a string or error
// Here &[u8] implements Read
fn decode_reader(bytes: Vec<u8>) -> io::Result<String> {
let mut gz = GzDecoder::new(&bytes[..]);
let mut gz = read::GzDecoder::new(&bytes[..]);
let mut s = String::new();
gz.read_to_string(&mut s)?;
Ok(s)
Expand Down