Overview
CFBReader provides low-level, read-only access to a Compound File Binary (CFB) container. It exposes the sector layout, directory tree, and raw stream bytes without loading the entire file into memory. CFBReader implements the context-manager protocol; always use it inside a with block to ensure file handles are released correctly.
Obtain an instance via the from_file class method and navigate the directory tree using iter_storages, iter_streams, or iter_tree.
Class Methods
| Method | Returns | Description |
|---|
from_file(path) | CFBReader | Opens the CFB file at path and returns a ready-to-use CFBReader. |
Properties
| Name | Type | Description |
|---|
data_size | int | Total size of the data region in bytes. |
major_version | int | CFB major version number (3 or 4). |
sector_size | int | Size of a single FAT sector in bytes. |
mini_sector_size | int | Size of a mini-stream sector in bytes. |
fat_sector_count | int | Number of FAT sectors in the container. |
directory_entry_count | int | Total number of directory entries. |
materialized_stream_count | int | Number of streams loaded into memory. |
file_size | int | Total file size in bytes. |
Methods
| Method | Returns | Description |
|---|
close() | None | Closes the underlying file handle; called automatically when used as a context manager. |
get_entry(stream_id) | DirectoryEntry | Returns the DirectoryEntry for the given stream_id. |
get_stream_data(stream_id) | bytes | Returns the raw bytes of the stream identified by stream_id. |
iter_storages() | Iterator[DirectoryEntry] | Iterates over all STORAGE_OBJECT entries in the directory tree. |
iter_streams() | Iterator[DirectoryEntry] | Iterates over all STREAM_OBJECT entries in the directory tree. |
iter_children(storage_stream_id) | Iterator[DirectoryEntry] | Iterates over the immediate children of the given storage entry. |
iter_tree(start_stream_id) | Iterator[Tuple[int, DirectoryEntry]] | Depth-first traversal yielding (depth, entry) tuples from start_stream_id. |
find_child_by_name(storage_stream_id, name) | Optional[DirectoryEntry] | Returns the first child of the given storage whose name matches name, or None. |
resolve_path(names, start_stream_id) | Optional[DirectoryEntry] | Resolves a sequence of names as a path from start_stream_id; returns None if not found. |
See Also