| Crates.io | totebag |
| lib.rs | totebag |
| version | 0.8.16 |
| created_at | 2026-01-25 07:25:02.723171+00 |
| updated_at | 2026-01-25 11:06:32.801081+00 |
| description | An API for extracting/archiving files and directories in multiple formats. |
| homepage | |
| repository | https://github.com/tamada/totebag |
| max_upload_size | |
| id | 2068326 |
| size | 172,061 |
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.
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),
}
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),
}
| 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) |
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),
}