Expand description
Rust library to create and read BagIt containers, with the Tokio async runtime.
§Learn about BagIt
Here are some resources to get started with BagIt containers:
- The Wikipedia article to get started with the format or to get a brief explanation
- The Library of Congress of the United States made a YouTube video (in 2009) to explain what is BagIt
- The spec of the container format: RFC 8493
For the integrity part of BagIt, any type implementing the Digest
trait from the digest
crate can be used to compute hashes.
§Load existing bag
use async_bagit::{Algorithm, BagIt, ChecksumAlgorithm};
// Specify the algorithm to use for checksums
type AlgorithmToUse = blake3::Hasher;
let algorithm = ChecksumAlgorithm::<AlgorithmToUse>::new(Algorithm::Custom("blake3"));
// Where is the bag on the filesystem?
let bag_directory = "/somewhere/where/the/bag/will/be/placed";
// Parse bagit metadata and verify checksums of payloads.
let bag = BagIt::read_existing(bag_directory, &algorithm).await.unwrap();
// This bag is complete and valid! You can get use files knowing their data is safe to use.
For more examples of what you can do with payload files once the bag has been validated, please see BagIt::payload_items()
.
§Create new bag and add files
use async_bagit::{Algorithm, BagIt, ChecksumAlgorithm};
// Specify the algorithm to use for checksums
type AlgorithmToUse = blake3::Hasher;
let algorithm = ChecksumAlgorithm::<AlgorithmToUse>::new(Algorithm::Custom("blake3"));
// Where the payloads and bag metadata will be placed
let bag_directory = "/somewhere/where/the/bag/will/be/placed";
// Create bag
let mut bag = BagIt::new_empty(bag_directory, &algorithm);
// Add files inside bag
for file in [
"handbag.jpg",
"important.pdf",
"hit_song.mp3",
"viral_video.mp4",
"dank_meme.png",
] {
bag.add_file::<AlgorithmToUse>(file).await.unwrap();
}
// Finalize bag, make it ready for distribution
bag.finalize::<AlgorithmToUse>().await.unwrap();
// The bag is ready: do whatever you want with it! Here are a few examples:
// - Copy its contents over the network
// - Burn it on a CD-ROM
// - Put it in an archive
Modules§
- error
- Possible errors when manipulating BagIt containers
Structs§
- BagIt
- BagIt container: A set of opaque files contained within the structure defined by RFC 8493 https://datatracker.ietf.org/doc/html/rfc8493
- Checksum
- Integrity checksum for a payload of a BagIt container.
- Checksum
Algorithm - Wrapper around the
Algorithm
enum that associates a specific hashing algorithm with a concrete type computing digests. - Payload
- File inside a bagit container
Enums§
- Algorithm
- List of common hashing algorithms