Documentation ¶
Overview ¶
Package tar implements access to tar archives. It aims to cover most of the variations, including those produced by GNU and BSD tars.
References:
http://www.freebsd.org/cgi/man.cgi?query=tar&sektion=5 http://www.gnu.org/software/tar/manual/html_node/Standard.html
Index ¶
Constants ¶
const ( // Types TypeReg = '0' // regular file TypeRegA = '\x00' // regular file TypeLink = '1' // hard link TypeSymlink = '2' // symbolic link TypeChar = '3' // character device node TypeBlock = '4' // block device node TypeDir = '5' // directory TypeFifo = '6' // fifo node TypeCont = '7' // reserved TypeXHeader = 'x' // extended header TypeXGlobalHeader = 'g' // global extended header )
Variables ¶
var ( ErrWriteTooLong = errors.New("archive/tar: write too long") ErrFieldTooLong = errors.New("archive/tar: header field too long") ErrWriteAfterClose = errors.New("archive/tar: write after close") )
var (
ErrHeader = errors.New("archive/tar: invalid tar header")
)
Functions ¶
This section is empty.
Types ¶
type Header ¶
type Header struct { Name string // name of header file entry Mode int64 // permission and mode bits Uid int // user id of owner Gid int // group id of owner Size int64 // length in bytes ModTime time.Time // modified time Typeflag byte // type of header entry Linkname string // target name of link Uname string // user name of owner Gname string // group name of owner Devmajor int64 // major number of character or block device Devminor int64 // minor number of character or block device AccessTime time.Time // access time ChangeTime time.Time // status change time }
A Header represents a single header in a tar archive. Some fields may not be populated.
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
A Reader provides sequential access to the contents of a tar archive. A tar archive consists of a sequence of files. The Next method advances to the next file in the archive (including the first), and then it can be treated as an io.Reader to access the file's data.
Example:
tr := tar.NewReader(r) for { hdr, err := tr.Next() if err == io.EOF { // end of tar 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 a tar archive in POSIX.1 format. A tar 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:
tw := tar.NewWriter(w) hdr := new(tar.Header) hdr.Size = length of data in bytes // populate other hdr fields as desired if err := tw.WriteHeader(hdr); err != nil { // handle error } io.Copy(tw, data) tw.Close()
func (*Writer) Close ¶
Close closes the tar archive, flushing any unwritten data to the underlying writer.
func (*Writer) Write ¶
Write writes to the current entry in the tar archive. Write returns the error ErrWriteTooLong if more than hdr.Size bytes are written after WriteHeader.
func (*Writer) WriteHeader ¶
WriteHeader writes hdr and prepares to accept the file's contents. WriteHeader calls Flush if it is not the first header. Calling after a Close will return ErrWriteAfterClose.