#cfb #storage #structured

cfb

Read/write Compound File Binary (structured storage) files

11 releases (6 breaking)

new 0.7.2 Jun 27, 2022
0.7.0 May 8, 2022
0.6.1 Sep 29, 2021
0.4.0 Nov 23, 2020
0.1.0 Mar 20, 2017

#65 in Filesystem

Download history 7551/week @ 2022-03-08 7011/week @ 2022-03-15 8977/week @ 2022-03-22 8941/week @ 2022-03-29 8062/week @ 2022-04-05 7145/week @ 2022-04-12 8965/week @ 2022-04-19 8009/week @ 2022-04-26 9618/week @ 2022-05-03 10594/week @ 2022-05-10 12625/week @ 2022-05-17 15240/week @ 2022-05-24 23139/week @ 2022-05-31 23349/week @ 2022-06-07 25131/week @ 2022-06-14 23139/week @ 2022-06-21

97,287 downloads per month
Used in 10 crates (3 directly)

MIT license

200KB
4.5K SLoC

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.

Documentation: https://mdsteele.github.io/rust-cfb/

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

~310KB