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
571 downloads per month
Used in 6 crates
(2 directly)
190KB
4K
SLoC
dwarfs
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(Onlyzstdis enabled by default)Enable relevant decompression algorithm support.
zstdis the default compression algorithmmkdwarfsuses and it should be enough for most cases. -
log(Enabled by default)Enable trace-level logging and time measurement for internal events via
logcrate. 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