asar

package module
v0.0.0-...-3d124ec Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2024 License: MPL-2.0 Imports: 12 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

asar

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

import (
    "os"

    "github.com/rahimov/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())

Also, please find an example of how to convert zip to asar in the example folder.

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, link string, integrity *Integrity) *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) Current

func (b *Builder) Current() *Entry

Current retrievs current Entry.

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.

func (*Builder) SetCurrent

func (b *Builder) SetCurrent(current *Entry) *Builder

SetCurrent changes directory to Entry. The active Entry is switched to this newly added Entry.

type Entry

type Entry struct {
	Name      string
	Size      int64
	Offset    int64
	Flags     Flag
	Parent    *Entry
	Children  []*Entry
	Link      string
	Integrity *Integrity
	// 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, link string) *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 usually 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
	FlagLink
)

type Integrity

type Integrity struct {
	Algorithm string
	Hash      string
	BlockSize int64
	Blocks    []string
}

Integrity is a checksum of file.

Directories

Path Synopsis
cmd
asar command

Jump to

Keyboard shortcuts

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