- 添加所需的库到
Cargo.toml
文件中:
- 直接上代码, 都在酒里了.
| use std::fs::File; |
| use std::io::{Read, Write}; |
| use std::process::exit; |
| use std::path::{Path, PathBuf}; |
| use zip::ZipArchive; |
| |
| fn main() { |
| |
| let zip_path = Path::new("xxx.gz"); |
| println!("{}", zip_path.display()); |
| if !zip_path.exists() { |
| println!("===指定文件不存在!==="); |
| exit(1); |
| } |
| let mut output_path = PathBuf::new(); |
| output_path.push("./output"); |
| |
| |
| |
| let zip_data = File::open(zip_path).expect("===读取压缩文件失败!!==="); |
| let mut archive = ZipArchive::new(zip_data).unwrap(); |
| |
| |
| |
| for index in 0..archive.len() { |
| let mut file_data: zip::read::ZipFile<'_> = archive.by_index(index).expect("===读取压缩文件失败!!==="); |
| |
| let out_file_name = match file_data.enclosed_name() { |
| Some(path) => path.to_owned(), |
| None => continue, |
| }; |
| |
| let out_file_name: PathBuf = PathBuf::from(&output_path).join(out_file_name); |
| println!("解压文件==>:{}", out_file_name.display()); |
| |
| let mut outfile = File::create(&out_file_name).expect("===创建数据文件失败!!==="); |
| let mut buffer: Vec<u8> = Vec::new(); |
| |
| file_data.read_to_end(&mut buffer).unwrap(); |
| outfile.write_all(&buffer).expect("===写入文件失败!!==="); |
| } |
| } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
· 【杂谈】分布式事务——高大上的无用知识?