#archive #image

dwarfs

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

2 unstable releases

Uses new Rust 2024

new 0.1.0 May 22, 2025
0.0.0 May 12, 2025

#79 in #archive

Download history 142/week @ 2025-05-11 111/week @ 2025-05-18

253 downloads per month

MIT/Apache

150KB
3K SLoC

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.


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.

Dependencies

~6–8.5MB
~138K SLoC