Categorygithub.com/FireworkMC/anvil
modulepackage
0.1.0
Repository: https://github.com/fireworkmc/anvil.git
Documentation: pkg.go.dev

# README

anvil

Go Go Report Card codecov Go Reference

anvil is a simple library for reading and writing minecraft anvil files.

Installation

go get github.com/FireworkMC/anvil

Usage

Reading and writing data from a directory containing anvil files

a, err := anvil.Open("/path/to/anvil/dir")
if err != nil{
    // handle error
}

var buffer bytes.Buffer
_, err = a.ReadTo(chunkX, chunkZ, &buffer)

// do stuff with the buffer


err = a.Write(chunkX, chunkZ, buffer.Bytes())

err = a.Close()

The anvil.Anvil returned by Open contains a cache of opened anvil files. It is recommended to use Open instead of OpenFile since opening anvil files is an expensive operation.

Reading and writing data from a single anvil file

f, err := anvil.OpenFile("/path/to/anvil/file")
if err != nil{
    // handle error
}

var buffer bytes.Buffer
// relative coordinates of the chunk data must be used
// If the chunk exists at chunkX, chunkZ: chunkX % 32, chunkZ % 32 should be used. 
_, err = f.ReadTo(chunkX%32, chunkZ%32, &buffer)


// do stuff with buffer

_, err = f.Write(chunkX%32, chunkZ%32, buffer.Bytes())

# Functions

LoadHeader reads the header from the given arrays.
Open opens the given directory.
OpenFile opens the given anvil file.
OpenFs opens the given directory.
ReadAnvil reads an anvil file from the given ReadAtCloser.
ReadHeader reads a header from the given reader.

# Constants

supported methods.
supported methods.
supported methods.
DefaultCompression the default compression method to be used.
Entries the number of Entries in a anvil file.
ErrClosed the given file has already been closed.
ErrCorrupted the given file contains invalid/corrupted data.
ErrExternal returned if the is in an external file.
ErrNotExist returned if the entry does not exist.
ErrReadOnly the file was opened in readonly mode.
ErrSize returned if the size of the anvil file is not a multiple of [SectionSize].
MaxFileSections the maximum number of sections a file can contain.
SectionSize the size of a section.

# Structs

Anvil a anvil file cache.
Entry
Entry an entry in the anvil file.
Header the header of the anvil file.
Settings settings.

# Interfaces

File is a single anvil file.

# Type aliases

CompressMethod the compression method used for compressing section data.