github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/cmd/internal/archive/archive.go (about) 1 // Copyright 2013 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // Package archive implements reading of archive files generated by the Go 6 // toolchain. 7 package archive 8 9 import ( 10 "github.com/shogo82148/std/bufio" 11 "github.com/shogo82148/std/io" 12 "github.com/shogo82148/std/os" 13 ) 14 15 // A Data is a reference to data stored in an object file. 16 // It records the offset and size of the data, so that a client can 17 // read the data only if necessary. 18 type Data struct { 19 Offset int64 20 Size int64 21 } 22 23 type Archive struct { 24 f *os.File 25 Entries []Entry 26 } 27 28 func (a *Archive) File() *os.File 29 30 type Entry struct { 31 Name string 32 Type EntryType 33 Mtime int64 34 Uid int 35 Gid int 36 Mode os.FileMode 37 Data 38 Obj *GoObj 39 } 40 41 type EntryType int 42 43 const ( 44 EntryPkgDef EntryType = iota 45 EntryGoObj 46 EntryNativeObj 47 EntrySentinelNonObj 48 ) 49 50 func (e *Entry) String() string 51 52 type GoObj struct { 53 TextHeader []byte 54 Arch string 55 Data 56 } 57 58 type ErrGoObjOtherVersion struct{ magic []byte } 59 60 func (e ErrGoObjOtherVersion) Error() string 61 62 // New writes to f to make a new archive. 63 func New(f *os.File) (*Archive, error) 64 65 // Parse parses an object file or archive from f. 66 func Parse(f *os.File, verbose bool) (*Archive, error) 67 68 // AddEntry adds an entry to the end of a, with the content from r. 69 func (a *Archive) AddEntry(typ EntryType, name string, mtime int64, uid, gid int, mode os.FileMode, size int64, r io.Reader) 70 71 // architecture-independent object file output 72 const HeaderSize = 60 73 74 func ReadHeader(b *bufio.Reader, name string) int 75 76 func FormatHeader(arhdr []byte, name string, size int64)