srctools.vpk
Classes for reading and writing Valve’s VPK format, version 1.
-
class
srctools.vpk.
OpenModes
(value) Bases:
Enum
Modes for opening VPK files.
-
READ
= 'r'
-
WRITE
= 'w'
-
APPEND
= 'a'
-
writable
Check if this mode allows modifying the VPK.
-
-
srctools.vpk.
get_arch_filename
() str Generate the name for a VPK file.
Prefix is the name of the file, usually ‘pak01’. index is the index of the data file, or None for the directory.
-
class
srctools.vpk.
FileInfo
(vpk: VPK,)
dir: str,
filename: str,
ext: str,
crc: int,
arch_index: int | None,
offset: int,
arch_len: int,
start_data: bytes, Represents a file stored inside a VPK.
Do not call the constructor, it is only meant for VPK’s use.
-
class
srctools.vpk.
VPK
(dir_file: str | PathLike[str],)
*,
mode: OpenModes | str = 'r',
dir_data_limit: int | None = 1024,
version: int = 1, Represents a VPK file set in a directory.
-
mode
: OpenModes How the file was opened.
- Read mode, the file will not be modified and it must already exist.
- Write mode will create the directory if needed.
- Append mode will also create the directory, but not wipe the file.
-
dir_limit
: int | None The maximum amount of data for files saved to the dir file.
None
: No limit.0
: Save all to a data file.
The block of data after the header, which contains the file data for files stored in the
_dir
file, not numeric files.
-
property
path
: str | PathLike[str] The filename of the directory VPK file.
This can be assigned to set
folder
andfile_prefix
.
-
load_dirfile
() None Read in the directory file to get all filenames. This erases all changes in the file.
-
write_dirfile
() None Write the directory file with the changes. This must be performed after writing to the VPK.
-
filenames
(ext: str = '', folder: str = '') Iterator[str] Yield filenames from this VPK.
If an extension or folder is specified, only files with this extension or in this folder are returned.
-
fileinfos
(ext: str = '', folder: str = '') Iterator[FileInfo] Yield file info objects from this VPK.
If an extension or folder is specified, only files with this extension or in this folder are returned.
-
new_file
() FileInfo Create the given file, making it empty by default.
If root is set, files are treated as relative to there, otherwise the filename must be relative.
FileExistsError will be raised if the file is already present.
-
add_file
(filename: str | Tuple[str, str] | Tuple[str, str, str],) None
data: bytes,
root: str = '',
arch_index: int | None = 0, Add the given data to the VPK.
If root is set, files are treated as relative to there, otherwise the filename must be relative. arch_index is the pak01_xxx file to copy this to, if the length is larger than self.dir_limit. If None it’s written to the _dir file.
FileExistsError will be raised if the file is already present.
-