1 unstable release
Uses new Rust 2024
new 0.1.0 | Mar 15, 2025 |
---|
#613 in Filesystem
30KB
665 lines
Cramfs
This crate can access cramfs filesystem in read-only mode.
Example
see examples
folder for more details
License
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
lib.rs
:
This crate can access cramfs filesystem in read-only mode.
The main entry point is the Cramfs
struct, which can be created from a file or a reader.
Example
This example opens a cramfs file and extract the files into a directory.
use cramfs::{Cramfs, DirEntry};
use std::{fs::File, path::Path};
fn main() {
let path = std::env::args().skip(1).next();
let Some(path) = path else {
println!("need a path to a cramfs file");
return;
};
let folder = Path::new(&path).parent().unwrap();
let cramfs = Cramfs::from_file(&path).unwrap();
let root = cramfs.root().unwrap();
walk(root, folder);
}
fn walk(mut entry: DirEntry<File>, folder: &Path) {
if entry.is_dir() {
println!("{}", entry.path().display());
let rd = entry.read_dir().unwrap();
for entry in rd {
let entry = entry.unwrap();
walk(entry, folder);
}
} else if entry.is_file() {
println!("{}", entry.path().display());
let mut file = File::create(folder.join(entry.path())).unwrap();
entry.read_file(&mut file).unwrap();
} else if entry.is_symlink() {
let target = entry.read_symlink().unwrap();
println!("{} -> {}", entry.path().display(), target);
}
}
Dependencies
~2.5MB
~52K SLoC