#storage #structured


Read/write Compound File Binary (structured storage) files

15 releases (8 breaking)

0.9.0 Oct 24, 2023
0.8.1 Jun 20, 2023
0.8.0 May 29, 2023
0.7.3 Jul 5, 2022
0.1.0 Mar 20, 2017

#129 in Filesystem

Download history 71863/week @ 2023-08-21 70376/week @ 2023-08-28 71225/week @ 2023-09-04 74005/week @ 2023-09-11 77527/week @ 2023-09-18 77760/week @ 2023-09-25 83986/week @ 2023-10-02 83327/week @ 2023-10-09 90855/week @ 2023-10-16 88269/week @ 2023-10-23 98542/week @ 2023-10-30 90143/week @ 2023-11-06 89676/week @ 2023-11-13 76951/week @ 2023-11-20 99068/week @ 2023-11-27 90591/week @ 2023-12-04

362,238 downloads per month
Used in 26 crates (8 directly)

MIT license


Contains (Cab file, 17KB) loop_in_chain, (Cab file, 17KB) tests/panics_fuzzed/alloc_panic, (Cab file, 17KB) tests/panics_fuzzed/minialloc_panic, (Cab file, 15KB) loop_in_alloc, (Cab file, 14KB) loop_in_directory, (Cab file, 15KB) loop_in_minialloc and 3 more.


Build Status Crates.io Documentation

A Rust library for reading/writing Compound File Binary (structured storage) files. See MS-CFB for the format specification.


rust-cfb is made available under the MIT License.


A library for reading/writing Compound File Binary (structured storage) files. See MS-CFB for the format specification.

A Compound File Binary (CFB) file, also called a structured storage file or simply a compound file, is a bit like a simple file system within a file. A compound file contains a tree of storage objects (i.e. directories), each of which can contain stream objects (i.e. files) or other storage objects. The format is designed to allow reasonably efficient in-place mutation and resizing of these stream and storage objects, without having to completely rewrite the CFB file on disk.

Example usage

use cfb;
use std::io::{Read, Seek, SeekFrom, Write};

// Open an existing compound file in read-write mode.
let mut comp = cfb::open_rw("path/to/cfb/file").unwrap();

// Read in all the data from one of the streams in that compound file.
let data = {
    let mut stream = comp.open_stream("/foo/bar").unwrap();
    let mut buffer = Vec::new();
    stream.read_to_end(&mut buffer).unwrap();

// Append that data to the end of another stream in the same file.
    let mut stream = comp.open_stream("/baz").unwrap();

// Now create a new compound file, and create a new stream with the data.
let mut comp2 = cfb::create("some/other/path").unwrap();
let mut stream = comp2.create_stream("/spam/eggs").unwrap();