romfs - RomFS reader

The romfs module enables reading application read-only filesystems.

RomFSReader objects

class pyctr.type.romfs.RomFSReader(file, case_insensitive=False, *, fs=None, closefd=None, open_compatibility_mode=True)[source]

Bases: TypeReaderBase, FS

Reads the contents of the RomFS, found inside NCCH containers.

The RomFS found inside an NCCH is wrapped in an IVFC hash-tree container. This class only supports Level 3, which contains the actual files.

Parameters:
  • file (FilePathOrObject) – A file path or a file-like object with the RomFS data.

  • case_insensitive (bool) – Use case-insensitive paths.

  • closefd (bool) – Close the underlying file object when closed. Defaults to True for file paths, and False for file-like objects.

  • open_compatibility_mode (bool) – Changes the behavior of open() to behave as it did before pyctr 0.8.0. Read its documentation for details.

  • fs (Optional[FS]) –

open(path, mode='r', buffering=-1, encoding=None, errors=None, newline='', **options)[source]

Open a file for reading.

Warning

By default, for compatibility reasons, this function works differently than the normal FS open method. Files are opened in binary mode by default and mode accepts an encoding. This can be toggled off when creating the RomFSReader by passing open_compatibility_mode=False. This compatibility layer will be removed in a future release.

Parameters:
  • path (str) – Path to a file.

  • buffering (int) – Buffering policy (-1 to use default buffering, 0 to disable buffering, 1 to select line buffering, of any positive integer to indicate a buffer size).

  • encoding (str) – Encoding for text files (defaults to utf-8)

  • errors (Optional[str]) – What to do with unicode decode errors (see codecs module for more information).

  • newline (str) – Newline parameter.

Returns:

A file-like object.

Return type:

SubsectionIO

get_info_from_path(path)[source]

Deprecated since version 0.8.0: Use getinfo(), listdir(), or scandir() instead.

Parameters:

path (str) –

Returns:

Data classes

class pyctr.type.romfs.RomFSDirectoryEntry(name, type, contents)[source]
Parameters:
  • name (str) –

  • type (str) –

  • contents (Tuple[str, ...]) –

class pyctr.type.romfs.RomFSFileEntry(name, type, offset, size)[source]
Parameters:
  • name (str) –

  • type (str) –

  • offset (int) –

  • size (int) –

Exceptions

exception pyctr.type.romfs.RomFSError[source]

Generic exception for RomFS operations.

exception pyctr.type.romfs.InvalidIVFCError[source]

Invalid IVFC header exception.

exception pyctr.type.romfs.InvalidRomFSHeaderError[source]

Invalid RomFS Level 3 header.

exception pyctr.type.romfs.RomFSEntryError[source]

Error with RomFS Directory or File entry.

exception pyctr.type.romfs.RomFSFileNotFoundError(path, exc=None, msg=None)[source]

Invalid file path in RomFS Level 3.

Parameters:
  • path (Text) –

  • exc (Optional[Exception]) –

  • msg (Optional[Text]) –

Return type:

None

exception pyctr.type.romfs.RomFSIsADirectoryError(path, exc=None, msg=None)[source]

Attempted to open a directory as a file.

Parameters:
  • path (Text) –

  • exc (Optional[Exception]) –

  • msg (Optional[Text]) –

Return type:

None