Crate cramfs

Crate cramfs 

Source
Expand description

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);
    }
}

Structs§

Cramfs
Read-only access to cramfs filesystem.
DirEntry
Directory entry
ReadDir
Iterator over each DirEntry in a directory inode.