forked from rust-lang/flate2-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request rust-lang#115 from AndyGauge/examples
crate level examples, including FlateReadExt
- Loading branch information
Showing
6 changed files
with
66 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
extern crate flate2; | ||
|
||
use flate2::{FlateReadExt, Compression}; | ||
use std::io::prelude::*; | ||
use std::io; | ||
use std::fs::File; | ||
|
||
fn main() { | ||
println!("{}", run().unwrap()); | ||
} | ||
|
||
fn run() -> io::Result<String> { | ||
let f = File::open("examples/hello_world.txt")?; | ||
|
||
//gz_encode method comes from FlateReadExt and applies to a std::fs::File | ||
let data = f.gz_encode(Compression::Default); | ||
let mut buffer = String::new(); | ||
|
||
//gz_decode method comes from FlateReadExt and applies to a &[u8] | ||
&data.gz_decode()?.read_to_string(&mut buffer)?; | ||
Ok(buffer) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters