### Read and Write SquashFS Filesystem Example Source: https://docs.rs/backhand/0.25.1/src/backhand/lib.rs.html This example demonstrates reading an existing SquashFS image, converting it to a writer, adding new files, replacing an existing file, and writing the modified filesystem to a new file. Ensure you have a file named 'file.squashfs' and 'dune' to run this example. ```rust # use std::fs::File; # use std::io::{Cursor, BufReader}; # use backhand::{FilesystemReader, FilesystemWriter, NodeHeader}; // read let file = BufReader::new(File::open("file.squashfs").unwrap()); let read_filesystem = FilesystemReader::from_reader(file).unwrap(); // convert to writer let mut write_filesystem = FilesystemWriter::from_fs_reader(&read_filesystem).unwrap(); // add file with data from slice let d = NodeHeader::default(); let bytes = Cursor::new(b"Fear is the mind-killer."); write_filesystem.push_file(bytes, "a/d/e/new_file", d); // add file with data from file let new_file = File::open("dune").unwrap(); write_filesystem.push_file(new_file, "/root/dune", d); // replace a existing file let bytes = Cursor::new(b"The sleeper must awaken.\n"); write_filesystem .replace_file("/a/b/c/d/e/first_file", bytes) .unwrap(); // write into a new file let mut output = File::create("modified.squashfs").unwrap(); write_filesystem.write(&mut output).unwrap(); ``` -------------------------------- ### FilesystemReader Usage Example Source: https://docs.rs/backhand/0.25.1/backhand/v3/filesystem/reader/struct.FilesystemReader.html Example demonstrating how to extract files using FilesystemReader. ```APIDOC ## Example Usage of FilesystemReader ### Description This example shows how to iterate through files in a filesystem and extract them using `FilesystemReaderFile`. ### Method N/A (Illustrative Example) ### Endpoint N/A ### Parameters N/A ### Request Example ```rust // [snip: creating FilesystemReader] for node in filesystem.files() { // extract match &node.inner { InnerNode::File(file) => { let mut reader = filesystem .file(&file) .reader(); // Then, do something with the reader }, _ => (), } } ``` ### Response N/A ```