C64Archive Class Overview
High-level API for working with C64 Archives.
- class c64os_util.car.archive.C64Archive(archive_type: CarArchiveType = CarArchiveType.GENERAL, timestamp: datetime = datetime.datetime(2023, 7, 6, 22, 34, 27, 878826), note: str = '')
A
C64Archiverepresents a deserialized, in-memory, editable archive. It provides fields and methods for easily creating and deleting files and folders, and for reading and writing the contents of files.- static deserialize(buffer: BinaryIO) C64Archive
Read binary data from a buffer and parse it into an archive object.
- Parameters:
buffer – The buffer from which to read.
- Returns:
The parsed archive object.
- property header: ArchiveHeader
Get the header (metadata) of the archive.
- Returns:
The header.
- ls(path: str, sep: str = '/')
Find the record (file or directory) at the given path.
- Parameters:
path – A path-like string representing the record’s location within the archive.
sep – The character used as a path separator (usually ‘/’ or ‘').
- Returns:
The requested record.
- mkdir(path: str, sep: str = '/', create_missing: bool = False, exists_ok: bool = False)
Create a directory at the given path.
- Parameters:
path – A path-like string representing the record’s location within the archive.
sep – The character used as a path separator (usually ‘/’ or ‘').
- Create_missing:
Create the parent directories if they do not exist.
- Exists_ok:
Do not throw an error if the directory already exists.
- Returns:
The newly created directory record.
- rm(path: str, sep: str = '/', missing_ok: bool = False, recursive: bool = False)
Remove the record (file or directory) at the given path.
- Parameters:
path – A path-like string representing the record’s location within the archive.
sep – The character used as a path separator (usually ‘/’ or ‘').
missing_ok – Do not throw an error if the record is missing.
recursive – Delete directories and their contents recursively.
- property root: ArchiveRecord | None
Get the root record of the archive.
- Returns:
The root record.
- serialize(buffer: BinaryIO)
Convert this archive into binary data and write it to a buffer.
- Parameters:
buffer – The buffer into which to write.
- touch(path: str, sep: str = '/', file_type: CarRecordType = CarRecordType.SEQFILE, compression_type: CarCompressionType = CarCompressionType.NONE, create_directories: bool = False, buffer: BinaryIO | None = None)
Create a file at the given path.
- Parameters:
path – A path-like string representing the record’s location within the archive.
sep – The character used as a path separator (usually ‘/’ or ‘').
- File_type:
The file type for the new file.
- Compression_type:
The compression type for the new file.
- Create_directories:
Create the parent directories if they do not exist.
- Buffer:
If provided, the contents of this buffer will be written to the file.
- Returns:
The newly created file record.
- walk()
A generator which visits each directory in the archive (in order, recursively).
- Returns:
The directory’s path (represented as a list) and the directory record itself.