Txtar archive format support with binary file encoding for Rust.
emx-txtar is a Rust implementation of the txtar archive format, originally from Go's toolchain. It provides a simple text-based archive format ideal for:
- Test fixtures
- Configuration files
- Embedded resources
- Data interchange
- ✅ Standard txtar format - Compatible with Go's txtar implementation
- ✅ Binary file support - Automatic base64 encoding for non-UTF8 files
- ✅ Content detection - Smart detection of binary vs text content
- ✅ Subdirectory support - Files with paths like
dir/file.txt - ✅ Edit operations - Support for snippet references and file edits
- ✅ Pure Rust - No external dependencies beyond
anyhowandbase64 - ✅ MIT License - Free to use in any project
Add to your Cargo.toml:
[dependencies]
emx-txtar = "0.1"Or use via Git:
[dependencies]
emx-txtar = { git = "https://github.com/coreseekdev/emx-txtar" }use emx_txtar::{Archive, File};
let mut archive = Archive::new();
archive.add_file(File::new("README.md", b"# Hello World\n"));
archive.add_file(File::new("config.json", br#"{"key": "value"}"#));
let encoder = emx_txtar::Encoder::new();
let txtar_content = encoder.encode(&archive)?;
println!("{}", txtar_content);use emx_txtar::Decoder;
let txtar_content = "-- README.md --
# Hello World
-- config.json --
{"key": "value"}
";
let decoder = Decoder::new();
let archive = decoder.decode(txtar_content.as_bytes())?;
for file in archive.files {
println!("{}: {} bytes", file.name, file.content.len());
}Binary files are automatically detected and encoded:
use emx_txtar::{Archive, File};
// Binary file - will be automatically base64 encoded
archive.add_file(File::with_encoding(
"image.jpg",
&[0xFF, 0xD8, 0xFF, 0xE0], // JPEG header
true // is_binary
));Output format:
-- image.jpg --
[.base64]
/9j/4AAQSkZJRg==
use emx_txtar::EditRef;
// Edit an existing file from another archive
let edit = EditRef::new(
"README.md",
"old content",
"new content",
Some("other-archive.txtar".to_string())
);
archive.add_edit(edit);-- filename1.txt --
Content of file 1
Can span multiple lines
-- filename2.txt --
Content of file 2
-- subdir/file3.txt --
Content in subdirectory
-- binary.dat --
[.base64]
SGVsbG8gV29ybGQ=
-- file.txt --
[edit:other.txt]
old content
-- new content --
MIT License - see LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
- emx-testspec - E2E testing framework using txtar
- Go txtar - Original Go implementation