Library and CLI for the Bedrock Archive (.brarchive) format, the bundling format Mojang uses
to pack the files inside Minecraft Bedrock Edition resource and behavior packs. Entries are
usually JSON, but newer packs also embed compiled binary data, and brarchive-rs handles both.
See FORMAT.md for the binary format specification.
// List entry names without reading any content
let names: Vec<String> = brarchive::list(&bytes)?;
// Deserialize into anything that implements FromIterator<(String, Vec<u8>)>.
// Content comes back as raw bytes, since an archive can hold binary entries.
let map: std::collections::BTreeMap<String, Vec<u8>> = brarchive::deserialize(&bytes)?;
let vec: Vec<(String, Vec<u8>)> = brarchive::deserialize(&bytes)?;
// Values that hold text can be turned back into a String when you need one
let text = String::from_utf8(map["entity.json"].clone())?;
// Serialize any iterable of key/value pairs. Keys are entry names; values are
// bytes, so &str, String, Vec<u8>, and &[u8] all work.
brarchive::serialize([("entity.json", r#"{"id":"zombie"}"#)])?;
brarchive::serialize(&btree_map)?;
// Serialize with options, for example deduplicating identical content
brarchive::serialize_with(&map, brarchive::SerializeOptions { dedup: true })?;Install the CLI from crates.io:
cargo install brarchive-cliPrebuilt binaries for Linux, macOS, and Windows are attached to every GitHub release as well.
There are three subcommands: encode, decode, and list. Each one takes
either a single .brarchive file or, with --recursive, a whole pack whose
archives live under __brarchive/.
Bundle a folder into one archive:
brarchive-cli encode path/to/dir output.brarchiveWalk a pack and mirror its directory tree into __brarchive/, writing one
archive per folder:
brarchive-cli encode path/to/pack --recursiveAdd --dedup to store identical file contents only once, and --delete-source
to remove the originals once the archive is written:
brarchive-cli encode path/to/dir output.brarchive --dedup --delete-sourceExtract a single archive into a folder:
brarchive-cli decode output.brarchive path/to/out/Extract every archive under a pack's __brarchive/ folder in one go:
brarchive-cli decode path/to/pack --recursiveMojang ships the JSON inside these archives minified, and by default the CLI
writes each entry back exactly as stored. Pass --pretty if you would rather
get readable JSON with a 2-space indent. Entries that are not JSON, such as the
compiled binary MCB files Bedrock now embeds, are always written untouched so
nothing gets corrupted:
brarchive-cli decode output.brarchive path/to/out/ --pretty--delete-source works here too and removes the archive after a successful
decode.
Print the entry names in an archive without extracting anything:
brarchive-cli list output.brarchiveOr list the contents of every archive in a pack:
brarchive-cli list path/to/pack --recursive