asar

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2026 License: BSD-3-Clause Imports: 14 Imported by: 0

README

asar-go

This Go package enables reading, writing, and modifying ASAR files.

It includes a comprehensive test suite with test files from the official repository.

The code is 100% human-written.

Examples

Extract a archive
package main

import (
	"fmt"
	"os"

	"codeberg.org/JakobDev/asar-go"
)

func main() {
    archive, err := asar.OpenFile("path", &asar.ReadOptions{})
    if err != nil {
        fmt.Println(err)
        os.Exit(1)
    }
    defer archive.Close()

    err = archive.ExtractAll("extract_path")
    if err != nil {
        fmt.Println(err)
        os.Exit(1)
    }
}
Read a file
package main

import (
	"fmt"
	"os"
    "io"

	"codeberg.org/JakobDev/asar-go"
)

func main() {
    archive, err := asar.OpenFile("path", &asar.ReadOptions{})
    if err != nil {
        fmt.Println(err)
        os.Exit(1)
    }
    defer archive.Close()

    entry, err := archive.GetEntry("test.txt")
    if err != nil {
        fmt.Println(err)
        os.Exit(1)
    }

    reader, err := entry.GetReader()
    if err != nil {
        fmt.Println(err)
        os.Exit(1)
    }

    content, err := io.ReadAll(reader)
    if err != nil {
        fmt.Println(err)
        os.Exit(1)
    }

    fmt.Println(string(content))
}

Documentation

Index

Constants

View Source
const DEFAULT_BLOCK_SIZE = 4 * 1024 * 1024

Variables

This section is empty.

Functions

This section is empty.

Types

type AsarArchive

type AsarArchive struct {
	FilePath string
	// contains filtered or unexported fields
}

func CreateArchive

func CreateArchive() *AsarArchive

Creates a new AsarArchive

func FromReader

func FromReader(reader io.ReadSeekCloser, options *ReadOptions) (*AsarArchive, error)

Creates an AsarArchive from a Reader The AsarArchive takes ownership of the Reader

func OpenFile

func OpenFile(path string, options *ReadOptions) (*AsarArchive, error)

Opens an ASAR file

func (*AsarArchive) AddFromDirectory

func (archive *AsarArchive) AddFromDirectory(path, prefix string) error

Add files from a directory to the Archive

func (*AsarArchive) Close

func (archive *AsarArchive) Close() error

Closes the Archive

func (*AsarArchive) CreateFileEntry

func (archive *AsarArchive) CreateFileEntry(name string, content []byte) error

Creates a File entry with the given Content If the Entry exists, it will be overwritten

func (*AsarArchive) CreateLinkEntry added in v1.1.0

func (archive *AsarArchive) CreateLinkEntry(name, link string) error

Creates a Link entry If the Entry exists, it will be overwritten

func (*AsarArchive) DeleteEntry

func (archive *AsarArchive) DeleteEntry(name string) error

Deletes a entry

func (*AsarArchive) ExtractAll

func (archive *AsarArchive) ExtractAll(path string) error

Extract the Archive

func (*AsarArchive) GetAllEntries

func (archive *AsarArchive) GetAllEntries() []*AsarEntry

Returns all entries

func (*AsarArchive) GetEntry

func (archive *AsarArchive) GetEntry(name string) (*AsarEntry, error)

Returns the entry with the given name

func (*AsarArchive) Save

func (archive *AsarArchive) Save(options *WriteOptions) error

Saves the Archive to the opened File If this throws an error, you may not be able to use the archive after

func (*AsarArchive) Write

func (archive *AsarArchive) Write(writer io.WriteSeeker, options *WriteOptions) error

Writes the Archive to the given Writer

func (*AsarArchive) WriteFile

func (archive *AsarArchive) WriteFile(path string, options *WriteOptions) error

Writes the Archive to the given file

type AsarEntry

type AsarEntry struct {
	Type AsarEntryType
	Name string
	Link string
	// contains filtered or unexported fields
}

func (*AsarEntry) GetReader

func (asarEntry *AsarEntry) GetReader() (io.ReadSeekCloser, error)

Returns an Reader for an file entry

type AsarEntryType

type AsarEntryType int8
const (
	AsarEntryTypeDirectory AsarEntryType = iota
	AsarEntryTypeFile
	AsarEntryTypeLink
)

func (AsarEntryType) String

func (entryType AsarEntryType) String() string

type AsarHeaderInfo

type AsarHeaderInfo struct {
	JsonData   any
	BaseOffset int64
}

func ReadAsarHeaderInfo

func ReadAsarHeaderInfo(reader io.ReadSeekCloser) (*AsarHeaderInfo, error)

Reads the Header of an Reader

type ReadOptions

type ReadOptions struct {
	UnpackedDir        string
	SkipIntegrityCheck bool
}

type WriteOptions

type WriteOptions struct {
	BlockSize int
}

Jump to

Keyboard shortcuts

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