Documentation
¶
Index ¶
- Constants
- type Anvil
- type CachedFile
- func (c *CachedFile) Close() (err error)
- func (c *CachedFile) CompressionMethod(m CompressMethod) (err error)
- func (c *CachedFile) Read(x, z uint8, reader io.ReaderFrom) (n int64, err error)
- func (c *CachedFile) Remove(x, z uint8) (err error)
- func (c *CachedFile) Write(x, z uint8, b []byte) (err error)
- type CompressMethod
- type Entry
- type File
- type Fs
- type Header
Constants ¶
const ( // ErrExternal returned if the chunk is in an external file. // This error is only returned if the anvil file was opened as a single file. ErrExternal = errors.Const("anvil: chunk is in separate file") // ErrNotExist returned if the entry does not exist. ErrNotExist = errors.Const("anvil: entry does not exist") // ErrSize returned if the size of the anvil file is not a multiple of 4096. ErrSize = errors.Const("anvil: invalid file size") // ErrCorrupted the given file contains invalid/corrupted data ErrCorrupted = errors.Const("anvil: corrupted file") // ErrClosed the given file has already been closed ErrClosed = errors.Const("anvil: file closed") )
const ( // Entries the number of Entries in a anvil file Entries = 32 * 32 // SectionSize the size of a section SectionSize = 1 << sectionShift // MaxFileSections the maximum number of sections a file can contain MaxFileSections = 255 * Entries )
const DefaultCompression = CompressionZlib
DefaultCompression the default compression method to be used
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Anvil ¶
type Anvil struct {
// contains filtered or unexported fields
}
Anvil a anvil file cache.
func (*Anvil) File ¶
func (a *Anvil) File(rgX, rgZ int32) (f *CachedFile, err error)
File opens the anvil file at rgX, rgZ. Callers must close the returned file for it to be removed from the cache.
type CachedFile ¶
type CachedFile struct {
// contains filtered or unexported fields
}
CachedFile a cached anvil file
func (*CachedFile) Close ¶
func (c *CachedFile) Close() (err error)
Close closes the file. This function can be called multiple times. This will block until all Read and Write calls return.
func (*CachedFile) CompressionMethod ¶
func (c *CachedFile) CompressionMethod(m CompressMethod) (err error)
CompressionMethod sets the compression method to be used by the writer.
func (*CachedFile) Read ¶
func (c *CachedFile) Read(x, z uint8, reader io.ReaderFrom) (n int64, err error)
Read reads the entry at x,z to the given `reader`. `reader` must not retain the io.Reader passed to it. `reader` must not return before reading has completed.
func (*CachedFile) Remove ¶
func (c *CachedFile) Remove(x, z uint8) (err error)
Remove removes the given entry from the file.
func (*CachedFile) Write ¶
func (c *CachedFile) Write(x, z uint8, b []byte) (err error)
Write updates the data for the entry at x,z to the given buffer. The given buffer is compressed and written to the anvil file. The compression method used can be changed using the CompressMethod method. If the data is larger than 1MB after compression, the data is stored externally. Calling this function with an empty buffer is the equivalent of calling `Remove(x,z)`.
type CompressMethod ¶
type CompressMethod byte
CompressMethod the compression method used for compressing section data
const ( CompressionGzip CompressMethod = 1 + iota CompressionZlib CompressionNone )
supported methods
func (CompressMethod) String ¶
func (c CompressMethod) String() string
type Entry ¶
type Entry struct {
// contains filtered or unexported fields
}
Entry an entry in the anvil file
func (*Entry) CompressedSize ¶
CompressedSize the number of sections used by this entry (in sections). To get the size in bytes, multiply this value by `SectionSize`. If this is zero the data does not exist in this file. If the entry is stored in an external file, this will return 1.
type File ¶
type File struct {
// contains filtered or unexported fields
}
File is a single anvil file. All functions can be called concurrently from multiple goroutines.
func NewAnvil ¶
func NewAnvil(rgx, rgz int32, fs *Fs, r io.ReaderAt, readonly bool, fileSize int64) (a *File, err error)
NewAnvil reads an anvil file from the given ReadAtCloser. This has the same limitations as OpenFile if `fs` is nil. If fileSize is 0, no attempt is made to read any headers.
func OpenFile ¶
OpenFile opens the given anvil file. If readonly is set any attempts to modify the file will return an error. If any data is stored in external files, any attempt to read it will return ErrExternal. If an attempt is made to write a data that is over 1MB after compression, ErrExternal will be returned. To allow reading and writing to external files use Open instead.
func (*File) CompressionMethod ¶
func (a *File) CompressionMethod(m CompressMethod) (err error)
CompressionMethod sets the compression method to be used by the writer.
func (*File) Read ¶
Read reads the entry at x,z to the given `reader`. `reader` must not retain the io.Reader passed to it. `reader` must not return before reading has completed.
func (*File) Write ¶
Write updates the data for the entry at x,z to the given buffer. The given buffer is compressed and written to the anvil file. The compression method used can be changed using the CompressMethod method. If the data is larger than 1MB after compression, the data is stored externally. Calling this function with an empty buffer is the equivalent of calling `Remove(x,z)`.
type Fs ¶
type Fs struct {
AnvilFmt, ChunkFmt string
// contains filtered or unexported fields
}
Fs handles opening anvil files.
type Header ¶
type Header struct {
// contains filtered or unexported fields
}
Header the header of the anvil file.
func LoadHeader ¶
LoadHeader reads the header from the given arrays. `size` should contains the size and position of entries, with the least significant byte being the number of sections used by the entry and the rest containing the offset where the entry starts. `timestamps` should be an array of timestamps when the entries were last modified as the number of seconds since January 1, 1970 UTC. This function expects `size`, `timestamps` to be in the hosts byte order. `fileSections` is the max amount of sections that can be used by the entries. If `fileSections` is 0, `maxFileSections` is used instead.
func ReadHeader ¶
ReadHeader reads a header from the given reader. The given reader must read at least 2*4096 bytes. If `maxSections` != 0, this returns an error if the header references more than `maxSections` sections.
func (*Header) FindSpace ¶
FindSpace finds the next free space large enough to store `size` sections
func (*Header) Free ¶
func (h *Header) Free()
Free frees the header and puts it into the pool. Callers must not use the header after calling this.
func (*Header) Get ¶
Get gets the entry at the given x,z coords. If the given x,z values are not between 0 and 31 (inclusive) this panics.
func (*Header) Remove ¶
Remove removes the given entry from the header and marks the space used by the given entry in the `used` bitset as unused.