#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

#618 in Compression

Download history 25/week @ 2024-01-08 46/week @ 2024-01-15 20/week @ 2024-01-22 19/week @ 2024-01-29 31/week @ 2024-02-05 53/week @ 2024-02-19 21/week @ 2024-02-26 15/week @ 2024-03-04 34/week @ 2024-03-11 41/week @ 2024-03-18 12/week @ 2024-03-25 57/week @ 2024-04-01 73/week @ 2024-04-08 49/week @ 2024-04-15 11/week @ 2024-04-22

191 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

~8–17MB
~223K SLoC