arc

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2026 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteFileByPath

func DeleteFileByPath(parent *Dir, path string) bool

DeleteFileByPath removes a file identified by its relative path from the specified parent directory and returns success status.

func NameHashUTF16

func NameHashUTF16(name string) uint64

NameHashUTF16 computes name hash (lowercased input) as UTF-16LE

func NameHashUTF8

func NameHashUTF8(name string) uint64

NameHashUTF8 computes name hash (lowercased input) as UTF-8

func Pack

func Pack(dirPath string, arcPath string) error

Pack loads all files from dirPath into an Arc structure and dumps it to arcPath

func UniqueIDHash

func UniqueIDHash(fullName string) uint64

UniqueIDHash computes the unique id hash of a full name encoded as UTF-16LE without lowercasing

Types

type Arc

type Arc struct {
	Name          string   // Name represents the name of the ARC file system or directory node.
	Root          *Dir     // Root represents the root directory of the ARC file system.
	KeepDupes     bool     // KeepDupes determines whether duplicate files are allowed based on their full path rather than just the name.
	CompressGlobs []string // CompressGlobs specifies glob patterns for file compression within the ARC file system.
}

Arc represents an ARC file system in memory

func NewArc added in v1.5.0

func NewArc(name string) *Arc

NewArc creates a new empty ARC file system

func ReadArc

func ReadArc(rs io.ReadSeeker) (*Arc, error)

ReadArc parses an ARC file and returns an in-memory Arc representation

func (*Arc) CopyFile

func (arc *Arc) CopyFile(srcPath string, dstPath string) error

CopyFile copies a file from the specified source path to the destination path within the Arc file system.

func (*Arc) CreateFile

func (arc *Arc) CreateFile(path string, data []byte) *File

CreateFile creates a new file at the specified path within the Arc file system and sets its data. creates a file node in the directory tree at the specified path relative to the given parent directory.

func (*Arc) DeleteFile

func (arc *Arc) DeleteFile(path string) bool

DeleteFile removes a file identified by its relative path within the Arc file system. Returns true if the file was deleted.

func (*Arc) Dump

func (arc *Arc) Dump(path string) error

Dump writes the Arc to an ARC file on disk

func (*Arc) GetFile

func (arc *Arc) GetFile(path string) *File

GetFile retrieves a file within the Arc file system by its relative path or returns nil if the file is not found.

func (*Arc) GetFileList

func (arc *Arc) GetFileList() []string

GetFileList retrieves a list of all files in the Arc file system with their relative paths.

func (*Arc) MergeFrom

func (arc *Arc) MergeFrom(src *Arc, keepDupes bool)

MergeFrom merges src into this Arc. If keepDupes is true, use full path as key for files; otherwise last segment.

func (*Arc) Unpack

func (arc *Arc) Unpack(outDir string) error

Unpack extracts the entire Arc file system to the specified directory.

type ArcPointer

type ArcPointer struct {
	// contains filtered or unexported fields
}

ArcPointer lazily reads from an .arc file at a given offset The offset points to the start of the 16-byte per-file header [u32 compressed][u32 padding][u32 rawSize][u32 size] followed by data

func NewArcPointer

func NewArcPointer(reader *stream.BinaryReader, offset int64) *ArcPointer

func (*ArcPointer) Compressed

func (a *ArcPointer) Compressed() bool

func (*ArcPointer) Data

func (a *ArcPointer) Data() ([]byte, error)

func (*ArcPointer) RawSize

func (a *ArcPointer) RawSize() uint32

func (*ArcPointer) Size

func (a *ArcPointer) Size() uint32

type Dir

type Dir struct {
	Arc    *Arc             // Arc represents a pointer to the Arc file system associated with this directory node.
	Name   string           // Name represents the name of the directory.
	Parent *Dir             // Parent represents the parent directory of the current directory node in the filesystem hierarchy.
	Dirs   map[string]*Dir  // Dirs maps directory names to their corresponding directory nodes within the current directory.
	Files  map[string]*File // Files maps file names to their corresponding file nodes within the current directory.
}

Dir represents a directory node

func AllDirs

func AllDirs(fs *Arc) []*Dir

AllDirs returns a list of all directories in the given Arc file system in depth-first order, excluding duplicates.

func GetOrCreateDirByPath

func GetOrCreateDirByPath(parent *Dir, path string) *Dir

GetOrCreateDirByPath navigates through or creates directories along the specified path starting from the given parent directory.

func (*Dir) AddFile

func (d *Dir) AddFile(f *File)

AddFile adds or replaces a file entry under this dir

func (*Dir) Depth

func (d *Dir) Depth() int

Depth returns the depth in the tree

func (*Dir) FullName

func (d *Dir) FullName() string

FullName returns full path with OS separator

func (*Dir) GetOrCreateDir

func (d *Dir) GetOrCreateDir(name string) *Dir

GetOrCreateDir finds or creates a directory by name under this dir

func (*Dir) UTF16Hash

func (d *Dir) UTF16Hash() uint64

UTF16Hash computes a hash for the directory name using UTF-16LE encoding and case-insensitive comparison.

func (*Dir) UTF8Hash

func (d *Dir) UTF8Hash() uint64

UTF8Hash computes a hash for the directory name using UTF-8 encoding and case-insensitive comparison.

func (*Dir) UniqueID

func (d *Dir) UniqueID() uint64

UniqueID computes a unique identifier for the directory based on its full path using UTF-16LE encoding.

type File

type File struct {
	Arc    *Arc        // Arc points to the ARC file system that this file belongs to.
	Name   string      // Name represents the name of the file or directory node.
	Parent *Dir        // Parent represents the parent directory of the current file node in the filesystem hierarchy.
	Ptr    FilePointer // Ptr represents a memory or compressed pointer to the file data.
}

File represents a file node with a data pointer

func AddFileByPath

func AddFileByPath(parent *Dir, path string) *File

AddFileByPath creates a file node in the directory tree at the specified path relative to the given parent directory.

func AllFiles

func AllFiles(fs *Arc) []*File

AllFiles returns a slice of all files in the provided Arc file system in a recursive traversal from the root directory.

func FindFileByPath

func FindFileByPath(parent *Dir, path string) *File

FindFileByPath retrieves a file by its path relative to the given parent directory or returns nil if not found.

func (*File) Extract

func (f *File) Extract(outPath string) error

Extract saves the file to the specified path.

func (*File) FullName

func (f *File) FullName() string

FullName returns full path including parent dirs

func (*File) RelativePath

func (f *File) RelativePath() string

RelativePath returns the path of the file relative to the Arc root.

func (*File) SetData

func (f *File) SetData(b []byte, compressed bool)

SetData sets file data using a memory pointer

func (*File) UTF16Hash

func (f *File) UTF16Hash() uint64

UTF16Hash computes and returns a hash value for the file name using UTF-16 encoding and case-insensitive comparison.

func (*File) UTF8Hash

func (f *File) UTF8Hash() uint64

UTF8Hash computes and returns a hash value for the file name using UTF-8 encoding and case-insensitive comparison.

func (*File) UniqueID

func (f *File) UniqueID() uint64

UniqueID computes and returns a unique identifier for the file based on its full path encoded as UTF-16LE without lowercasing.

type FilePointer

type FilePointer interface {
	Compressed() bool      // Compressed indicates if the file data is compressed.
	Data() ([]byte, error) // Data retrieves the file data as a byte slice.
	RawSize() uint32       // RawSize returns the uncompressed file size in bytes.
	Size() uint32          // Size returns the file size in bytes, respecting compression if applied.
}

FilePointer represents an interface for managing file data within an ARC file system.

type MemoryPointer

type MemoryPointer struct {
	// contains filtered or unexported fields
}

MemoryPointer represents a structure that encapsulates a memory buffer as a slice of bytes.

func NewMemoryPointer

func NewMemoryPointer(data []byte) *MemoryPointer

NewMemoryPointer creates a new MemoryPointer instance with a copy of the provided byte slice.

func (*MemoryPointer) Compressed

func (m *MemoryPointer) Compressed() bool

func (*MemoryPointer) Data

func (m *MemoryPointer) Data() ([]byte, error)

func (*MemoryPointer) RawSize

func (m *MemoryPointer) RawSize() uint32

func (*MemoryPointer) Size

func (m *MemoryPointer) Size() uint32

type MemoryPointerCompressed

type MemoryPointerCompressed struct {
	// contains filtered or unexported fields
}

MemoryPointerCompressed represents a data structure for managing compressed data and its raw size.

func NewMemoryPointerCompressed

func NewMemoryPointerCompressed(compressed []byte, rawSize uint32) *MemoryPointerCompressed

func NewMemoryPointerCompressedAuto

func NewMemoryPointerCompressedAuto(compressed []byte) *MemoryPointerCompressed

NewMemoryPointerCompressedAuto tries to determine raw size by decompressing

func (*MemoryPointerCompressed) Compressed

func (m *MemoryPointerCompressed) Compressed() bool

func (*MemoryPointerCompressed) Data

func (m *MemoryPointerCompressed) Data() ([]byte, error)

func (*MemoryPointerCompressed) RawSize

func (m *MemoryPointerCompressed) RawSize() uint32

func (*MemoryPointerCompressed) Size

func (m *MemoryPointerCompressed) Size() uint32

Jump to

Keyboard shortcuts

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