totebag

Crates.iototebag
lib.rstotebag
version0.8.16
created_at2026-01-25 07:25:02.723171+00
updated_at2026-01-25 11:06:32.801081+00
descriptionAn API for extracting/archiving files and directories in multiple formats.
homepage
repositoryhttps://github.com/tamada/totebag
max_upload_size
id2068326
size172,061
Haruaki Tamada (tamada)

documentation

README

API of totebag crate

:speaking_head: Overview

This is the README for the totebag crate, which provides the API of the totebag tool for extracting/archiving files and directories in multiple formats.

The totebag crate provides a unified API for handling various archive formats, making it easy for developers to integrate archiving and extraction functionality into their Rust applications. It abstracts the differences between various archive formats, providing a consistent interface for working with archives.

Supported archive formats

:walking: How to use

:green_heart: Archiving files and directories

use std::path::PathBuf;

let config = totebag::ArchiveConfig::builder()
    .dest("results/test.zip")         // destination file.
    .rebase_dir(PathBuf::from("new")) // rebased directory in the archive file.
    .overwrite(true)                  // set overwrite flag of the destination file.
    .build();
let targets: Vec<PathBuf> = vec!["src", "Cargo.toml"].iter() // files to be archived.
    .map(|s| PathBuf::from(s)).collect::<Vec<_>>();   
match totebag::archive(&targets, &config) {
    Ok(_) => println!("archiving is done"),
    Err(e) => eprintln!("error: {:?}", e),
}

:yellow_heart: Extracting the archive file

use std::path::PathBuf;

let config = totebag::ExtractConfig::builder()
    .dest("results") // set the destination directory.
    .build();
match totebag::extract("extracting_archive_file.zip", &config) {
    Ok(r) => println!("{:?}", r),
    Err(e) => println!("error: {:?}", e),
}
Compression level
Level
Ar N/A
Cab 0: None, otherwise: MsZIP; see CompressionType.
Cpio 0-3: Odc, 4-6: Newc, 7: Crc, 8: Bin(LittleEndian), 9: Bin(BigEndian); see kpea::Format.
Gzip See Compression.
Bzip2 See Compression.
Xz See XzEncoder.
Zstd Map 1-22 to 0-9 See Encoder.
Zip 0: No compression, 1-3: Deflate (10, 24, 264), 4-6: Bzip2 (1, 6, 9), 7-9: Zstd (-7, 3, 22); see FileOptions.
7z 0-4: LZMA, 5-9: LZMA64 (SevenZMethod)

:blue_heart: List entries in an archive file

The list function returns a string-formatted list of entries in the archive file.

use std::path::PathBuf;

let file = PathBuf::from("listing_archive_file.zip");
let config = totebag::ListConfig::new(totebag::OutputFormat::Default);
match totebag::list(file, &config) {
    Ok(formatted_list) => println!("{:?}", formatted_list),
    Err(e) => println!("error: {:?}", e),
}

The entries function returns a vector of Entry objects that are reflected in the archive file.

use std::path::PathBuf;

let file = PathBuf::from("listing_archive_file.zip");
match totebag::entries(file) {
    Ok(entries) => println!("{:?}", entries),
    Err(e) => println!("error: {:?}", e),
}
Commit count: 302

cargo fmt