CfbWriter

Overview

CfbWriter serializes a CfbDocument into a valid Compound File Binary file. Call ToBytes to obtain the serialized content as a byte array, or WriteFile to write directly to disk. The internal Serialize method builds the FAT, DIFAT, mini-FAT, and directory sectors according to the MS-CFB specification. Constructors are used internally by the writer to represent entry records and sector chains.

Constructors

SignatureDescription
Serializer(document: CfbDocument)Creates a new CfbWriter with the specified parameters.
EntryRecord(streamId: uint, name: string, objectType: DirectoryObjectType, clsid: byte[], stateBits: uint, creationTime: ulong, modifiedTime: ulong)Creates a new CfbWriter with the specified parameters.
Chain(payload: byte[])Creates a new CfbWriter with the specified parameters.

Methods

SignatureDescription
ToBytes(document: CfbDocument)Serializes document to a CFB-compliant byte array.
WriteFile(document: CfbDocument, path: string)Serializes document and writes it to the file at path.
Serialize()Performs the internal CFB layout: allocates FAT sectors, builds directory entries, and returns the complete binary.

Properties

NameTypeAccessDescription
StreamIduintReadZero-based directory index assigned to this entry record.
NamestringReadUTF-16LE entry name as it will appear in the CFB directory.
ObjectTypeDirectoryObjectTypeReadThe DirectoryObjectType value encoded in this entry’s object-type byte.
Clsidbyte[]Read16-byte CLSID written to this entry’s CLSID field.
StateBitsuintReadApplication-defined state bits written to this entry.
CreationTimeulongReadCreation timestamp (FILETIME) written to this entry.
ModifiedTimeulongReadModification timestamp (FILETIME) written to this entry.
StreamDatabyte[]ReadPayload bytes for stream-type entries (empty for storage-type entries).
ChildrenList<EntryRecord>ReadOrdered list of child EntryRecord entries for storage-type nodes.
ColorFlagDirectoryColorFlagReadRed-black tree color written to this entry’s directory record.
LeftSiblingIduintReadStream ID of the left sibling in the red-black tree.
RightSiblingIduintReadStream ID of the right sibling in the red-black tree.
ChildIduintReadStream ID of the first child entry (for storage-type nodes).
StartingSectorLocationuintReadFirst FAT sector index for this stream’s data.
StreamSizeulongReadSize in bytes of the stream’s data payload.
IsRootboolReadTrue if this entry is the root storage entry (stream ID 0).
IsStorageboolReadTrue if this entry is a storage container.
IsStreamboolReadTrue if this entry is a data stream.
Payloadbyte[]ReadThe complete serialized bytes of this entry (used internally by the chain builder).
SectorsList<uint>ReadOrdered list of FAT sector indices allocated to this entry’s data.
FirstSectoruintReadIndex of the first FAT sector allocated to this entry’s data.

See Also