#zip-archive #tar #xz #deflate #gz #zlib #format

zippylib

ZippyLib是一个多功能的Rust库,旨在将文件压缩和解压缩功能集成到Rust项目中。

1个不稳定版本

0.1.0 2024年2月3日

#673 in 压缩

MIT许可证

30KB
573

ZippyLib

ZippyLib是一个多功能的Rust库,旨在将文件压缩和解压缩功能集成到Rust项目中,支持多种格式:ZIP、TAR、TAR.GZ、TAR.XZ、TAR.BZ2、BZ2、XZ、GZ、Deflate和Zlib。本指南提供了简单的API使用说明,以方便包含文件压缩和解压缩功能。

安装

通过将ZippyLib包含在你的Cargo.toml中将其添加到你的Rust项目中

[dependencies]
zippylib = "^0.1"

或使用

cargo add zippylib

使用

ZIP

use zippylib::create_zip_archive;
use std::path::PathBuf;

let files = vec![PathBuf::from("file1.txt"), PathBuf::from("file2.txt")];
let output_path = PathBuf::from("archive.zip");

create_zip_archive(&files, output_path).expect("ZIP archive creation failed");

TAR

use zippylib::create_tar_archive;
use std::path::PathBuf;

let files = vec![PathBuf::from("file1.txt"), PathBuf::from("file2.txt")];
let output_path = PathBuf::from("archive.tar");

create_tar_archive(&files, &output_path).expect("TAR archive creation failed");

TAR.GZ

use zippylib::create_tar_gz_archive;
use std::path::PathBuf;

let files = vec![PathBuf::from("file1.txt"), PathBuf::from("file2.txt")];
let output_path = PathBuf::from("archive.tar.gz");

create_tar_gz_archive(&files, &output_path).expect("TAR.GZ archive creation failed");

TAR.XZ

use zippylib::create_tar_xz_archive;
use std::path::PathBuf;

let files = vec![PathBuf::from("file1.txt"), PathBuf::from("file2.txt")];
let output_path = PathBuf::from("archive.tar.xz");

create_tar_xz_archive(&files, &output_path).expect("TAR.XZ archive creation failed");

TAR.BZ2

use zippylib::create_tar_bz2_archive;
use std::path::PathBuf;

let files = vec![PathBuf::from("file1.txt"), PathBuf::from("file2.txt")];
let output_path = PathBuf::from("archive.tar.bz2");

create_tar_bz2_archive(&files, &output_path).expect("TAR.BZ2 archive creation failed");

BZ2

use zippylib::create_file_bzip2;
use std::path::PathBuf;

let input_path = PathBuf::from("file1.txt");
let output_path = PathBuf::from("file1.bz2");

create_file_bzip2(&input_path, &output_path).expect("BZ2 file creation failed");

XZ

use zippylib::create_file_xz;
use std::path::PathBuf;

let input_path = PathBuf::from("file1.txt");
let output_path = PathBuf::from("file1.xz");

create_file_xz(&input_path, &output_path).expect("XZ file creation failed");

GZ

use zippylib::create_gzip_archive;
use std::path::PathBuf;

let file_path = PathBuf::from("file1.txt");
let output_path = PathBuf::from("file1.gz");

create_gzip_archive(&file_path, &output_path).expect("GZ archive creation failed");

Deflate

use zippylib::encode_file_deflate;
use std::path::PathBuf;

let file_to_compress = PathBuf::from("file1.txt");
let output_path = PathBuf::from("file1.deflate");

encode_file_deflate(&file_to_compress, &output_path).expect("Deflate encoding failed");

Zlib

use zippylib::encode_file_zlib;
use std::path::PathBuf;

let file_to_compress = PathBuf::from("file1.txt");
let output_path = PathBuf::from("file1.zlib");

encode_file_zlib(&file_to_compress, &output_path).expect("Zlib encoding failed");

错误处理

所有操作都设计为返回一个Result<(), ErrorType>,以实现强大的错误处理。定义了特定的错误类型,以便于详细报告和处理错误。

依赖

ZippyLib使用几个第三方crate来支持其功能

  • bzip2 (0.4.4)
  • flate2 (1.0.28)
  • tar (0.4.40)
  • tempfile (3.9.0)
  • xz2 (0.1.7)
  • zip (0.6.6)

这些依赖对于提供ZippyLib的全面压缩和归档功能至关重要。

许可证

ZippyLib遵循MIT许可证。完整的许可证文本可在存储库中的LICENSE文件中找到。

依赖

~9–19MB
~259K SLoC