Documentation ¶
Overview ¶
Package ar implements reading and writing of ar archives. It supports reading archives in the GNU and BSD formats, but only supports writing in the BSD format.
Index ¶
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
A Reader provides sequential access to the contents of a BSD or GNU-style ar archive. An archive file consists of a sequence of files. The Next method advances to the next file in the archive (including the first). After Next has returned a header, the Reader can be treated as an io.Reader to access the data of the file described by the header received from Next.
Example:
tr := ar.NewReader(r) for { hdr, err := tr.Next() if err == io.EOF { // end of archive break } if err != nil { // handle error } io.Copy(data, tr) }
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
A Writer provides sequential writing of an ar archive in BSD format. It does not support writing in the GNU format, since the GNU-style extended filenames cannot be written sequentially. The BSD ar format is widely compatible with most modern ar readers out there.
An ar archive consists of a sequence of files. Call WriteHeader to begin a new file, and then call Write to supply that file's data, writing at most hdr.Size bytes in total.
Example:
aw := ar.NewWriter(w) hdr := new(ar.Header) hdr.Size = length of data in bytes // populate other hdr fields as desired if err := aw.WriteHeader(hdr); err != nil { // handle error } io.Copy(tw, data) tw.Close()
func (*Writer) Write ¶
Write writes the current entry in the ar archive. Write returns the error ErrWriteTooLong if more than hdr.Size bytes are written following a call to WriteHeader.
func (*Writer) WriteHeader ¶
WriteHeader writes hdr and prepares to accept the file's content. WriteHeader calls Flush to correctly pad the last written file. Calling after WriteHeader a Close will return ErrWriteAfterClose.