Follow these steps:
-
Open the Cargo.toml file that was generated earlier for you.
-
Under [dependencies], add the following line:
flate2 = "0.2.20"
If you want, you can go to flate2's crates.io page (https://crates.io/crates/flate2) to check for the newest version and use that one instead.
-
In the bin folder, create a file called compression.rs.
-
Add the following code and run it with cargo run --bin compression:
1 extern crate flate2;
2
3 use std::io::{self, SeekFrom};
4 use std::io::prelude::*;
5
6 use flate2::{Compression, FlateReadExt};
7 use flate2::write::ZlibEncoder;
8 use flate2::read::ZlibDecoder;
9
10 use std::fs::{File, OpenOptions};
11 use std::io::{BufReader, BufWriter, Read};
12
13 fn main() {
14 let bytes = b"I have a dream that one day this nation will
rise up, \
15 and live out the true meaning of its creed";
16 println!("Original: {:?}", bytes.as_ref());
17 // Conpress...