gunzip/gunzip.rs
1// Copyright 2023 The rust-ggstd authors.
2// SPDX-License-Identifier: 0BSD
3
4use std::fs::File;
5use std::io::BufReader;
6use std::io::Read;
7
8fn main() {
9 let path = "src/testdata/hello.txt.gz";
10 println!("{}", extract_with_ggstd(path).unwrap());
11 // println!("{}", extract_with_flate2(path).unwrap());
12}
13
14fn extract_with_ggstd(path: &str) -> std::io::Result<String> {
15 use ggstd::compress::gzip;
16
17 let mut f = BufReader::new(File::open(path)?);
18 let mut gzip = gzip::Reader::new(&mut f)?;
19 let mut content = String::new();
20 gzip.read_to_string(&mut content)?;
21 Ok(content)
22}
23
24// fn extract_with_flate2(path: &str) -> std::io::Result<String> {
25// use flate2::read::GzDecoder;
26
27// let f = BufReader::new(File::open(path)?);
28// let mut gzip = GzDecoder::new(f);
29// let mut content = String::new();
30// gzip.read_to_string(&mut content)?;
31// Ok(content)
32// }