CFBReader

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.

from aspose.email_foss.cfb import CFBReader

with CFBReader.from_file("archive.cfb") as reader:
    print(f"sector_size={reader.sector_size}")
    for entry in reader.iter_storages():
        print(f"storage: {entry.name}")
    for entry in reader.iter_streams():
        data = reader.get_stream_data(entry.stream_id)
        print(f"stream: {entry.name}, {len(data)} bytes")

Class Methods

MethodReturnsDescription
from_file(path)CFBReaderOpens the CFB file at path and returns a ready-to-use CFBReader.

Properties

NameTypeDescription
data_sizeintTotal size of the data region in bytes.
major_versionintCFB major version number (3 or 4).
sector_sizeintSize of a single FAT sector in bytes.
mini_sector_sizeintSize of a mini-stream sector in bytes.
fat_sector_countintNumber of FAT sectors in the container.
directory_entry_countintTotal number of directory entries.
materialized_stream_countintNumber of streams loaded into memory.
file_sizeintTotal file size in bytes.

Methods

MethodReturnsDescription
close()NoneCloses the underlying file handle; called automatically when used as a context manager.
get_entry(stream_id)DirectoryEntryReturns the DirectoryEntry for the given stream_id.
get_stream_data(stream_id)bytesReturns 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