squash

package
v0.5.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 27, 2024 License: MIT, MIT Imports: 17 Imported by: 0

README

squashfs

This is a read-only implementation of squashfs that conforms to the io/fs interfaces.

Example use

package main

import (
	"os"
	"net/http"
	"gitlab.com/rackn/squashfs"
)

func main() {
	fi, _ := os.Open("file.squashfs")
	sqfs, _ := squashfs.Open(fi)
	// sqfs is a regular fs.FS

	http.Handle("/", http.FileServer(http.FS(sqfs)))
	// etc...
}

You can find more looking at the test file.

File format

Some documentation is available online on SquashFS.

TODO

  • Access to directories do not currently use indexes and can be slow for random file accesses in very large directories.
  • A block caching scheme is needed to handle high-traffic sections of the file. That could be fun.

Documentation

Index

Constants

View Source
const (
	DirType inoType = iota + 1
	FileType
	SymlinkType
	BlockDevType
	CharDevType
	FifoType
	SocketType
	XDirType
	XFileType
	XSymlinkType
	XBlockDevType
	XCharDevType
	XFifoType
	XSocketType
)

Variables

View Source
var (
	ErrInvalidFile    = errors.New("invalid file, squashfs signature not found")
	ErrInvalidSuper   = errors.New("invalid squashfs superblock")
	ErrInvalidVersion = errors.New("invalid file version, expected squashfs 4.0")
)

Functions

func Open

func Open(fs io.ReaderAt) (res c.Filesystem, err error)

Open returns a new instance of squashFs for a given io.ReaderAt that can be used to access files inside squashfs.

func RegisterDecompressor

func RegisterDecompressor(method Compression, dcomp Decompressor)

RegisterDecompressor can be used to register a Decompressor for squashfs. GZip and ZSTD are supported by default. You can register additional decompressor types before opening squashfs archives that use them. Once registered, decompressors cannot be deregistered, only replaced.

Types

type Compression

type Compression uint16

Compression tracks what type of compression a squashfs is using. We support all known formats except LZO to a greater or lesser degree of efficiency. right now, zstd will be the most performant, followed by zlib. LZO is excluded due to the only Go native implementation being GPL licensed.

const (
	GZip Compression = iota + 1 // GZip is compatible with darn near everything, but is neither the fastest or smallest compression.
	LZMA                        // LZMA decompressors are bloated and slow, avoid.
	LZO                         // LZO is not available due to GPL entanglements.
	XZ                          // XZ has good compression, but it isnt the fastest decompression around.
	LZ4                         // LZ4 has fast decompression, but is by far the least space efficient.
	ZSTD                        // ZSTD has excellent decompression speed and good compression ratios.
)

func (Compression) String

func (s Compression) String() string

type Decompressor

type Decompressor func([]byte, []byte) ([]byte, error)

Decompressor takes an input buffer and a destination buffer and returns the destination buffer filled with data and an error It matches the function signature of github.com/klauspost/compress/zstd Reader.DecodeAll. The library internals will eventually leverage it to optimize buffer reuse and caching.

func MakeDecompressor

func MakeDecompressor(dec func(r io.Reader) io.Reader) Decompressor

func MakeDecompressorErr

func MakeDecompressorErr(dec func(r io.Reader) (io.Reader, error)) Decompressor

MakeDecompressorErr is similar to MakeDecompressor but the factory method also returns an error.

Example use: * squashfs.RegisterDecompressor(squashfs.LZMA, squashfs.MakeDecompressorErr(lzma.NewReader)) * squashfs.RegisterDecompressor(squashfs.XZ, squashfs.MakeDecompressorErr(xz.NewReader))

type Flags

type Flags uint16
const (
	UNCOMPRESSED_INODES Flags = 1 << iota
	UNCOMPRESSED_DATA
	CHECK
	UNCOMPRESSED_FRAGMENTS
	NO_FRAGMENTS
	ALWAYS_FRAGMENTS
	DUPLICATES
	EXPORTABLE
	UNCOMPRESSED_XATTRS
	NO_XATTRS
	COMPRESSOR_OPTIONS
	UNCOMPRESSED_IDS
)

func (Flags) Has

func (f Flags) Has(what Flags) bool

func (Flags) String

func (f Flags) String() string

type SysStat

type SysStat struct {
	Mode     fs.FileMode
	Nlink    uint32
	Ino      uint32
	Uid, Gid uint32
	Mtime    time.Time
	Size     int64
	Blocks   int64
	Blksize  int64
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL