python-cabarchive¶
- class cabarchive.CabArchive(buf: Optional[bytes] = None, flattern: bool = False)¶
Bases:
dictThis instance allows parsing or writing a MS Cabinet archive.
You can treat the CabArchive instance like a dictionary when reading and writing archives.
For instance, loading an archive:
with open("test.cab", "rb") as f: arc = CabArchive(f.read()) cff = arc["test.txt"] print("filename", cff.filename) # "test.txt" print("contents", cff.buf) # b"test123" print("created", cff.date.year) # 2015 for fn in arc: print(fn) # "test.txt"
…or creating and saving an archive:
arc = CabArchive() arc["test.txt"] = CabFile("test123".encode()) with open("test.cab", "wb") as f: f.write(arc.save())
- find_file(glob: str) Optional[cabarchive.file.CabFile]¶
Gets a file from the archive using a glob.
- Args:
self: A CabArchive instance. glob: File glob, e.g.
*.txt- Returns:
The first CabFile that matches the filename glob, or None.
- find_files(glob: str) List[cabarchive.file.CabFile]¶
Gets files from the archive using a glob.
- Args:
self: A CabArchive instance. glob: File glob, e.g.
*.txt- Returns:
All CabFile object that matches the filename glob, or None.
- parse(buf: bytes) None¶
Parse .cab binary data
- Args:
self: A CabArchive instance. bytes: Binary blob loaded from disk.
- Raises:
CorruptionError: The cab file was invalid or corrupt. NotSupportedError: The format was not supported, e.g. unknown compression.
- save(compress: bool = False, sort: bool = True) bytes¶
Returns cabinet file data, optionally compressed
- Args:
self: A CabArchive instance. compress: If the binary data should be compressed. sort: If the file lists should be sorted in a predictable order
- Returns:
The blob of memory that can be written to disk.
- set_id: int¶
The “Set ID” used for multi-file archives
- class cabarchive.CabFile(buf: Optional[bytes] = None, filename: Optional[str] = None, mtime: Optional[datetime.datetime] = None)¶
Bases:
objectAn object representing a file in a Cab archive
Any number of CabFile instances can be stored in a CabArchive. A new instance can be created with just the data bytes or with an additional
mtime. If the modification time is not set then the current date and time is used, which may be unhelpful if you require a reproducable builds.cff = CabFile(b"test123")
- buf¶
bytes to use for the file contents
- date: Optional[datetime.date]¶
date the file was created
- property filename: Optional[str]¶
filename to use in the archive
- is_arch¶
set if file modified since last backup
- is_exec¶
set if file is executable
set if file is hidden
- is_readonly¶
set if file is read-only
- is_system¶
set if file is a system file
- time: Optional[datetime.time]¶
time the file was created
- exception cabarchive.CorruptionError¶
Bases:
Exception
- exception cabarchive.NotSupportedError¶
Bases:
Exception