archivefs

package
v0.35.2 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2024 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package archivefs allows the traversal of a filetree and treating archive files transparently.

Supported archive formats is currently limited to zip.

Index

Constants

This section is empty.

Variables

View Source
var ArchiveExtensions = [...]string{".ZIP"}

list of file extensions for the supported archive types

Functions

func Open

func Open(filename string) (io.ReadSeeker, int, error)

Open and return an io.ReadSeeker for the specified filename. Filename can be inside an archive supported by archivefs

Returns the io.ReadSeeker, the size of the data behind the ReadSeeker and any errors.

func RemoveArchiveExt

func RemoveArchiveExt(s string) string

RemoveArchiveExt removes the file extension of any supported/recognised archive type from within the string. Only the first instance of the extension is removed

func Sort added in v0.32.0

func Sort(entries []Entry)

Sort entries according to the archivefs rules, which are simply: case insensitive and directories at the top of the listing.

func TrimArchiveExt

func TrimArchiveExt(s string) string

TrimArchiveExt removes the file extension of any supported/recognised archive type from the end of the string

Types

type AsyncPath added in v0.30.1

type AsyncPath struct {
	Set     chan string
	Close   chan bool
	Destroy chan bool

	// Results of most recent change of path settings
	Results AsyncResults
	// contains filtered or unexported fields
}

AsyncPath provides asynchronous access to an archivefs

func NewAsyncPath added in v0.30.1

func NewAsyncPath(setter FilenameSetter) AsyncPath

NewAsyncPath is the preferred method of initialisation for the AsyncPath type

func (*AsyncPath) Process added in v0.30.1

func (pth *AsyncPath) Process() error

Process results from previous push to Set channel

type AsyncResults added in v0.30.1

type AsyncResults struct {
	Entries  []Entry
	Selected string
	IsDir    bool
	Dir      string
	Base     string
}

AsyncResults are copies of archivefs path information that are safe to access asynchronously

type Entry added in v0.32.0

type Entry struct {
	Name string

	// a directory has the the field of IsDir set to true
	IsDir bool

	// a recognised archive file has InArchive set to true. note that an archive
	// file is also considered to be directory
	IsArchive bool
}

Entry represents a single part of a full path

func (Entry) String added in v0.32.0

func (e Entry) String() string

type FilenameSetter added in v0.30.1

type FilenameSetter interface {
	SetSelectedFilename(string)
}

SetSelectedFilename is called after a successful Set()

type Path

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

Path represents a single destination in the file system

func (Path) Base

func (afs Path) Base() string

Base returns the last element of the current path

func (*Path) Close

func (afs *Path) Close()

Close any open zip files and reset path

func (Path) Dir

func (afs Path) Dir() string

Dir returns all but the last element of path

func (Path) InArchive

func (afs Path) InArchive() bool

InArchive returns true if path is currently inside an archive

func (Path) IsDir

func (afs Path) IsDir() bool

IsDir returns true if Path is currently set to a directory. For the purposes of archivefs, the root of an archive is treated as a directory

func (*Path) List

func (afs *Path) List() ([]Entry, error)

List returns the child entries for the current path location. If the current path is a file then the list will be the contents of the containing directory of that file. Returned entries are sorted.

func (Path) Open

func (afs Path) Open() (io.ReadSeeker, int, error)

Open and return an io.ReadSeeker for the filename previously set by the Set() function.

Returns the io.ReadSeeker, the size of the data behind the ReadSeeker and any errors.

func (*Path) Set

func (afs *Path) Set(path string, fallback bool) error

Set path to the requested path, handling archive files as appropriate.

If fallback is true then the Set() function will try to open the most recent valid sub-path. If setting the fallback is successful then no error will be returned.

func (Path) String

func (afs Path) String() string

String returns the current path

Jump to

Keyboard shortcuts

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