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<'_, ()>
impl RegionWriter<'_, ()>
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new RegionWriter with no custom compression specified.
Sourcepub fn sector_size(compressed_len: usize, compression: &Compression) -> usize
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
Sourcepub fn chunk_view_len(compressed_len: usize, compression: &Compression) -> usize
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
Sourcepub fn write_packed<W: Write>(
writer: &mut W,
chunks: Vec<PackedChunk<'_>>,
) -> Result<usize, McaError>
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>
impl<'c, C: CustomCompression> RegionWriter<'c, C>
Sourcepub fn new_with_compression(custom_compression: C) -> Self
pub fn new_with_compression(custom_compression: C) -> Self
Creates a new RegionWriter with a specified custom compression to use when writing chunks.
Sourcepub fn chunk(
&self,
x: u8,
z: u8,
) -> Result<&Option<WritableChunk<'_>>, McaError>
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
Sourcepub fn chunk_mut(
&mut self,
x: u8,
z: u8,
) -> Result<&mut Option<WritableChunk<'c>>, McaError>
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
Sourcepub fn set_chunk(
&mut self,
x: u8,
z: u8,
data: Vec<u8>,
compression: Compression,
) -> Result<(), McaError>
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())?;Sourcepub fn clear_chunk(&mut self, x: u8, z: u8) -> Result<(), McaError>
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)?;
Sourcepub fn write<W: Write>(self, writer: &mut W) -> Result<usize, McaError>
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>
impl<'d, C: Clone + CustomCompression> Clone for RegionWriter<'d, C>
Source§fn clone(&self) -> RegionWriter<'d, C>
fn clone(&self) -> RegionWriter<'d, C>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<C: CustomCompression + Debug> Debug for RegionWriter<'_, C>
impl<C: CustomCompression + Debug> Debug for RegionWriter<'_, C>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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