Skip to content

coreseekdev/emx-txtar

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

emx-txtar

Txtar archive format support with binary file encoding for Rust.

Overview

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

Features

  • 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 anyhow and base64
  • MIT License - Free to use in any project

Installation

Add to your Cargo.toml:

[dependencies]
emx-txtar = "0.1"

Or use via Git:

[dependencies]
emx-txtar = { git = "https://github.com/coreseekdev/emx-txtar" }

Usage

Creating an Archive

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);

Parsing an Archive

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 File Support

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==

File Edit Operations

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);

Format Specification

Basic Structure

-- filename1.txt --
Content of file 1
Can span multiple lines

-- filename2.txt --
Content of file 2

-- subdir/file3.txt --
Content in subdirectory

Binary Files

-- binary.dat --
[.base64]
SGVsbG8gV29ybGQ=

Edit References

-- file.txt --
[edit:other.txt]
old content
-- new content --

Documentation

License

MIT License - see LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Related Projects

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •