vpk

package module
v0.0.0-...-25ff2ef Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2024 License: Unlicense Imports: 11 Imported by: 2

README

go-vpk

GoDoc Go Report Card

Golang implementation of a reader for Valve's Pak format (.vpk)

Installation

$ go get -u github.com/NublyBR/go-vpk

Examples

List all entries inside a .vpk dir file:

package main

import (
	"fmt"

	"github.com/NublyBR/go-vpk"
)

func main() {
	// Open the VPK dir file
	pak, err := vpk.OpenDir(`C:\Program Files (x86)\Steam\steamapps\common\Half-Life 2\hl2\hl2_pak_dir.vpk`)
	if err != nil {
		panic(err)
	}
	defer pak.Close()

	// Iterate through all files in the VPK
	for _, file := range pak.Entries() {
		// Print the file size and full file name
		fmt.Printf("% 8d %s\n", file.Length(), file.Filename())
	}
}

Example output:

    1517 gamepadui/schemetab.res
    2056 gamepadui/schemesavebutton.res
    3348 gamepadui/schemepanel.res
    1233 gamepadui/schemeoptions_wheelywheel.res
    1440 gamepadui/schemeoptions_slideyslide.res
    3206 gamepadui/schemeoptions_skillyskill.res
    1150 gamepadui/schemeoptions_sectiontitle.res
    2038 gamepadui/schemeoptions_checkybox.res
    2691 gamepadui/schememainmenu.res
    2051 gamepadui/schemechapterbutton.res
    2356 gamepadui/schemeachievement.res
    8817 gamepadui/options.res
    1074 gamepadui/mainmenu.res
   18563 whitelist.cfg
     301 unusedcontent.cfg
    5595 shader_cache.cfg
  997033 scenes/scenes.image
   81317 scene.cache
      16 modelsounds.cache
    6062 maps/graphs/intro.ain
    7350 maps/graphs/d3_citadel_05.ain
       ...

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidVPKVersion   = errors.New("invalid VPK version")
	ErrInvalidVPKSignature = errors.New("invalid VPK signature")
	ErrWrongHeaderSize     = errors.New("wrong header size")
	ErrInvalidArchiveIndex = errors.New("invalid archive index")
	ErrInvalidPath         = errors.New("invalid path")
)

Functions

This section is empty.

Types

type Entry

type Entry interface {
	// Filename of VPK entry
	Filename() string

	// Filename without path
	Basename() string

	// Path of VPK entry
	Path() string

	// Length of VPK entry
	Length() uint32

	// Is filename and path safe to extract in linux/unix?
	FilenameSafeUnix() bool

	// Is filename and path safe to extract in windows?
	FilenameSafeWindows() bool

	// Open VPK entry for reading
	Open() (FileReader, error)

	// CRC of VPK entry
	CRC() uint32
}

type FileReader

type FileReader interface {
	io.Reader
	io.ReaderAt
	io.Seeker
	io.Closer
}

type VPK

type VPK interface {
	// Opens the entry at the given path
	Open(path string) (FileReader, error)

	// Find the entry at the given path
	Find(path string) (Entry, bool)

	// All entries in the VPK
	Entries() []Entry

	// Closes the VPK
	Close() error
}

func OpenAny

func OpenAny(path string) (VPK, error)

Opens either a single VPK file or a VPK directory depending on the file name.

func OpenDir

func OpenDir(path string) (VPK, error)

Open a VPK file with multiple index files.

func OpenSingle

func OpenSingle(path string) (VPK, error)

Opens a single VPK file.

func OpenStream

func OpenStream(fs FileReader) (VPK, error)

Jump to

Keyboard shortcuts

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