1 // Copyright 2009 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.
5 // Package tar implements access to tar archives.
6 // It aims to cover most of the variations, including those produced
7 // by GNU and BSD tars.
10 // http://www.freebsd.org/cgi/man.cgi?query=tar&sektion=5
11 // http://www.gnu.org/software/tar/manual/html_node/Standard.html
18 TypeReg = '0' // regular file.
19 TypeRegA = '\x00' // regular file.
20 TypeLink = '1' // hard link.
21 TypeSymlink = '2' // symbolic link.
22 TypeChar = '3' // character device node.
23 TypeBlock = '4' // block device node.
24 TypeDir = '5' // directory.
25 TypeFifo = '6' // fifo node.
26 TypeCont = '7' // reserved.
27 TypeXHeader = 'x' // extended header.
28 TypeXGlobalHeader = 'g' // global extended header.
31 // A Header represents a single header in a tar archive.
32 // Some fields may not be populated.
34 Name string // name of header file entry.
35 Mode int64 // permission and mode bits.
36 Uid int // user id of owner.
37 Gid int // group id of owner.
38 Size int64 // length in bytes.
39 Mtime int64 // modified time; seconds since epoch.
40 Typeflag byte // type of header entry.
41 Linkname string // target name of link.
42 Uname string // user name of owner.
43 Gname string // group name of owner.
44 Devmajor int64 // major number of character or block device.
45 Devminor int64 // minor number of character or block device.
46 Atime int64 // access time; seconds since epoch.
47 Ctime int64 // status change time; seconds since epoch.
51 var zeroBlock = make([]byte, blockSize)
53 // POSIX specifies a sum of the unsigned byte values, but the Sun tar uses signed byte values.
54 // We compute and return both.
55 func checksum(header []byte) (unsigned int64, signed int64) {
56 for i := 0; i < len(header); i++ {
58 // The chksum field (header[148:156]) is special: it should be treated as space bytes.
64 unsigned += int64(header[i])
65 signed += int64(int8(header[i]))
72 func (sp *slicer) next(n int) (b []byte) {
74 b, *sp = s[0:n], s[n:]