backhand/lib.rs
1//! Library and binaries for the reading, creating, and modification
2//! of [SquashFS](https://en.wikipedia.org/wiki/SquashFS) file systems.
3//!
4//! ## Library
5//! Add the following to your `Cargo.toml` file:
6//! ```toml
7//! [dependencies]
8//! backhand = "0.23.0"
9//! ```
10//!
11//! ### Reading
12//! For reading an image and extracting its details and contents, use
13//! [`FilesystemReader::from_reader`].
14//!
15//! ### Writing
16//! For creating a modified or new image, use [`FilesystemWriter::from_fs_reader`].
17//! [`FilesystemWriter`] can also be created from scratch, without a previous image to base itself
18//! on.
19//!
20//!### Example
21//!```rust,no_run
22//! # use std::fs::File;
23//! # use std::io::{Cursor, BufReader};
24//! # use backhand::{FilesystemReader, FilesystemWriter, NodeHeader};
25//! // read
26//! let file = BufReader::new(File::open("file.squashfs").unwrap());
27//! let read_filesystem = FilesystemReader::from_reader(file).unwrap();
28//!
29//! // convert to writer
30//! let mut write_filesystem = FilesystemWriter::from_fs_reader(&read_filesystem).unwrap();
31//!
32//! // add file with data from slice
33//! let d = NodeHeader::default();
34//! let bytes = Cursor::new(b"Fear is the mind-killer.");
35//! write_filesystem.push_file(bytes, "a/d/e/new_file", d);
36//!
37//! // add file with data from file
38//! let new_file = File::open("dune").unwrap();
39//! write_filesystem.push_file(new_file, "/root/dune", d);
40//!
41//! // replace a existing file
42//! let bytes = Cursor::new(b"The sleeper must awaken.\n");
43//! write_filesystem
44//! .replace_file("/a/b/c/d/e/first_file", bytes)
45//! .unwrap();
46//!
47//! // write into a new file
48//! let mut output = File::create("modified.squashfs").unwrap();
49//! write_filesystem.write(&mut output).unwrap();
50//! ```
51//!
52//! # Features
53#![cfg_attr(feature = "document-features", doc = document_features::document_features!())]
54#![cfg_attr(docsrs, feature(doc_cfg))]
55
56#[cfg(doctest)]
57#[doc = include_str!("../../README.md")]
58type _ReadmeTest = ();
59
60mod compressor;
61mod data;
62mod dir;
63mod entry;
64mod error;
65mod export;
66mod filesystem;
67mod fragment;
68mod id;
69mod inode;
70mod kinds;
71mod metadata;
72mod reader;
73mod squashfs;
74mod unix_string;
75
76pub use crate::data::DataSize;
77pub use crate::error::BackhandError;
78pub use crate::export::Export;
79pub use crate::filesystem::node::{
80 InnerNode, Node, NodeHeader, SquashfsBlockDevice, SquashfsCharacterDevice, SquashfsDir,
81 SquashfsFileReader, SquashfsFileWriter, SquashfsSymlink,
82};
83pub use crate::filesystem::reader::{FilesystemReader, FilesystemReaderFile};
84#[cfg(not(feature = "parallel"))]
85pub use crate::filesystem::reader_no_parallel::SquashfsReadFile;
86#[cfg(feature = "parallel")]
87pub use crate::filesystem::reader_parallel::SquashfsReadFile;
88pub use crate::filesystem::writer::{
89 CompressionExtra, ExtraXz, FilesystemCompressor, FilesystemWriter,
90};
91pub use crate::fragment::Fragment;
92pub use crate::id::Id;
93pub use crate::inode::{BasicFile, Inode};
94pub use crate::reader::BufReadSeek;
95pub use crate::squashfs::{
96 Flags, Squashfs, SuperBlock, DEFAULT_BLOCK_SIZE, DEFAULT_PAD_LEN, MAX_BLOCK_SIZE,
97 MIN_BLOCK_SIZE,
98};
99
100/// Support the wonderful world of vendor formats
101pub mod kind {
102 pub use crate::kinds::{Endian, Kind, Magic, AVM_BE_V4_0, BE_V4_0, LE_V4_0};
103}
104
105/// Compression Choice and Options
106pub mod compression {
107 pub use crate::compressor::{
108 CompressionAction, CompressionOptions, Compressor, DefaultCompressor, Gzip, Lz4, Lzo, Xz,
109 Zstd,
110 };
111}