squashfs

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2020 License: MIT Imports: 12 Imported by: 4

README

squashfs PkgGoDev

A PURE Go library to read and write squashfs.

Currently, you can read a squashfs and extract files (folder extraction not supported. Yet).

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

Where I'm at

  • Working on the File interface that should make it easier to deal with squashfs files. I'm also trying to make them capable for when I get squashing working.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	//ErrBrokenSymlink is returned when using ExtractWithOptions with the unbreakSymlink set to true, but the symlink's file cannot be extracted.
	ErrBrokenSymlink = errors.New("Extracted symlink is probably broken")
)

Functions

This section is empty.

Types

type File added in v0.2.0

type File struct {
	Name   string    //The name of the file or folder. Root folder will not have a name ("")
	Parent *File     //The parent directory. Should ALWAYS be a folder. If it's the root directory, will be nil
	Reader io.Reader //Underlying reader. When writing, will probably be an os.File. When reading this is kept nil UNTIL reading to save memory.
	// contains filtered or unexported fields
}

File is the main way to interact with files within squashfs, or when putting files into a squashfs. File can be either a file or folder. When reading from a squashfs, it reads from the datablocks. When writing, this holds the information on WHERE the file will be placed inside the archive.

func (*File) Close added in v0.2.0

func (f *File) Close() error

Close frees up the memory held up by the underlying reader. Should NOT be called when writing. When reading, Close is safe to use, but any subsequent Read calls resets to the beginning of the file.

func (*File) ExtractTo added in v0.3.0

func (f *File) ExtractTo(path string) []error

ExtractTo extracts the file to the given path. This is the same as ExtractWithOptions(path, false, os.ModePerm, false). Will NOT try to keep symlinks valid, folders extracted will have the permissions set by the squashfs, but the folder to make path will have full permissions (777).

Will try it's best to extract all files, and if any errors come up, they will be appended to the error slice that's returned.

func (*File) ExtractWithOptions added in v0.3.0

func (f *File) ExtractWithOptions(path string, unbreakSymlink bool, folderPerm os.FileMode, verbose bool) (errs []error)

ExtractWithOptions will extract the file to the given path, while allowing customization on how it works. ExtractTo is the "default" options. Will try it's best to extract all files, and if any errors come up, they will be appended to the error slice that's returned. Should only return multiple errors if extracting a folder.

If unbreakSymlink is set, it will also try to extract the symlink's associated file. WARNING: the symlink's file may have to go up the directory to work. If unbreakSymlink is set and the file cannot be extracted, a ErrBrokenSymlink will be appended to the returned error slice.

folderPerm only applies to the folders created to get to path. Folders from the archive are given the correct permissions defined by the archive.

func (*File) GetChildren added in v0.2.0

func (f *File) GetChildren() (children []*File, err error)

GetChildren returns a *squashfs.File slice of every direct child of the directory. If the File is not a directory, will return ErrNotDirectory

func (*File) GetChildrenRecursively added in v0.2.0

func (f *File) GetChildrenRecursively() (children []*File, err error)

GetChildrenRecursively returns ALL children. Goes down ALL folder paths.

func (*File) GetFileAtPath added in v0.2.1

func (f *File) GetFileAtPath(dirPath string) *File

GetFileAtPath tries to return the File at the given path, relative to the file. Returns nil if called on something other then a folder, OR if the path goes oustide the archive. Allows wildcards supported by path.Match (namely * and ?).

func (*File) GetSymlinkFile added in v0.2.1

func (f *File) GetSymlinkFile() *File

GetSymlinkFile tries to return the squashfs.File associated with the symlink

func (*File) IsDir added in v0.2.0

func (f *File) IsDir() bool

IsDir returns if the file is a directory.

func (*File) IsFile added in v0.3.0

func (f *File) IsFile() bool

IsFile returns if the file is a file.

func (f *File) IsSymlink() bool

IsSymlink returns if the file is a symlink.

func (*File) Path added in v0.2.0

func (f *File) Path() string

Path returns the path of the file within the archive.

func (*File) Permission added in v0.3.0

func (f *File) Permission() os.FileMode

Permission returns the os.FileMode of the File. Sets mode bits for directories and symlinks.

func (*File) Read added in v0.2.0

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

Read from the file. Doesn't do anything fancy, just pases it to the underlying io.Reader. If a directory, return io.EOF.

func (*File) SymlinkPath added in v0.2.1

func (f *File) SymlinkPath() string

SymlinkPath returns the path the symlink is pointing to. If the file ISN'T a symlink, will return an empty string. If a path begins with "/" then the symlink is pointing to an absolute path (starting from root, and not a file inside the archive)

type Reader

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

Reader processes and reads a squashfs archive.

func NewSquashfsReader

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

NewSquashfsReader returns a new squashfs.Reader from an io.ReaderAt

func (*Reader) FindAll added in v0.2.0

func (r *Reader) FindAll(query func(*File) bool) (all []*File)

FindAll returns all files where the given function returns true.

func (*Reader) FindFile added in v0.2.0

func (r *Reader) FindFile(query func(*File) bool) *File

FindFile returns the first file (in the same order as Reader.GetAllFiles) that the given function returns true for. Returns nil if nothing is found.

func (*Reader) GetAllFiles added in v0.2.0

func (r *Reader) GetAllFiles() (fils []*File, err error)

GetAllFiles returns a slice of ALL files and folders contained in the squashfs.

func (*Reader) GetFileAtPath added in v0.2.0

func (r *Reader) GetFileAtPath(path string) *File

GetFileAtPath will return the file at the given path. If the file cannot be found, will return nil.

func (*Reader) GetRootFolder added in v0.2.0

func (r *Reader) GetRootFolder() (root *File, err error)

GetRootFolder returns a squashfs.File that references the root directory of the squashfs archive.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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