-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflate.rs
30 lines (26 loc) · 910 Bytes
/
flate.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Copyright 2023 The rust-ggstd authors.
// SPDX-License-Identifier: 0BSD
use ggstd::bytes;
use ggstd::compress::flate;
use ggstd::encoding::hex;
use std::io::Write;
fn main() {
let msg = "Hello World! Hello Rust! Hello World! Hello Rust!";
let mut buffer = bytes::Buffer::new();
let mut w = flate::Writer::new(&mut buffer, flate::BEST_COMPRESSION).unwrap();
w.write_all(msg.as_bytes()).unwrap();
w.close().unwrap();
let result_str = hex::encode_to_string(buffer.bytes());
println!(
"input string ({:02} bytes): {}",
msg.as_bytes().len(),
msg,
);
println!(
"deflated string ({:02} bytes): {}",
result_str.len() / 2,
result_str
);
}
// The output can be decompressed using Python:
// python3 -c 'import zlib; print(zlib.decompress(bytes.fromhex("f248cdc9c95708cf2fca4951548070824a8b4b606c4c0940000000ffff"), -15))'