/** * OLE2/CFB (Compound File Binary) Container Reader * * Pure TypeScript implementation of the OLE2 (also known as Compound File Binary or * Structured Storage) container format used by legacy Microsoft Office files (.doc, .xls, .ppt). * * Ported from the algorithms in: * - ref/olefile/olefile/olefile.py (BSD-2 license, Python OLE2 parser) * - Microsoft [MS-CFB] specification * * The OLE2 format is essentially a filesystem-within-a-file. It contains: * - A 512-byte header with FAT sector locations * - A FAT (File Allocation Table) mapping sector chains * - A directory of named streams (like files in a filesystem) * - A mini-FAT for streams smaller than 4096 bytes * - The actual stream data stored across linked sectors * * @module ole2 */ /// /** Represents a directory entry in the OLE2 container */ export interface OLE2DirectoryEntry { /** Entry name (decoded from UTF-16LE) */ name: string; /** Entry type: 0=empty, 1=storage, 2=stream, 5=root */ entryType: number; /** Index of left sibling in red-black tree */ leftSibling: number; /** Index of right sibling in red-black tree */ rightSibling: number; /** Index of child node (for storages/root) */ child: number; /** First sector of this stream's data */ startSector: number; /** Stream size in bytes */ size: number; /** Stream ID (index in directory array) */ sid: number; } /** Parsed OLE2 container providing stream access */ export interface OLE2Container { /** All directory entries */ entries: OLE2DirectoryEntry[]; /** Get a named stream's data. Throws if not found. */ getStream(name: string): Buffer; /** Check if a named stream exists */ hasStream(name: string): boolean; /** List all stream names (type=2) in the container */ listStreams(): string[]; /** Get the sector size (512 or 4096) */ sectorSize: number; } /** * Parse an OLE2/CFB container from a buffer. * * @param data - Buffer containing the OLE2 file * @returns An OLE2Container providing access to named streams * @throws Error if the file is not a valid OLE2 container */ export declare function parseOLE2(data: Buffer): OLE2Container; /** * Check if a buffer starts with OLE2 magic bytes. * Useful for quick format detection before full parsing. */ export declare function isOLE2(data: Buffer | Uint8Array): boolean; /** * Detect the specific Office format inside an OLE2 container by examining * its directory entries. Returns 'doc', 'xls', or 'ppt' (or undefined if unknown). */ export declare function detectOLE2Format(container: OLE2Container): 'doc' | 'xls' | 'ppt' | undefined;