Documentation
¶
Overview ¶
Package asar reads and writes ASAR (Atom-Shell Archive) archives.
Index ¶
- Variables
- type Builder
- type DecodeOptions
- type Entry
- func (e *Entry) Bytes() []byte
- func (e *Entry) EncodeTo(w io.Writer) (n int64, err error)
- func (e *Entry) FileInfo() os.FileInfo
- func (e *Entry) Find(path ...string) *Entry
- func (e *Entry) Open() *io.SectionReader
- func (e *Entry) Path() string
- func (e *Entry) String() string
- func (e *Entry) Walk(walkFn filepath.WalkFunc) error
- func (e *Entry) WriteTo(w io.Writer) (n int64, err error)
- type Flag
Constants ¶
This section is empty.
Variables ¶
var DefaultDecodeOptions = DecodeOptions{ StrictValidation: true, }
DefaultDecodeOptions 默认选项(严格模式)
Functions ¶
This section is empty.
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder helps construct an Entry.
A builder keeps track of the root Entry and the active Entry. When entries are added using the Add* methods, they are added as children to the active Entry.
func (*Builder) AddDir ¶
AddDir adds a new directory Entry. The active Entry is switched to this newly added Entry.
type DecodeOptions ¶ added in v0.0.2
type DecodeOptions struct {
// StrictValidation 如果为 false,会忽略一些格式验证错误和尾部填充
StrictValidation bool
}
DecodeOptions 用于控制解码行为
type Entry ¶
type Entry struct {
Name string
Size int64
Offset int64
Flags Flag
Parent *Entry
Children []*Entry
// contains filtered or unexported fields
}
Entry is a file or a folder in an ASAR archive.
func Decode ¶
Decode decodes the ASAR archive in ra.
Returns the root element and nil on success. nil and an error is returned on failure.
func DecodeWithOptions ¶ added in v0.0.2
func DecodeWithOptions(ra io.ReaderAt, opts DecodeOptions) (*Entry, error)
DecodeWithOptions 带选项的解码函数
func (*Entry) Bytes ¶
Bytes returns the entry's contents as a byte slice. nil is returned if the entry cannot be read.
func (*Entry) EncodeTo ¶
EncodeTo writes an ASAR archive containing Entry's descendants. This function is usally called on the root entry.
func (*Entry) Find ¶
Find searches for a sub-entry of the current entry. nil is returned if the requested sub-entry cannot be found.
For example, given the following tree structure:
root
- sub1
- sub2
- sub2.1
- file2.jpg
The following expression would return the .jpg *Entry:
root.Find("sub2", "sub2.1", "file2.jpg")
func (*Entry) Open ¶
func (e *Entry) Open() *io.SectionReader
Open returns an *io.SectionReader of the entry's contents. nil is returned if the entry cannot be opened (e.g. because it is a directory).
func (*Entry) Path ¶
Path returns the file path to the entry.
For example, given the following tree structure:
root - sub1 - sub2 - file2.jpg
file2.jpg's path would be:
sub2/file2.jpg
func (*Entry) String ¶
Bytes returns the entry's contents as a string. nil is returned if the entry cannot be read.
type Flag ¶
type Flag uint32
Flag is a bit field of Entry flags.
const ( // FlagNone denotes an entry with no flags. FlagNone Flag = 0 // FlagDir denotes a directory entry. FlagDir Flag = 1 << iota // FlagExecutable denotes a file with the executable bit set. FlagExecutable // FlagUnpacked denotes that the entry's contents are not included in // the archive. FlagUnpacked )