#directory #archive #archive-format #zip #root-directory #xz

zip_archive

Library that archive a directory with a specific compression format

5 releases (stable)

1.2.2 Apr 23, 2022
1.0.0 Apr 10, 2022
0.1.1 Apr 1, 2022

#607 in Compression

Download history 52/week @ 2023-12-15 45/week @ 2023-12-22 28/week @ 2023-12-29 25/week @ 2024-01-05 46/week @ 2024-01-12 25/week @ 2024-01-19 16/week @ 2024-01-26 29/week @ 2024-02-02 9/week @ 2024-02-09 47/week @ 2024-02-16 19/week @ 2024-02-23 17/week @ 2024-03-01 29/week @ 2024-03-08 36/week @ 2024-03-15 24/week @ 2024-03-22 75/week @ 2024-03-29

166 downloads per month

MIT license

45KB
1K SLoC

Zip archive

zip_archive is a library that archive a directory with a specific compression format. Supports multi-threading.

Requirements for 7z format

To use 7z archiving format, you need to install 7z or get the executable depending on the operating system.

Windows 10

  1. Install 7-Zip.
  2. Find 7z.exe file in installed 7z folder and add it to path. Or place 7z.exe in project root folder.

macOS

  1. Download 7-Zip console version executable for macOS.
  2. Place 7zz executable to home directory.

Examples

For more information and examples, see document page.


lib.rs:

Zip archive

zip_archive is a library that archive a directory with a specific compression format. Supports multi-threading.

Supported Formats

Formats description
xz Using [xz2] crate.
7z See Requirements section.
[zip] Using [zip] crate.

Examples

  • Compress root directory with 4 threads.
use std::path::PathBuf;
use zip_archive::Archiver;

let origin = PathBuf::from("./origin");
let dest = PathBuf::from("./dest");
let thread_count = 4;

let mut archiver = Archiver::new();
archiver.push(origin);
archiver.set_destination(dest);
archiver.set_thread_count(thread_count);

match archiver.archive(){
    Ok(_) => (),
    Err(e) => println!("Cannot archive the directory! {}", e),
};
  • Compress each directory using the container's iterator.
use std::path::PathBuf;
use zip_archive::Archiver;

let origin = PathBuf::from("./origin");
let dest = PathBuf::from("./dest");

let mut archiver = Archiver::new();
archiver.push_from_iter(vec!["./origin/dir1", "./origin/dir2", "./origin/dir3"].into_iter());
archiver.set_destination(dest);
match archiver.archive(){
    Ok(_) => (),
    Err(e) => println!("Cannot archive the directory! {}", e),
};
  • Compress directory with .xz format.
use std::path::PathBuf;
use zip_archive::Format;
use zip_archive::{Archiver, get_dir_list_with_depth};

let origin = PathBuf::from("./origin");  // Change to the wanted directory.
let dest = PathBuf::from("./dest");

let mut archiver = Archiver::new();
archiver.push(origin);
archiver.set_destination(dest);
archiver.set_format(Format::Xz); // == `archiver.set_format_str("xz");`
match archiver.archive(){
    Ok(_) => (),
    Err(e) => println!("Cannot archive the directory! {}", e),
};

Requirements for 7z format

To use 7z archiving format, you need to install 7z or get the executable depending on the operating system.

Windows 10

  1. Install 7-Zip.
  2. Find 7z.exe file in installed program folder and add it to path. Or place it in project root folder.

macOS

  1. Download 7-Zip console version executable for macOS.
  2. Place 7zz executable to home directory.

Dependencies

~7–18MB
~222K SLoC