arc

package
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2026 License: BSD-3-Clause Imports: 13 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 从给定父目录删除相对路径所标识的文件并返回成功状态 DeleteFileByPath removes a file identified by its relative path from the specified parent directory and returns success status

func NameHashUTF8

func NameHashUTF8(name string) uint64

NameHashUTF8 将输入转换为小写并按 UTF-8 计算名称哈希 NameHashUTF8 computes name hash (lowercased input) as UTF-8

func NameHashUTF16

func NameHashUTF16(name string) uint64

NameHashUTF16 将输入转换为小写并按 UTF-16LE 计算名称哈希 NameHashUTF16 computes name hash (lowercased input) as UTF-16LE

func Pack

func Pack(dirPath string, arcPath string) error

Pack 将 dirPath 中的全部文件载入 Arc 结构并写到 arcPath Pack loads all files from dirPath into an Arc structure and dumps it to arcPath

func UniqueIDHash

func UniqueIDHash(fullName string) uint64

UniqueIDHash 对不转换小写的完整名称按 UTF-16LE 计算唯一 ID 哈希 UniqueIDHash computes the unique id hash of a full name encoded as UTF-16LE without lowercasing

Types

type Arc

type Arc struct {
	Name          string   // ARC 文件系统或目录节点的名称 / Name represents the name of the ARC file system or directory node
	Root          *Dir     // ARC 文件系统的根目录 / 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 // ARC 文件系统内用于压缩文件的通配模式 / CompressGlobs specifies glob patterns for file compression within the ARC file system
}

Arc 表示内存中的 ARC 文件系统 Arc represents an ARC file system in memory

func NewArc

func NewArc(name string) *Arc

NewArc 创建新的空 ARC 文件系统 NewArc creates a new empty ARC file system

func ReadArc

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

ReadArc 从 rs 解析 ARC 元数据 文件载荷仍由 rs 延迟支持,因此后续 Data 或 Extract 调用时调用方必须保持 rs 可读,需要脱离源流时使用 ReadArcFile 或 ReadArcBytes ReadArc parses ARC metadata from rs File payloads remain lazily backed by rs, so callers must keep rs readable for later Data or Extract calls Use ReadArcFile or ReadArcBytes when a detached Arc is required

func ReadArcBytes

func ReadArcBytes(data []byte) (*Arc, error)

ReadArcBytes 从内存中解析 ARC 载荷 返回的 Arc 延迟读取内存缓冲区,不依赖打开的文件句柄 ReadArcBytes parses an ARC payload from memory The returned Arc lazily reads from the in-memory buffer and does not depend on an open file handle

func ReadArcFile

func ReadArcFile(path string) (*Arc, error)

ReadArcFile 将 ARC 文件读入内存后解析 当源文件关闭后仍需使用返回的 Arc 时使用此函数 ReadArcFile loads an ARC file into memory before parsing it Use this when the returned Arc must remain usable after the source file is closed

func (*Arc) CopyFile

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

CopyFile 在 ARC 文件系统中将文件从指定源路径复制到目标路径 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 在 ARC 文件系统中的指定路径创建新文件并设置其数据 此函数在目录树中按相对于给定父目录的指定路径创建文件节点 CreateFile creates a new file at the specified path within the Arc file system and sets its data This 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 删除 ARC 文件系统中相对路径所标识的文件,成功删除时返回 true DeleteFile removes a file identified by its relative path within the Arc file system and returns true if the file was deleted

func (*Arc) Dump

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

Dump 将 Arc 写入磁盘上的 ARC 文件 Dump writes the Arc to an ARC file on disk

func (*Arc) GetFile

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

GetFile 按相对路径获取 ARC 文件系统中的文件,未找到时返回 nil 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 获取 ARC 文件系统中所有文件及其相对路径的列表 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 将 src 合并到当前 Arc,keepDupes 为 true 时使用完整路径作为文件键,否则使用最后一段名称 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 将整个 Arc 文件系统解压到指定目录 Unpack extracts the entire Arc file system to the specified directory

type ArcPointer

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

ArcPointer 从 ARC 文件中的给定偏移延迟读取数据 此偏移指向每个文件所用的 16 字节头部起始位置 头部依次为压缩标志、保留值、原始大小和存储大小,随后是文件数据 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

NewArcPointer 创建一个从给定文件头偏移读取数据的延迟指针 NewArcPointer creates a lazy pointer that reads data from the given file-header offset

func (*ArcPointer) Compressed

func (a *ArcPointer) Compressed() bool

Compressed 返回文件头中的压缩标志,读取错误时返回当前缓存值 Compressed returns the header compression flag and returns the cached value on read failure

func (*ArcPointer) Data

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

Data 根据已缓存的偏移和大小读取 ARC 中的数据字节 Data reads the ARC data bytes using the cached offset and size

func (*ArcPointer) RawSize

func (a *ArcPointer) RawSize() uint32

RawSize 返回文件头记录的解压后大小 RawSize returns the uncompressed size recorded in the file header

func (*ArcPointer) Size

func (a *ArcPointer) Size() uint32

Size 返回文件头记录的 ARC 存储大小 Size returns the ARC storage size recorded in the file header

type Dir

type Dir struct {
	Arc    *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 表示目录节点 Dir represents a directory node

func AllDirs

func AllDirs(fs *Arc) []*Dir

AllDirs 返回给定 ARC 文件系统中按深度优先顺序排列且不重复的所有目录 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 从给定父目录开始沿指定路径查找或创建目录 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 在当前目录下添加或替换文件条目 AddFile adds or replaces a file entry under this dir

func (*Dir) Depth

func (d *Dir) Depth() int64

Depth 返回目录在树中的深度 Depth returns the depth in the tree

func (*Dir) FullName

func (d *Dir) FullName() string

FullName 返回使用操作系统分隔符连接的完整路径 FullName returns full path with OS separator

func (*Dir) GetOrCreateDir

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

GetOrCreateDir 在当前目录下查找或创建指定名称的目录 GetOrCreateDir finds or creates a directory by name under this dir

func (*Dir) UTF8Hash

func (d *Dir) UTF8Hash() uint64

UTF8Hash 使用 UTF-8 编码和不区分大小写的比较方式计算目录名哈希 UTF8Hash computes a hash for the directory name using UTF-8 encoding and case-insensitive comparison

func (*Dir) UTF16Hash

func (d *Dir) UTF16Hash() uint64

UTF16Hash 使用 UTF-16LE 编码和不区分大小写的比较方式计算目录名哈希 UTF16Hash computes a hash for the directory name using UTF-16LE encoding and case-insensitive comparison

func (*Dir) UniqueID

func (d *Dir) UniqueID() uint64

UniqueID 使用 UTF-16LE 编码根据目录完整路径计算唯一标识 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 文件系统 / 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 表示带有数据指针的文件节点 File represents a file node with a data pointer

func AddFileByPath

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

AddFileByPath 在给定父目录的指定相对路径中创建文件节点 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 返回从根目录递归遍历给定 ARC 文件系统得到的所有文件 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 按相对于给定父目录的路径获取文件,未找到时返回 nil 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 将文件保存到指定路径 Extract saves the file to the specified path

func (*File) FullName

func (f *File) FullName() string

FullName 返回包含父目录的完整路径 FullName returns full path including parent dirs

func (*File) RelativePath

func (f *File) RelativePath() string

RelativePath 返回文件相对于 ARC 根目录的路径 RelativePath returns the path of the file relative to the Arc root

func (*File) SetData

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

SetData 使用内存指针设置文件数据 SetData sets file data using a memory pointer

func (*File) UTF8Hash

func (f *File) UTF8Hash() uint64

UTF8Hash 使用 UTF-8 编码和不区分大小写的比较方式计算并返回文件名哈希 UTF8Hash computes and returns a hash value for the file name using UTF-8 encoding and case-insensitive comparison

func (*File) UTF16Hash

func (f *File) UTF16Hash() uint64

UTF16Hash 使用 UTF-16 编码和不区分大小写的比较方式计算并返回文件名哈希 UTF16Hash computes and returns a hash value for the file name using UTF-16 encoding and case-insensitive comparison

func (*File) UniqueID

func (f *File) UniqueID() uint64

UniqueID 根据不转换为小写的 UTF-16LE 文件完整路径计算并返回唯一标识 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 表示文件数据是否已压缩 / Compressed indicates if the file data is compressed
	Data() ([]byte, error) // Data 以字节切片形式获取文件数据 / Data retrieves the file data as a byte slice
	RawSize() uint32       // RawSize 返回未压缩文件的字节大小 / RawSize returns the uncompressed file size in bytes
	Size() uint32          // Size 返回文件的存储字节大小,并反映是否应用压缩 / Size returns the file size in bytes, respecting compression if applied
}

FilePointer 表示用于管理 ARC 文件系统内文件数据的接口 FilePointer represents an interface for managing file data within an ARC file system

type MemoryPointer

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

MemoryPointer 表示将内存缓冲区封装为字节切片的结构 MemoryPointer represents a structure that encapsulates a memory buffer as a slice of bytes

func NewMemoryPointer

func NewMemoryPointer(data []byte) *MemoryPointer

NewMemoryPointer 创建一个复制所提供字节切片的新 MemoryPointer 实例 NewMemoryPointer creates a new MemoryPointer instance with a copy of the provided byte slice

func (*MemoryPointer) Compressed

func (m *MemoryPointer) Compressed() bool

Compressed 始终返回 false,因为该指针保存未压缩数据 Compressed always returns false because this pointer stores uncompressed data

func (*MemoryPointer) Data

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

Data 返回未压缩数据的副本 Data returns a copy of the uncompressed data

func (*MemoryPointer) RawSize

func (m *MemoryPointer) RawSize() uint32

RawSize 返回未压缩数据的字节数 RawSize returns the number of bytes in the uncompressed data

func (*MemoryPointer) Size

func (m *MemoryPointer) Size() uint32

Size 返回未压缩数据在 ARC 中的存储字节数 Size returns the number of bytes used to store the uncompressed data in the ARC

type MemoryPointerCompressed

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

MemoryPointerCompressed 表示用于管理压缩数据及其原始大小的结构 MemoryPointerCompressed represents a data structure for managing compressed data and its raw size

func NewMemoryPointerCompressed

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

NewMemoryPointerCompressed 创建一个保存压缩数据的内存指针 NewMemoryPointerCompressed creates a memory pointer for already compressed data

func NewMemoryPointerCompressedAuto

func NewMemoryPointerCompressedAuto(compressed []byte) *MemoryPointerCompressed

NewMemoryPointerCompressedAuto 尝试通过解压数据确定原始大小,解压失败时将原始大小保留为零 NewMemoryPointerCompressedAuto tries to determine raw size by decompressing and leaves it at zero when decompression fails

func (*MemoryPointerCompressed) Compressed

func (m *MemoryPointerCompressed) Compressed() bool

Compressed 始终返回 true,因为该指针保存压缩数据 Compressed always returns true because this pointer stores compressed data

func (*MemoryPointerCompressed) Data

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

Data 返回压缩数据的副本 Data returns a copy of the compressed data

func (*MemoryPointerCompressed) RawSize

func (m *MemoryPointerCompressed) RawSize() uint32

RawSize 返回压缩数据解压后的大小 RawSize returns the size of the compressed data after decompression

func (*MemoryPointerCompressed) Size

func (m *MemoryPointerCompressed) Size() uint32

Size 返回压缩数据在 ARC 中的存储字节数 Size returns the number of bytes used to store the compressed data in the ARC

Jump to

Keyboard shortcuts

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