File tree 4 files changed +8
-8
lines changed
4 files changed +8
-8
lines changed Original file line number Diff line number Diff line change 1
1
target
2
2
Cargo.lock
3
+ examples /* .gz
4
+ .idea
Original file line number Diff line number Diff line change @@ -6,14 +6,14 @@ use std::fs::File;
6
6
use std:: io;
7
7
use std:: io:: prelude:: * ;
8
8
9
- // Open file and debug print the contents compressed with gzip
9
+ // Compresses content of a text file into a gzip file
10
10
fn main ( ) {
11
11
sample_builder ( ) . unwrap ( ) ;
12
12
}
13
13
14
14
// GzBuilder opens a file and writes a sample string using Builder pattern
15
15
fn sample_builder ( ) -> Result < ( ) , io:: Error > {
16
- let f = File :: create ( "examples/hello_world.gz" ) ?;
16
+ let f = File :: create ( "examples/hello_world.txt. gz" ) ?;
17
17
let mut gz = GzBuilder :: new ( )
18
18
. filename ( "hello_world.txt" )
19
19
. comment ( "test file, please delete" )
Original file line number Diff line number Diff line change 1
1
extern crate flate2;
2
2
3
- use flate2:: bufread:: GzDecoder ;
4
3
use flate2:: write:: GzEncoder ;
5
- use flate2:: Compression ;
4
+ use flate2:: { bufread , Compression } ;
6
5
use std:: io;
7
6
use std:: io:: prelude:: * ;
8
7
@@ -17,7 +16,7 @@ fn main() {
17
16
// Uncompresses a Gz Encoded vector of bytes and returns a string or error
18
17
// Here &[u8] implements BufRead
19
18
fn decode_reader ( bytes : Vec < u8 > ) -> io:: Result < String > {
20
- let mut gz = GzDecoder :: new ( & bytes[ ..] ) ;
19
+ let mut gz = bufread :: GzDecoder :: new ( & bytes[ ..] ) ;
21
20
let mut s = String :: new ( ) ;
22
21
gz. read_to_string ( & mut s) ?;
23
22
Ok ( s)
Original file line number Diff line number Diff line change 1
1
extern crate flate2;
2
2
3
- use flate2:: read:: GzDecoder ;
4
3
use flate2:: write:: GzEncoder ;
5
- use flate2:: Compression ;
4
+ use flate2:: { read , Compression } ;
6
5
use std:: io;
7
6
use std:: io:: prelude:: * ;
8
7
@@ -17,7 +16,7 @@ fn main() {
17
16
// Uncompresses a Gz Encoded vector of bytes and returns a string or error
18
17
// Here &[u8] implements Read
19
18
fn decode_reader ( bytes : Vec < u8 > ) -> io:: Result < String > {
20
- let mut gz = GzDecoder :: new ( & bytes[ ..] ) ;
19
+ let mut gz = read :: GzDecoder :: new ( & bytes[ ..] ) ;
21
20
let mut s = String :: new ( ) ;
22
21
gz. read_to_string ( & mut s) ?;
23
22
Ok ( s)
You can’t perform that action at this time.
0 commit comments