Documentation ¶
Index ¶
- Constants
- Variables
- type File
- func (f *File) ExtractSymlink(path string) []error
- func (f *File) ExtractTo(path string) []error
- func (f *File) ExtractWithOptions(path string, dereferenceSymlink, unbreakSymlink bool, folderPerm os.FileMode, ...) (errs []error)
- func (f *File) GetChildren() (children []*File, err error)
- func (f *File) GetChildrenRecursively() (children []*File, err error)
- func (f *File) GetFileAtPath(dirPath string) *File
- func (f *File) GetSymlinkFile() *File
- func (f *File) GetSymlinkFileRecursive() *File
- func (f *File) IsDir() bool
- func (f *File) IsFile() bool
- func (f *File) IsSymlink() bool
- func (f *File) ModTime() time.Time
- func (f *File) Mode() os.FileMode
- func (f *File) Name() string
- func (f *File) Path() string
- func (f *File) Read(p []byte) (int, error)
- func (f *File) Size() int64
- func (f *File) SymlinkPath() string
- func (f *File) Sys() interface{}
- type Reader
- func (r *Reader) ExtractTo(path string) []error
- func (r *Reader) FindAll(query func(*File) bool) (all []*File)
- func (r *Reader) FindFile(query func(*File) bool) *File
- func (r *Reader) GetAllFiles() (fils []*File, err error)
- func (r *Reader) GetFileAtPath(path string) *File
- func (r *Reader) GetRootFolder() (root *File, err error)
- func (r *Reader) ModTime() time.Time
- type Writer
- func (w *Writer) AddFile(file *os.File) error
- func (w *Writer) AddFileTo(filepath string, file *os.File) error
- func (w *Writer) AddFileToFolder(folder string, file *os.File) error
- func (w *Writer) AddReaderTo(filepath string, reader io.Reader) error
- func (w *Writer) FixSymlinks() error
- func (w *Writer) Remove(filepath string) bool
- func (w *Writer) WriteTo(write io.Writer) (int64, error)
- func (w *Writer) WriteToFilename(filepath string) error
Constants ¶
const ( GzipCompression = 1 + iota LzmaCompression LzoCompression XzCompression Lz4Compression ZstdCompression )
The types of compression supported by squashfs.
Variables ¶
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") )
var ( //ErrOptions is returned when compression options that I haven't tested is set. When this is returned, the Reader is also returned. ErrOptions = errors.New("Possibly incompatible compressor options") )
Functions ¶
This section is empty.
Types ¶
type File ¶ added in v0.2.0
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.
Implements os.FileInfo and io.ReadCloser
func (*File) ExtractSymlink ¶ added in v0.3.1
ExtractSymlink is similar to ExtractTo, but when it extracts a symlink, it instead extracts the file associated with the symlink in it's place. This is the same as ExtractWithOptions(path, true, false, os.ModePerm, false)
func (*File) ExtractTo ¶ added in v0.3.0
ExtractTo extracts the file to the given path. This is the same as ExtractWithOptions(path, false, 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, dereferenceSymlink, 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 dereferenceSymlink is set, instead of extracting a symlink, it will extract the file the symlink is pointed to in it's place. If both dereferenceSymlink and unbreakSymlink is set, dereferenceSymlink takes precendence.
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
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
GetChildrenRecursively returns ALL children. Goes down ALL folder paths.
func (*File) GetFileAtPath ¶ added in v0.2.1
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
GetSymlinkFile tries to return the squashfs.File associated with the symlink. If the file isn't a symlink or the symlink points to a location outside the archive, nil is returned.
func (*File) GetSymlinkFileRecursive ¶ added in v0.3.5
GetSymlinkFileRecursive tries to return the squasfs.File associated with the symlink. It will recursively try to get the symlink's file. This will return either a non-symlink File, or nil.
func (*File) Mode ¶ added in v0.3.4
Mode returns the os.FileMode of the File. Sets mode bits for directories and symlinks.
func (*File) Read ¶ added in v0.2.0
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
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 ¶
NewSquashfsReader returns a new squashfs.Reader from an io.ReaderAt
func (*Reader) ExtractTo ¶ added in v0.3.3
ExtractTo tries to extract ALL files to the given path. This is the same as getting the root folder and extracting that.
func (*Reader) FindAll ¶ added in v0.2.0
FindAll returns all files where the given function returns true.
func (*Reader) FindFile ¶ added in v0.2.0
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
GetAllFiles returns a slice of ALL files and folders contained in the squashfs.
func (*Reader) GetFileAtPath ¶ added in v0.2.0
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
GetRootFolder returns a squashfs.File that references the root directory of the squashfs archive.
type Writer ¶ added in v0.3.7
type Writer struct {
// contains filtered or unexported fields
}
Writer is used to creaste squashfs archives. Currently unusable TODO: Make usable
func NewWriter ¶ added in v0.3.7
NewWriter creates a new with the default options (Gzip compression and allow errors)
func NewWriterWithOptions ¶ added in v0.3.7
NewWriterWithOptions creates a new squashfs.Writer with the given options. compressionType can be of any types, except LZO (which this library doesn't have support for yet) allowErrors determines if, when adding folders, it allows errors encountered with it's sub-directories and instead logs the errors.
func (*Writer) AddFile ¶ added in v0.3.8
AddFile attempts to add an os.File to the archive at it's root.
func (*Writer) AddFileTo ¶ added in v0.3.8
AddFileTo adds the given file to the squashfs archive at the given filepath.
func (*Writer) AddFileToFolder ¶ added in v0.3.8
AddFileToFolder adds the given file to the squashfs archive, placing it inside the given folder.
func (*Writer) AddReaderTo ¶ added in v0.3.8
AddReaderTo adds the data from the given reader to the archive as a file located at the given filepath. Data from the reader is not read until the squashfs archive is writen. If the given reader implements io.Closer, it will be closed after it is fully read.
func (*Writer) FixSymlinks ¶ added in v0.3.8
FixSymlinks will scan through the squashfs archive and try to find broken symlinks and fix them. This done by replacing the symlink with the target file and then pointing other symlinks to that file.
If this is not run before writing, you may end up with broken symlinks.
func (*Writer) Remove ¶ added in v0.3.8
Remove tries to remove the file(s) at the given filepath. If wildcards are used, it will remove all files that match. Returns true if one or more files are removed.
func (*Writer) WriteTo ¶ added in v0.3.8
WriteTo attempts to write the archive to the given io.Writer.
func (*Writer) WriteToFilename ¶ added in v0.3.8
WriteToFilename creates the squashfs archive with the given filepath.