use libarchive2::{ArchiveFormat, CallbackWriter, CompressionFormat, WriteArchive};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let buffer = Vec::new();
let callback = CallbackWriter::new(buffer);
let mut archive = WriteArchive::new()
.format(ArchiveFormat::TarPax)
.compression(CompressionFormat::Gzip)
.open_callback(callback)?;
archive.add_file("hello.txt", b"Hello, World!")?;
archive.add_file("test.txt", b"This is a test file.")?;
archive.add_directory("my_directory")?;
archive.finish()?;
println!("Archive written to memory buffer!");
println!("Note: In this redesigned version, the buffer is consumed by the callback.");
println!("For capturing output, consider writing to a file directly or using Cursor.");
Ok(())
}