20 releases (12 breaking)

0.13.0 Jan 27, 2026
0.12.1 Nov 8, 2025
0.12.0 Oct 14, 2025
0.11.0 Jul 27, 2025
0.1.0 Mar 20, 2017

#116 in Filesystem

Download history 300903/week @ 2025-10-17 316268/week @ 2025-10-24 294128/week @ 2025-10-31 302055/week @ 2025-11-07 303573/week @ 2025-11-14 291265/week @ 2025-11-21 299855/week @ 2025-11-28 337914/week @ 2025-12-05 349117/week @ 2025-12-12 282062/week @ 2025-12-19 248297/week @ 2025-12-26 372806/week @ 2026-01-02 427408/week @ 2026-01-09 426129/week @ 2026-01-16 481203/week @ 2026-01-23 426588/week @ 2026-01-30

1,835,765 downloads per month
Used in 58 crates (20 directly)

MIT license

245KB
5.5K SLoC

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.

rust-cfb

Build Status Crates.io Documentation

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

License

rust-cfb is made available under the MIT License.


lib.rs:

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();
    buffer
};

// Append that data to the end of another stream in the same file.
{
    let mut stream = comp.open_stream("/baz").unwrap();
    stream.seek(SeekFrom::End(0)).unwrap();
    stream.write_all(&data).unwrap();
}

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

Dependencies

~260–495KB