#archive #archive-compression

dwarfs

A library for reading DwarFS archives (aka. DwarFS images)

4 releases (2 breaking)

Uses new Rust 2024

0.2.1 Jun 9, 2025
0.2.0 May 26, 2025
0.1.0 May 22, 2025
0.0.0 May 12, 2025

#459 in Compression

Download history 6/week @ 2025-10-14 99/week @ 2025-12-23 59/week @ 2025-12-30 70/week @ 2026-01-06 321/week @ 2026-01-13 112/week @ 2026-01-20 56/week @ 2026-01-27

571 downloads per month
Used in 6 crates (2 directly)

MIT/Apache

190KB
4K SLoC

dwarfs

crates.io docs.rs

A library for reading DwarFS archives (aka. DwarFS images).

See documentations for more details.

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

lib.rs:

A library for reading DwarFS archives (aka. images).

Currently, DwarFS filesystem version 2.3..=2.5 is supported, which should be compatible with files generated by upstream mkdwarfs v0.5.0..=v0.12.4 (latest at the time of writing). Other versions may also be readable but are not guaranteed.

use dwarfs::{Archive, ArchiveIndex, AsChunks};
use std::fs::File;

// Open an archive file and load the metadata of it.
let file = File::open("./my.dwarfs")?;
let (index, mut archive) = Archive::new(file)?;

// Hierarchy traversal.
for entry in index.root().entries() {
    let inode = entry.inode();
    println!("/{} mode={}", entry.name(), inode.metadata().file_type_mode());
    if let Some(deep) = inode.as_dir() {
        for entry in deep.entries() {
            // ...
        }
    }
}

// Resolve paths.
let file: dwarfs::File = index.get_path(["src", "Cargo.toml"])
    .expect("does not exist")
    .as_file()
    .expect("not a file");
// The simple way to read content.
let bytes: Vec<u8> = file.read_to_vec(&mut archive)?;

Cargo features

  • zstd, lzma, lz4 (Only zstd is enabled by default)

    Enable relevant decompression algorithm support. zstd is the default compression algorithm mkdwarfs uses and it should be enough for most cases.

  • log (Enabled by default)

    Enable trace-level logging and time measurement for internal events via log crate. Useful for profiling or debugging. Should not have performance penalty unless trace-level log is enabled.

  • serialize (Disabled by default)

    Enable serialization support for various structures. It enables:

Dependencies

~3.5–6.5MB
~100K SLoC