asar

package module
Version: v0.0.0-...-bf07d19 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2018 License: MPL-2.0 Imports: 11 Imported by: 7

README

asar GoDoc

Package asar reads and writes ASAR (Atom-Shell Archive) archives

import (
    "os"

    "layeh.com/asar"
)


f, err := os.Open("sample.asar")
if err != nil {
    panic(err)
}
defer f.Close()

archive, err := asar.Decode(f)
if err != nil {
    panic(err)
}

test := archive.Find("test", "file.txt")
if test == nil {
    panic("file not found")
}
// print contents of test/file.txt in sample.asar
fmt.Println(test.String())

License

MPL 2.0

Author

Tim Cooper (tim.cooper@layeh.com)

Documentation

Overview

Package asar reads and writes ASAR (Atom-Shell Archive) archives.

Index

Constants

This section is empty.

Variables

This section is empty.

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) Add

func (b *Builder) Add(name string, ra io.ReaderAt, size int64, flags Flag) *Builder

Add adds a new file Entry.

func (*Builder) AddDir

func (b *Builder) AddDir(name string, flags Flag) *Builder

AddDir adds a new directory Entry. The active Entry is switched to this newly added Entry.

func (*Builder) AddString

func (b *Builder) AddString(name, contents string, flags Flag) *Builder

AddString adds a new file Entry whose contents are the given string.

func (*Builder) Parent

func (b *Builder) Parent() *Builder

Parent sets the active entry to the parent of the active Entry (i.e. moves up a level).

The function panics if called on the root Entry.

func (*Builder) Root

func (b *Builder) Root() *Entry

Root returns the root Entry.

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

func Decode(ra io.ReaderAt) (*Entry, error)

Decode decodes the ASAR archive in ra.

Returns the root element and nil on success. nil and an error is returned on failure.

func New

func New(name string, ra io.ReaderAt, size, offset int64, flags Flag) *Entry

New creates a new Entry.

func (*Entry) Bytes

func (e *Entry) Bytes() []byte

Bytes returns the entry's contents as a byte slice. nil is returned if the entry cannot be read.

func (*Entry) EncodeTo

func (e *Entry) EncodeTo(w io.Writer) (n int64, err error)

EncodeTo writes an ASAR archive containing Entry's descendants. This function is usally called on the root entry.

func (*Entry) FileInfo

func (e *Entry) FileInfo() os.FileInfo

FileInfo returns the os.FileInfo information about the entry.

func (*Entry) Find

func (e *Entry) Find(path ...string) *Entry

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

func (e *Entry) Path() string

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

func (e *Entry) String() string

Bytes returns the entry's contents as a string. nil is returned if the entry cannot be read.

func (*Entry) Walk

func (e *Entry) Walk(walkFn filepath.WalkFunc) error

Walk recursively walks over the entry's children. See filepath.Walk and filepath.WalkFunc for more information.

func (*Entry) WriteTo

func (e *Entry) WriteTo(w io.Writer) (n int64, err error)

WriteTo writes the entry's contents to the given writer. nil is returned if the entry cannot be opened (e.g. if the entry is a directory).

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
)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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