Skip to main content

RegionWriter

Struct RegionWriter 

Source
pub struct RegionWriter<'d, C: CustomCompression = ()> { /* private fields */ }
Expand description

Used to write raw chunk data to and then format it into the region file format (.mca)

§Example

let mut writer = RegionWriter::new();

writer.set_chunk(0, 0, Vec::new(), Compression::ZLib)?;

let mut region_file: Vec<u8> = Vec::new();
writer.write(&mut region_file)?;

Implementations§

Source§

impl RegionWriter<'_, ()>

Source

pub fn new() -> Self

Creates a new RegionWriter with no custom compression specified.

Source

pub fn sector_size(compressed_len: usize, compression: &Compression) -> usize

Calculates how many 4096 byte sectors a complete chunk data view is.

data length + compression byte + ?custom compression id + compressed data / 4096

Source

pub fn chunk_view_len(compressed_len: usize, compression: &Compression) -> usize

Calculates how many bytes a complete chunk data view is.

data length + compression byte + ?custom compression id + compressed data

Source

pub fn write_packed<W: Write>( writer: &mut W, chunks: Vec<PackedChunk<'_>>, ) -> Result<usize, McaError>

Writes a list of PackedChunks into the specified writer.
Used internally by RegionWriter::write after it has compressed and gathered metadata per chunk.

This may be useful if you need more control, like skipping the libraries compression handling.
Look more at PackedChunk for info and important things to know

§Example
let chunks = vec![PackedChunk::default(), PackedChunk::default()];

let mut buf = Vec::new();
RegionWriter::<()>::write_packed(&mut buf, chunks)?;
Source§

impl<'c, C: CustomCompression> RegionWriter<'c, C>

Source

pub fn new_with_compression(custom_compression: C) -> Self

Creates a new RegionWriter with a specified custom compression to use when writing chunks.

Source

pub fn chunk( &self, x: u8, z: u8, ) -> Result<&Option<WritableChunk<'_>>, McaError>

Returns a reference to a chunk entry within the RegionWriter

§Error

Fails if the specified chunk coordinates are outside of the region

Source

pub fn chunk_mut( &mut self, x: u8, z: u8, ) -> Result<&mut Option<WritableChunk<'c>>, McaError>

Returns a mutable reference to a chunk entry within the RegionWriter

§Error

Fails if the specified chunk coordinates are outside of the region

Source

pub fn set_chunk( &mut self, x: u8, z: u8, data: Vec<u8>, compression: Compression, ) -> Result<(), McaError>

Set the data of a specific chunk along side it’s compression.

Can be called multiple times on the same coordinates, but will overwrite previous data.
Sets the modified timestamp to when this function was called.

§Example
let mut region = RegionWriter::new();

region.set_chunk(5, 1, Vec::new(), Compression::default())?;
Source

pub fn clear_chunk(&mut self, x: u8, z: u8) -> Result<(), McaError>

Marks this chunk as empty and will skip writing this chunk.

§Example
let mut region = RegionWriter::new();

region.set_chunk(5, 1, Vec::new(), Compression::default())?;
region.set_chunk(21, 8, Vec::new(), Compression::default())?;

// 5, 1 will not get written now, but 21, 8 will
region.clear_chunk(5, 1)?;
Source

pub fn write<W: Write>(self, writer: &mut W) -> Result<usize, McaError>

Writes the chunks to a destination

This will compress and format the chunks into the region file format (.mca)

By default, this compresses all chunks in parallel, but can be disabled with default-features = false in your cargo.toml

§Example
let mut region = RegionWriter::new();

region.set_chunk(5, 8, Vec::new(), Compression::ZLib)?;

// region.write can take in anything that impl `Write`
let mut file = Vec::new();
region.write(&mut file)?;

Trait Implementations§

Source§

impl<'d, C: Clone + CustomCompression> Clone for RegionWriter<'d, C>

Source§

fn clone(&self) -> RegionWriter<'d, C>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<C: CustomCompression + Debug> Debug for RegionWriter<'_, C>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for RegionWriter<'_, ()>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'d, C> Freeze for RegionWriter<'d, C>
where C: Freeze,

§

impl<'d, C> RefUnwindSafe for RegionWriter<'d, C>
where C: RefUnwindSafe,

§

impl<'d, C> Send for RegionWriter<'d, C>

§

impl<'d, C> Sync for RegionWriter<'d, C>

§

impl<'d, C> Unpin for RegionWriter<'d, C>
where C: Unpin,

§

impl<'d, C> UnsafeUnpin for RegionWriter<'d, C>
where C: UnsafeUnpin,

§

impl<'d, C> UnwindSafe for RegionWriter<'d, C>
where C: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.