Help us shape the future of Go! Take the 2026 Go Developer Survey

vpk

package
v0.1.41 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package vpk reads and writes Valve archives (VPK), the packages Source 2 games mount their resources from.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Files

func Files(archive []byte) (map[string][]byte, error)

Files reads every file of a single-file Valve archive. A file without preload bytes aliases archive. An archive split across numbered parts is refused.

func Packed

func Packed(tree fs.FS) fs.FS

Packed returns tree with each directory named *.vpk shown as the archive Write packs from its files, the inverse of Unpacked. Its size comes from the files' sizes alone; opening it starts packing, and reading it streams the archive as Write produces it.

func Paths

func Paths(source io.Reader) (map[string]struct{}, error)

Paths reads only a Valve archive's directory, including split-archive indexes. Payloads are skipped; compatibility checks need resource names only.

func Size

func Size(tree fs.FS) (int64, error)

Size returns the length of the archive Write packs from tree, reading only the files' sizes.

func Unpacked

func Unpacked(tree fs.FS) fs.FS

Unpacked returns tree with each single-file archive named *.vpk shown as a directory of the same name holding the archive's files. Importing the result stores each file on its own, so a file a new version leaves unchanged stores as the same blocks. A file that is not a single-file archive, such as a split archive's directory, stays a file. Unpacked reads each archive whole the first time it is asked about and keeps its files for the returned tree's lifetime; an archive nested in another stays a file.

func Write

func Write(w io.Writer, tree fs.FS) error

Write packs every regular file in tree into one version 1 Valve archive on w, the layout the resource compiler writes: no preload bytes, and each file's data stored after the directory, in directory order. Files are ordered by extension, directory and name, so equal trees pack to equal bytes. Paths keep their case; the game reads lowercase resource names. Write reads each file twice, once for its checksum and once to copy it, and fails if a file changes in between.

Types

type Archive

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

Archive is an archive on disk, read one file at a time: a single-file archive such as an addon's, or a directory such as the game's pak01_dir.vpk whose files live in numbered parts beside it.

func OpenArchive

func OpenArchive(path string) (*Archive, error)

OpenArchive reads the directory of the archive at path.

func (*Archive) Names

func (a *Archive) Names() []string

Names returns the archive's file names in order.

func (*Archive) ReadFile

func (a *Archive) ReadFile(name string) ([]byte, error)

ReadFile reads the file name: its preload bytes, then the rest from the directory file or the numbered part that holds it.

func (*Archive) Size

func (a *Archive) Size(name string) (int64, bool)

Size returns the length of the file name, and whether the archive holds it.

Directories

Path Synopsis
Package vpktest writes small Valve archives for tests.
Package vpktest writes small Valve archives for tests.

Jump to

Keyboard shortcuts

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