mca
A simple but effective & fast writer / reader for Minecrafts Region Files (mca).
Read Example
use ;
use RegionReader;
let mut data = Vecnew;
open?.read_to_end?;
// Initialize the region
// This mostly just validates the header
let region = new?;
// Get a specific chunk based of it's chunk coordinates
let chunk = region.get_chunk?.unwrap;
// Decompress the chunk data
// This will most commonly be either ZLib or LZ4 compressed
let decompressed = chunk.decompress?;
// You can now bring your own NBT parser to parse the actual chunk data here
// I recommend either `simdnbt` or `fastnbt` for this.
Write Example
use ;
use RegionWriter;
let data = vec!; // some chunk data to write
// Initialize the region writer
let mut writer = new;
// Push a chunk to the writer
writer.push_chunk?;
// Write the writer to a buffer
let mut buf = vec!;
writer.write?;
// Write the buffer to a file
create?.write_all?;
Unsafe Feature
Toggling the unsafe feature will add unsafe get_unchecked calls to the code.
And this improves the performance by about 50% - 100% (were talking 2-3ns faster).
I think i have added enough manual bound checks to make this safe, but i can't guarantee it.
I've tested this on a few hundred MBs of region files and no issues at all.
Do note that enabling unsafe changes the function signature of RegionReader::get_timestamp to return a result
Reader Benchmarks
There is one benchmark included that compares against the only other
mca parser that i could find (mca-parser) and this crate is just like 1-3ns faster (with unsafe).
A very stupid, marginal error difference, but uhh this seems "faster".
you can run it with cargo bench or cargo bench --features unsafe for the unsafe version.