squashfs

package module
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2022 License: MIT Imports: 19 Imported by: 5

README

sylabs/squashfs (WIP)

PkgGoDev Go Report Card

This is a fork of CalebQ42/squashfs for the purpose of maintaing a package that removes the lzo dependency, so that it does not contain GPL code.

Branches

  • remove-lzo - main from CalebQ42/squashfs with LZO support removed.
  • remove-lzo-vX.Y.Z - vX.Y.Z from CalebQ42/squashfs with LZO support removed.

Tags

  • vX.Y.Z - vX.Y.Z from CalebQ42/squashfs with LZO support removed.

A PURE Go library to read and write squashfs.

Currently has support for reading squashfs files and extracting files and folders.

Special thanks to https://dr-emann.github.io/squashfs/ for some VERY important information in an easy to understand format. Thanks also to distri's squashfs library as I referenced it to figure some things out (and double check others).

TODO

Limitations

  • No Xattr parsing. This is simply because I haven't done any research on it and how to apply these in a pure go way.

Performance

This library, decompressing the Firefox AppImage and using go tests, takes about twice as long as unsquashfs on my quad core laptop. (~1 second with the library and about half a second with unsquashfs).

My recents tests have shown the Firefox AppImage might be an outlier and this library might be considerably slower (4x ~ 6x time slower then unsquashfs)

Documentation

Index

Constants

View Source
const (
	GZipCompression = uint16(iota + 1)
	LZMACompression
	LZOCompression
	XZCompression
	LZ4Compression
	ZSTDCompression
)

The types of compression supported by squashfs

Variables

View Source
var (
	ErrorMagic   = errors.New("magic incorrect. probably not reading squashfs archive")
	ErrorLog     = errors.New("block log is incorrect. possible corrupted archive")
	ErrorVersion = errors.New("squashfs version of archive is not 4.0")
)
View Source
var (
	ErrReadNotFile = errors.New("read called on non-file")
)

Functions

This section is empty.

Types

type ExtractionOptions

type ExtractionOptions struct {
	LogOutput          io.Writer   //Where error log should write. If nil, uses os.Stdout. Has no effect if verbose is false.
	DereferenceSymlink bool        //Replace symlinks with the target file
	UnbreakSymlink     bool        //Try to make sure symlinks remain unbroken when extracted, without changing the symlink
	Verbose            bool        //Prints extra info to log on an error
	FolderPerm         fs.FileMode //The permissions used when creating the extraction folder
}

ExtractionOptions are available options on how to extract.

func DefaultOptions

func DefaultOptions() ExtractionOptions

DefaultOptions is the default ExtractionOptions.

type FS

type FS struct {
	*File
	// contains filtered or unexported fields
}

FS is a fs.FS representation of a squashfs directory. Implements fs.GlobFS, fs.ReadDirFS, fs.ReadFileFS, fs.StatFS, and fs.SubFS

func (FS) Glob

func (f FS) Glob(pattern string) (out []string, err error)

Glob returns the name of the files at the given pattern. All paths are relative to the FS. Uses filepath.Match to compare names.

func (FS) Open

func (f FS) Open(name string) (fs.File, error)

Open opens the file at name. Returns a squashfs.File.

func (FS) ReadDir

func (f FS) ReadDir(name string) ([]fs.DirEntry, error)

ReadDir returns all the DirEntry returns all DirEntry's for the directory at name. If name is not a directory, returns an error.

func (FS) ReadFile

func (f FS) ReadFile(name string) ([]byte, error)

ReadFile returns the data (in []byte) for the file at name.

func (FS) Stat

func (f FS) Stat(name string) (fs.FileInfo, error)

Stat returns the fs.FileInfo for the file at name.

func (FS) Sub

func (f FS) Sub(dir string) (fs.FS, error)

Sub returns the FS at dir

type File

type File struct {
	// contains filtered or unexported fields
}

File represents a file inside a squashfs archive.

func (*File) Close

func (f *File) Close() error

Close simply nils the underlying reader. Here mostly to satisfy fs.File

func (f File) ExtractSymlink(folder string) error

ExtractSymlink extracts the File to the folder with the DereferenceSymlink option. If the File is a directory, it instead extracts the directory's contents to the folder.

func (File) ExtractTo

func (f File) ExtractTo(folder string) error

ExtractTo extracts the File to the given folder with the default options. If the File is a directory, it instead extracts the directory's contents to the folder.

func (File) ExtractWithOptions

func (f File) ExtractWithOptions(folder string, op ExtractionOptions) error

ExtractWithOptions extracts the File to the given folder with the given ExtrationOptions. If the File is a directory, it instead extracts the directory's contents to the folder.

func (*File) FS

func (f *File) FS() (*FS, error)

FS returns the File as a FS.

func (File) GetSymlinkFile

func (f File) GetSymlinkFile() *File

GetSymlinkFile returns the File the symlink is pointing to. If not a symlink, or the target is unobtainable (such as it being outside the archive or it's absolute) returns nil

func (File) IsDir

func (f File) IsDir() bool

IsDir Yep.

func (File) IsRegular

func (f File) IsRegular() bool

IsRegular yep.

func (f File) IsSymlink() bool

IsSymlink yep.

func (File) Read

func (f File) Read(p []byte) (int, error)

Read reads the data from the file. Only works if file is a normal file.

func (*File) ReadDir

func (f *File) ReadDir(n int) (out []fs.DirEntry, err error)

ReadDir returns n fs.DirEntry's that's contained in the File (if it's a directory). If n <= 0 all fs.DirEntry's are returned.

func (File) Stat

func (f File) Stat() (fs.FileInfo, error)

Stat returns the File's fs.FileInfo

func (File) SymlinkPath

func (f File) SymlinkPath() string

SymlinkPath returns the symlink's target path. Is the File isn't a symlink, returns an empty string.

func (File) WriteTo

func (f File) WriteTo(w io.Writer) (int64, error)

WriteTo writes all data from the file to the writer. This is multi-threaded. The underlying reader is seperate from the one used with Read and can be reused.

type Reader

type Reader struct {
	*FS
	// contains filtered or unexported fields
}

func NewReader

func NewReader(r io.ReaderAt) (*Reader, error)

Creates a new squashfs.Reader from the given io.ReaderAt.

func NewReaderFromReader

func NewReaderFromReader(r io.Reader) (*Reader, error)

Creates a new squashfs.Reader from the given io.Reader. NOTE: All data from the io.Reader will be read and stored in memory.

func (Reader) ModTime

func (r Reader) ModTime() time.Time

Returns the last time the archive was modified.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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