archive

Imports

Imports #

"bufio"
"bytes"
"cmd/internal/bio"
"cmd/internal/goobj"
"errors"
"fmt"
"io"
"log"
"os"
"strconv"
"strings"
"time"
"unicode/utf8"

Constants & Variables

EntryGoObj const #

const EntryGoObj

EntryNativeObj const #

const EntryNativeObj

EntryPkgDef const #

const EntryPkgDef EntryType = iota

EntrySentinelNonObj const #

const EntrySentinelNonObj

HeaderSize const #

architecture-independent object file output

const HeaderSize = 60

archiveHeader var #

var archiveHeader = *ast.CallExpr

archiveMagic var #

var archiveMagic = *ast.CallExpr

entryHeader const #

const entryHeader = "%s%-12d%-6d%-6d%-8o%-10d`\n"

entryLen const #

In entryHeader the first entry, the name, is always printed as 16 bytes right-padded.

const entryLen = *ast.BinaryExpr

errCorruptArchive var #

var errCorruptArchive = *ast.CallExpr

errCorruptObject var #

var errCorruptObject = *ast.CallExpr

errNotObject var #

var errNotObject = *ast.CallExpr

errTruncatedArchive var #

var errTruncatedArchive = *ast.CallExpr

goobjHeader var #

var goobjHeader = *ast.CallExpr

timeFormat const #

const timeFormat = "Jan _2 15:04 2006"

Type Aliases

EntryType type #

type EntryType int

Structs

Archive struct #

type Archive struct {
f *os.File
Entries []Entry
}

Data struct #

A Data is a reference to data stored in an object file. It records the offset and size of the data, so that a client can read the data only if necessary.

type Data struct {
Offset int64
Size int64
}

Entry struct #

type Entry struct {
Name string
Type EntryType
Mtime int64
Uid int
Gid int
Mode os.FileMode
Data
Obj *GoObj
}

ErrGoObjOtherVersion struct #

type ErrGoObjOtherVersion struct {
magic []byte
}

GoObj struct #

type GoObj struct {
TextHeader []byte
Arch string
Data
}

objReader struct #

An objReader is an object file reader.

type objReader struct {
a *Archive
b *bio.Reader
err error
offset int64
limit int64
tmp [256]byte
}

Functions

AddEntry method #

AddEntry adds an entry to the end of a, with the content from r.

func (a *Archive) AddEntry(typ EntryType, name string, mtime int64, uid int, gid int, mode os.FileMode, size int64, r io.Reader)

Error method #

func (e ErrGoObjOtherVersion) Error() string

File method #

func (a *Archive) File() *os.File

FormatHeader function #

func FormatHeader(arhdr []byte, name string, size int64)

New function #

New writes to f to make a new archive.

func New(f *os.File) (*Archive, error)

Parse function #

Parse parses an object file or archive from f.

func Parse(f *os.File, verbose bool) (*Archive, error)

ReadHeader function #

func ReadHeader(b *bufio.Reader, name string) int

String method #

func (e *Entry) String() string

error method #

error records that an error occurred. It returns only the first error, so that an error caused by an earlier error does not discard information about the earlier error.

func (r *objReader) error(err error) error

exactly16Bytes function #

exactly16Bytes truncates the string if necessary so it is at most 16 bytes long, then pads the result with spaces to be exactly 16 bytes. Fmt uses runes for its width calculation, but we need bytes in the entry header.

func exactly16Bytes(s string) string

init method #

func (r *objReader) init(f *os.File)

parseArchive method #

parseArchive parses a Unix archive of Go object files.

func (r *objReader) parseArchive(verbose bool) error

parseObject method #

parseObject parses a single Go object file. The object file consists of a textual header ending in "\n!\n" and then the part we want to parse begins. The format of that part is defined in a comment at the top of cmd/internal/goobj/objfile.go.

func (r *objReader) parseObject(o *GoObj, size int64) error

peek method #

peek returns the next n bytes without advancing the reader.

func (r *objReader) peek(n int) ([]byte, error)

readByte method #

readByte reads and returns a byte from the input file. On I/O error or EOF, it records the error but returns byte 0. A sequence of 0 bytes will eventually terminate any parsing state in the object file. In particular, it ends the reading of a varint.

func (r *objReader) readByte() byte

readFull method #

readFull reads exactly len(b) bytes from the input file. If an error occurs, read returns the error but also records it, so it is safe for callers to ignore the result as long as delaying the report is not a problem.

func (r *objReader) readFull(b []byte) error

skip method #

skip skips n bytes in the input.

func (r *objReader) skip(n int64)

trimSpace function #

trimSpace removes trailing spaces from b and returns the corresponding string. This effectively parses the form used in archive headers.

func trimSpace(b []byte) string

Generated with Arrow