代码拉取完成,页面将自动刷新
This repository contains binding for lz4 compression library (https://github.com/Cyan4973/lz4).
LZ4 is a very fast lossless compression algorithm, providing compression speed at 400 MB/s per core, with near-linear scalability for multi-threaded applications. It also features an extremely fast decoder, with speed in multiple GB/s per core, typically reaching RAM speed limits on multi-core systems.
Put this in your Cargo.toml
:
[dependencies]
lz4 = "1.23.1"
Sample code for compression/decompression:
extern crate lz4;
use std::env;
use std::fs::File;
use std::io::{self, Result};
use std::path::{Path, PathBuf};
use lz4::{Decoder, EncoderBuilder};
fn main() {
println!("LZ4 version: {}", lz4::version());
for path in env::args().skip(1).map(PathBuf::from) {
if let Some("lz4") = path.extension().and_then(|e| e.to_str()) {
decompress(&path, &path.with_extension("")).unwrap();
} else {
compress(&path, &path.with_extension("lz4")).unwrap();
}
}
}
fn compress(source: &Path, destination: &Path) -> Result<()> {
println!("Compressing: {} -> {}", source.display(), destination.display());
let mut input_file = File::open(source)?;
let output_file = File::create(destination)?;
let mut encoder = EncoderBuilder::new()
.level(4)
.build(output_file)?;
io::copy(&mut input_file, &mut encoder)?;
let (_output, result) = encoder.finish();
result
}
fn decompress(source: &Path, destination: &Path) -> Result<()> {
println!("Decompressing: {} -> {}", source.display(), destination.display());
let input_file = File::open(source)?;
let mut decoder = Decoder::new(input_file)?;
let mut output_file = File::create(destination)?;
io::copy(&mut decoder, &mut output_file)?;
Ok(())
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。