#archive #squash-fs

squashfs_reader

Fully featured rust reader for the squashfs archive format

1 unstable release

Uses new Rust 2024

0.1.0 Jul 27, 2025

#2155 in Filesystem

MIT/Apache

94KB
2K SLoC

Squashfs_reader

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.

Dependencies

~2.8–5.5MB
~90K SLoC