feat: add __compress/zstd-demo
This commit is contained in:
@@ -8,6 +8,8 @@ Project or files:
|
||||
├── README_2.md
|
||||
├── __bin
|
||||
│ └── goblin
|
||||
├── __compress
|
||||
│ └── zstd-demo
|
||||
├── __concurrent
|
||||
│ ├── arc-swap
|
||||
│ ├── async_study
|
||||
@@ -267,6 +269,6 @@ Project or files:
|
||||
├── vec.rs
|
||||
└── while.rs
|
||||
|
||||
236 directories, 39 files
|
||||
238 directories, 39 files
|
||||
```
|
||||
|
||||
|
||||
70
__compress/zstd-demo/Cargo.lock
generated
Normal file
70
__compress/zstd-demo/Cargo.lock
generated
Normal file
@@ -0,0 +1,70 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.0.79"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f"
|
||||
dependencies = [
|
||||
"jobserver",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "jobserver"
|
||||
version = "0.1.25"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "068b1ee6743e4d11fb9c6a1e6064b3693a1b600e7f5f5988047d98b3dc9fb90b"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.139"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79"
|
||||
|
||||
[[package]]
|
||||
name = "pkg-config"
|
||||
version = "0.3.26"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160"
|
||||
|
||||
[[package]]
|
||||
name = "zstd"
|
||||
version = "0.12.3+zstd.1.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "76eea132fb024e0e13fd9c2f5d5d595d8a967aa72382ac2f9d39fcc95afd0806"
|
||||
dependencies = [
|
||||
"zstd-safe",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zstd-demo"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"zstd",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zstd-safe"
|
||||
version = "6.0.4+zstd.1.5.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7afb4b54b8910cf5447638cb54bf4e8a65cbedd783af98b98c62ffe91f185543"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"zstd-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zstd-sys"
|
||||
version = "2.0.7+zstd.1.5.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "94509c3ba2fe55294d752b79842c530ccfab760192521df74a081a78d2b3c7f5"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"libc",
|
||||
"pkg-config",
|
||||
]
|
||||
9
__compress/zstd-demo/Cargo.toml
Normal file
9
__compress/zstd-demo/Cargo.toml
Normal file
@@ -0,0 +1,9 @@
|
||||
[package]
|
||||
name = "zstd-demo"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
zstd = "0.12.3"
|
||||
29
__compress/zstd-demo/src/main.rs
Normal file
29
__compress/zstd-demo/src/main.rs
Normal file
@@ -0,0 +1,29 @@
|
||||
use std::collections::VecDeque;
|
||||
use std::io;
|
||||
use zstd::Encoder;
|
||||
|
||||
fn main() {
|
||||
let inputs = "hello world".repeat(100);
|
||||
let outputs = compress_manually(1, inputs.as_bytes().to_vec().into());
|
||||
|
||||
println!("Inputs len: {}", inputs.len());
|
||||
println!("Outputs len: {}", outputs.len());
|
||||
println!("{:x?}", outputs);
|
||||
}
|
||||
|
||||
// fn compress(level: i32) {
|
||||
// zstd::stream::copy_encode(io::stdin(), io::stdout(), level).unwrap();
|
||||
// }
|
||||
// fn decompress() {
|
||||
// zstd::stream::copy_decode(io::stdin(), io::stdout()).unwrap();
|
||||
// }
|
||||
|
||||
// This function does the same thing, directly using an `Encoder`:
|
||||
fn compress_manually(level: i32, mut input: VecDeque<u8>) -> Vec<u8> {
|
||||
let mut output: Vec<u8> = vec![];
|
||||
let mut encoder = Encoder::new(&mut output, level).unwrap();
|
||||
io::copy(&mut input, &mut encoder).unwrap();
|
||||
encoder.finish().unwrap();
|
||||
output
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user