Documentation ¶
Overview ¶
Package ar implements access to read and write ar archives.
Reading supports both GNU, BSD, and Go ar variants, and writing creates archives of the GNU variant.
References:
https://mebsd.com/man/ar/5 http://www.unix.com/man-page/all/3head/ar.h/
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrHeader = errors.New("ar: invalid ar header") ErrStringsEntry = errors.New("ar: entry name not in strings table") )
Functions ¶
This section is empty.
Types ¶
type Header ¶
type Header struct { Name string // Name of file. ModTime time.Time // Modification time. Uid int // User id of owner. Gid int // Group id of owner. Mode int64 // Permission and mode bits. Size int64 // Length in bytes. }
Header represents a single file header in an ar archive. Some fields may not be populated.
func FileInfoHeader ¶
FileInfoHeader creates a populated Header from info. Because os.FileInfo's Name method returns only the base name of the file it describes, it may be necessary to modify the Name field of the returned header to provide the full path name of the file.
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader provides sequential access to an ar archive. The Next method advances to the next file entry, which afterwards can be treated as an io.Reader.
Example ¶
package main import ( "github.com/larzconwell/ar" "io" "os" ) func main() { in, err := os.Open("libz.a") if err != nil { panic(err) } defer in.Close() arReader := ar.NewReader(in) for { header, err := arReader.Next() if err != nil { panic(err) } if header == nil { break } out, err := os.Create(header.Name) if err != nil { panic(err) } _, err = io.Copy(out, arReader) if err != nil { panic(err) } err = out.Close() if err != nil { panic(err) } } }
Output:
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer provides sequential writing to an ar archive using the GNU format. WriteHeader triggers a new entry to be written, aftwards the writer can be used as an io.Writer.
Example ¶
package main import ( "github.com/larzconwell/ar" "io" "os" ) func main() { out, err := os.Create("libz.a") if err != nil { panic(err) } defer out.Close() arWriter := ar.NewWriter(out) object, err := os.Open("hasher.o") if err != nil { panic(err) } defer object.Close() stat, err := object.Stat() if err != nil { panic(err) } header := ar.FileInfoHeader(stat) err = arWriter.WriteHeader(header) if err != nil { panic(err) } _, err = io.Copy(arWriter, object) if err != nil { panic(err) } err = arWriter.Close() if err != nil { panic(err) } }
Output:
func (*Writer) Close ¶
Close closes the ar archive creating the symbol/string tables. All writing to the underlying writer is delayed until Close.
func (*Writer) Write ¶
Write writes b to the current file entry. It returns ErrWriteTooLong if more bytes are being written than the header allows.
func (*Writer) WriteHeader ¶
WriteHeader creates a new file entry for header. Calling after it's closed will return ErrWriteAfterClose. ErrHeaderTooLong is returned if the header won't fit.