Documentation
¶
Overview ¶
Package vpk reads, edits, and writes Valve VPK archives.
A VPK value is also an fs.FS, so callers can use the standard io/fs helpers to read files, stat entries, and list directories.
Index ¶
- Variables
- func Create(path string, v *VPK, opts ...CreateOption) error
- type ArchiveResolver
- type ChecksumError
- type CreateOption
- type Entry
- type EntryOption
- type File
- type Header
- type Option
- type Reader
- type ReaderOption
- type VPK
- func (v *VPK) Add(name string, r io.Reader, opts ...EntryOption) error
- func (v *VPK) AddFS(fsys fs.FS, root string, opts ...EntryOption) error
- func (v *VPK) Clear() error
- func (v *VPK) Close() error
- func (v *VPK) Delete(name string) error
- func (v *VPK) Entries() []Entry
- func (v *VPK) Open(name string) (fs.File, error)
- func (v *VPK) Put(name string, r io.Reader, opts ...EntryOption) error
- func (v *VPK) ReadDir(name string) ([]fs.DirEntry, error)
- func (v *VPK) ReadFile(name string) ([]byte, error)
- func (v *VPK) Rename(oldName, newName string) error
- func (v *VPK) Save() error
- func (v *VPK) SetVerifyCRC(enabled bool)
- func (v *VPK) Stat(name string) (fs.FileInfo, error)
- func (v *VPK) VerifyCRC() bool
- type Version
- type Writer
Constants ¶
This section is empty.
Variables ¶
var ( // ErrClosed is returned when an operation uses a closed VPK or Writer. ErrClosed = errors.New("vpk: closed") // ErrExist is returned when adding an entry that already exists. ErrExist = errors.New("vpk: file already exists") // ErrNoSavePath is returned when Save is called for a VPK without an // original filesystem path. ErrNoSavePath = errors.New("vpk: no save path") // ErrNotExist is returned when an entry does not exist. ErrNotExist = errors.New("vpk: file does not exist") )
Functions ¶
Types ¶
type ArchiveResolver ¶ added in v1.0.0
ArchiveResolver opens numbered sub archives referenced by directory entries.
type ChecksumError ¶ added in v1.0.0
ChecksumError is returned when CRC verification fails while reading a file.
func (ChecksumError) Error ¶ added in v1.0.0
func (e ChecksumError) Error() string
type CreateOption ¶ added in v1.0.0
type CreateOption func(*createOptions)
CreateOption configures archive creation.
func WithVersion ¶ added in v1.0.0
func WithVersion(version Version) CreateOption
WithVersion sets the VPK version used when writing.
Supported versions are Version1 and Version2.
type Entry ¶ added in v1.0.0
type Entry struct {
Name string
CRC32 uint32
PreloadBytes []byte
ArchiveIndex uint16
Offset uint32
Size uint32
}
Entry describes a file entry in a VPK directory tree.
type EntryOption ¶ added in v1.0.0
type EntryOption func(*entryOptions)
EntryOption configures an entry added to a VPK.
type Header ¶ added in v1.0.0
type Header struct {
Signature uint32
Version uint32
TreeSize uint32
FileDataSectionSize uint32
ArchiveMD5SectionSize uint32
OtherMD5SectionSize uint32
SignatureSectionSize uint32
}
Header is the fixed VPK header parsed from a directory archive.
type Option ¶ added in v1.0.0
type Option func(*options)
Option configures Open and OpenFS.
func WithArchiveResolver ¶ added in v1.0.0
func WithArchiveResolver(resolver ArchiveResolver) Option
WithArchiveResolver sets the resolver used to lazily open numbered sub archives while reading file contents.
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader reads a VPK directory archive from an io.ReaderAt.
type ReaderOption ¶ added in v1.0.0
type ReaderOption func(*readerOptions)
ReaderOption configures Reader.
func WithReaderArchiveResolver ¶ added in v1.0.0
func WithReaderArchiveResolver(resolver ArchiveResolver) ReaderOption
WithReaderArchiveResolver sets the resolver used by the VPK returned from Reader.Read.
type VPK ¶ added in v1.0.0
type VPK struct {
// contains filtered or unexported fields
}
VPK is an editable VPK archive and implements fs.FS.
func Open ¶ added in v1.0.0
Open opens a VPK from a filesystem path.
The path may point to either "name.vpk" or "name_dir.vpk". Numbered sub archives are opened lazily when their file data is read.
func OpenFS ¶ added in v1.0.0
OpenFS opens a VPK directory archive from fsys.
The opened file and any lazily opened sub archives must implement io.ReaderAt.
func (*VPK) Add ¶ added in v1.0.0
Add adds a new file entry. It returns ErrExist if name already exists.
func (*VPK) AddFS ¶ added in v1.0.0
AddFS adds regular files below root from fsys.
When root is ".", file names are stored relative to the filesystem root.
func (*VPK) Save ¶ added in v1.0.0
Save overwrites the original path used by Open.
It returns ErrNoSavePath for VPK values created with New, OpenFS, or NewReader(...).Read().
func (*VPK) SetVerifyCRC ¶ added in v1.0.0
SetVerifyCRC controls whether file reads verify Entry.CRC32.
type Version ¶ added in v1.0.0
type Version uint32
Version is a VPK directory archive format version.
type Writer ¶ added in v1.0.0
type Writer struct {
// contains filtered or unexported fields
}
Writer writes VPK archives to an io.Writer.
func NewWriter ¶ added in v1.0.0
func NewWriter(w io.Writer, opts ...CreateOption) *Writer
NewWriter returns a writer that serializes VPK values to w.