cp2077_extractor.cr2w.io

File IO operations.

Exceptions:

CNameError

Error raised when an invalid name is read.

Classes:

ParsingData(names_list, chunks, buffers)

Working data for parsing CR2W/W2RC files.

Functions:

parse_cr2w_buffer(fp[, filename])

Parse a CR2W/W2RC file from an opened file.

parse_cr2w_file(filename)

Parse a CR2W/W2RC file from the given path.

read_buffer(fp, info)

Read a buffer from the CR2W/W2RC file.

read_c_name(fp, names_list)

Read a name from the open file.

read_chunk(fp, chunk_index, file_info)

Read an export chunk from the file.

read_file_info(fp)

Read the file header and metadata.

read_struct(fp, struct_type)

Read the given struct from the open file.

read_tables(fp, table_struct, header)

Read a tables of the given type in from the opened file.

exception CNameError[source]

Bases: Exception

Error raised when an invalid name is read.

namedtuple ParsingData(names_list, chunks, buffers)[source]

Bases: NamedTuple

Working data for parsing CR2W/W2RC files.

Fields
  1.  names_list (list[bytes]) – Name lookup table for the file.

  2.  chunks (list[tuple[bytes, bytes]]) – List of tuples of the raw chunk data and the chunk’s datatype

  3.  buffers (list[tuple[bytes, CR2WBufferInfo]]) – List of tuples of the raw buffer data and the buffer metadata

__repr__()

Return a nicely formatted representation string

parse_cr2w_buffer(fp, filename=None)[source]

Parse a CR2W/W2RC file from an opened file.

Parameters
Return type

CR2WFile

parse_cr2w_file(filename)[source]

Parse a CR2W/W2RC file from the given path.

Parameters

filename (Union[str, Path, PathLike])

Return type

CR2WFile

read_buffer(fp, info)[source]

Read a buffer from the CR2W/W2RC file.

Parameters
Return type

bytes

read_c_name(fp, names_list)[source]

Read a name from the open file.

Reads the ordinal of the name, and looks up the name string in names_list.

Parameters
  • fp (IO)

  • names_list (list[bytes]) – Ordered list of names used in the file, for lookups.

Return type

bytes

read_chunk(fp, chunk_index, file_info)[source]

Read an export chunk from the file.

Parameters
Return type

tuple[bytes, bytes]

Returns

A tuple of the raw chunk data and the chunk’s datatype.

read_file_info(fp)[source]

Read the file header and metadata.

Parameters

fp (IO)

Return type

CR2WFileInfo

read_struct(fp, struct_type)[source]

Read the given struct from the open file.

Parameters
  • fp (IO)

  • struct_type (type[~_S])

Return type

~_S

read_tables(fp, table_struct, header)[source]

Read a tables of the given type in from the opened file.

Parameters
Return type

Iterator[~_S]

Returns

An iterator over instances of table_struct.