arclib

package module
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 8, 2024 License: MIT Imports: 6 Imported by: 2

README

arclib

A library to read and write U8 archives.

Documentation

License

arclib is released under the MIT License, read here for more information.

Q&A

This library is an absolute mess.

Thanks!

Why does this library not utilize fs.FS?

Unfortunately, the fs.FS package only provides read-only functions. There are no write capabilities, making it unfortunately unsuitable. Implementing read-only and custom write feels hacky. In the future, it would be highly preferable to migrate this library to utilize its interface.

Documentation

Index

Constants

View Source
const (
	ARCHeader = 0x55AA382D
)

Variables

View Source
var (
	ErrInvalidRootNode = errors.New("root node was not a directory")
	ErrInvalidMagic    = errors.New("invalid ARC magic")
	ErrUnknownNode     = errors.New("unknown node type")
)

Functions

This section is empty.

Types

type ARC

type ARC struct {
	// RootRecord holds the root record for this ARC.
	//
	// It's important to note that this root record is nameless.
	// Many officially-provided ARCs within Nintendo games have one folder
	// containing all data, typically named "arc".
	// This folder has "arc" as one of its contents.
	RootRecord ARCDir
}

ARC describes a hierarchy suitable for serialization and deserialization of an ARC file.

func Load

func Load(contents []byte) (*ARC, error)

Load takes the given ARC and breaks it down into a more easily dealt with format.

func LoadFromFile

func LoadFromFile(path string) (*ARC, error)

LoadFromFile reads a file and passes its contents to Load.

func (*ARC) FileSize

func (a *ARC) FileSize(path string) (int, error)

FileSize returns the size in bytes of the file for the given path.

func (*ARC) OpenDir

func (a *ARC) OpenDir(path string) (*ARCDir, error)

OpenDir returns the directory at the given path, or an errir if not possible.

func (*ARC) OpenFile

func (a *ARC) OpenFile(path string) (*ARCFile, error)

OpenFile returns a file at the given path, or an error if not possible.

func (*ARC) ReadFile

func (a *ARC) ReadFile(path string) ([]byte, error)

ReadFile returns the contents of a file at the given path.

func (*ARC) Save

func (a *ARC) Save() ([]byte, error)

Save converts the given ARC hierarchy to a usable binary file.

func (*ARC) SaveToFile

func (a *ARC) SaveToFile(path string) error

SaveToFile writes a serialized ARC to the specified path.

func (*ARC) WriteFile

func (a *ARC) WriteFile(path string, contents []byte) error

WriteFile writes the passed contents at the given path.

type ARCDir

type ARCDir struct {
	// Filename is the name of this directory. It must not be empty.
	Filename string
	// Files is an array of files within this directory.
	Files []ARCFile
	// Subdirs is an array of directories within this directory.
	Subdirs []ARCDir
	// contains filtered or unexported fields
}

ARCDir represents a directory available within an ARC.

func (*ARCDir) AddDir

func (d *ARCDir) AddDir(dir ARCDir)

AddDir adds a directory to the list of subdirectories.

func (*ARCDir) AddFile

func (d *ARCDir) AddFile(file ARCFile)

AddFile adds a file to the list of files in this directory.

func (*ARCDir) GetDir

func (d *ARCDir) GetDir(name string) (*ARCDir, error)

GetDir retrieves the directory by the given name.

func (*ARCDir) GetFile

func (d *ARCDir) GetFile(name string) (*ARCFile, error)

GetFile retrieves the file by the given name.

func (*ARCDir) RecursiveCount

func (d *ARCDir) RecursiveCount() int

RecursiveCount returns the amount of files and sub-directories within.

func (*ARCDir) Size

func (d *ARCDir) Size() int

Size returns the count of files and directories immediately within.

func (*ARCDir) WriteFile

func (d *ARCDir) WriteFile(name string, contents []byte)

WriteFile adds a file with the specified contents to the directory.

type ARCFile

type ARCFile struct {
	// Filename is the name of this file. It must not be empty.
	Filename string
	// Data is the contents of this file.
	Data []byte
}

ARCFile represents a file available within an ARC.

func (*ARCFile) Size

func (f *ARCFile) Size() int

Size returns the size of the given file in bytes.

func (*ARCFile) Write

func (f *ARCFile) Write(contents []byte)

Write writes the passed contents to the given file.

type ARCType

type ARCType uint8
const (
	File ARCType = iota
	Directory
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL