CPK File Pack
- class PyCriCodecsEx.cpk.CPK(filename: str | BinaryIO)[source]
Bases:
object
Use this class to load CPK file table-of-content, and read files from them on-demand.
- __init__(filename: str | BinaryIO) None [source]
Loads a CPK archive’s table-of-content and ready for file reading.
- Parameters:
filename (str | BinaryIO) – The path to the CPK file or a BinaryIO stream containing the CPK data.
- property files: Generator[PackedFile, None, None]
Creates a generator for all files in the CPK archive as PackedFile.
- property mode
Get the current mode of the CPK archive. [0,1,2,3]
See also CPKBuilder
- class PyCriCodecsEx.cpk.CPKBuilder(mode: int = 1, Tver: str = None, encrypt: bool = False, encoding: str = 'utf-8', progress_cb: callable = None)[source]
Bases:
object
Use this class to build semi-custom CPK archives.
- __init__(mode: int = 1, Tver: str = None, encrypt: bool = False, encoding: str = 'utf-8', progress_cb: callable = None) None [source]
Setup CPK file building
- Parameters:
mode (int, optional) – CPK mode. 0: ID Only (ITOC), 1: Name Only (TOC), 2: Name + ID (ITOC + TOC), 3: Name + ID + GTOC (GTOC). Defaults to 1.
Tver (str, optional) – CPK version. Defaults to None.
encrypt (bool, optional) – Enable encryption. Defaults to False.
encoding (str, optional) – Filename encoding. Defaults to “utf-8”.
progress_cb (callable, optional) – Progress callback taking (task name, current, total). Defaults to None.
- add_file(src: str, dst: str = None, compress=False)[source]
Add a file to the bundle.
- Parameters:
src (str) – The source file path.
dst (str) – The destination full file name (containing directory). Can be None in ITOC Mode. Defaults to None.
compress (bool, optional) – Whether to compress the file. Defaults to False.
Note
In ITOC-related mode, the insertion order determines the final integer ID of the files.
- save(outfile: str | BinaryIO, threads: int = 1)[source]
Build and save the bundle into a file
- Parameters:
outfile (str | BinaryIO) – The output file path or a writable binary stream.
threads (int, optional) – The number of threads to use for file compression. Defaults to 1.
Note
Temporary files may be created during the process if compression is used.