Crate squashfs_reader

Source
Expand description

Squashfs_reader is a rust crate offering full read-only access to squashfs archive files. It offers an api similar to std::io.

§Features

  • Pure Rust: Implementation of the entire SquashFS format specification.
  • Full Compression Support: All possible compression formats (gzip, lzma, xz, lzo, lz4, and zstd) are supported.
  • Thread Safety: This library is fully thread-safe.
  • Caching: All accessed metadata and data blocks are cached using quick_cache to prevent unnecessary decompressions. The cache size can be configured.
  • Familiar API: Directory iteration is supported with an API similar to std::fs::ReadDir, and files implement the std::io::Read and std::io::Seek traits.

§Example

use std::io;
use squashfs_reader::FileSystem;

fn main() -> io::Result<()> {
    // Open a SquashFS file
    let fs = FileSystem::from_path("example.squashfs")?;
     
    // List contents of root directory
    let root = fs.read_dir("/")?;
    for entry in root {
        println!("{}", entry?.name());
    }
     
    // Read a file
    let mut file = fs.open("path/to/file.txt")?;
    let file_size = file.seek(io::SeekFrom::End(0))?;
    file.rewind()?;

    let mut contents = String::new();
    file.read_to_string(&mut contents)?;
     
    Ok(())
}

§Compression and features

  • best_performance (default) - Uses external (non-Rust) libraries when they offer better performance (liblzma and zstd-safe).
  • only_rust- Only has Rust dependencies, but may offer lower performance when using some compression formats.

If both features are enabled, only_rust will be prioritized.

§Safety

This crate is entirely written in safe Rust (it uses #![forbid(unsafe_code)]). However, please note that some dependencies may contain unsafe code.

Structs§

DirEntry
Represent an entry in a folder
FileReader
Reader for a file in the squashfs filesystem
FileSystem
The Filesystem structure, this is used to interact with the content of the squashfs file. This is the entrypoint from the library. From there, one can use functions such as read_dir, metadata or open to search and open files inside the squashfs
Metadata
MetadataRef
In the SquashFS archive format, metadata entries (e.g. inodes) are often referenced using a 64 bit integer. The lower 16 bit hold an offset into the uncompressed block and the upper 48 bit point to the on-disk location of the block Relative to the start of the metadata entry (inodes, file listings…)
OpenOptions
Options which can be used to configure how a squashfs filesystem is opened So far only the cache size can be configured
ReadDir
Structure to iterate over files in a directory

Enums§

Compression
Compressor used for both data and meta data blocks
FileType
Different types of Files which can be stored in a squashfs

Type Aliases§

Error
Result