const ( // Type '0' indicates a regular file.(普通文件) TypeReg = '0' TypeRegA = '\x00'// Deprecated: Use TypeReg instead.
// Type '1' to '6' are header-only flags and may not have a data body. 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
// Type '7' is reserved.(保留项) TypeCont = '7'
// Type 'x' is used by the PAX format to store key-value records that // are only relevant to the next file. // This package transparently handles these types. TypeXHeader = 'x'// 可扩展头部
// Type 'g' is used by the PAX format to store key-value records that // are relevant to all subsequent files. // This package only supports parsing and composing such headers, // but does not currently support persisting the global state across files. TypeXGlobalHeader = 'g'// 全局扩展头部
// Type 'S' indicates a sparse file in the GNU format. TypeGNUSparse = 'S'// 稀疏文件
// Types 'L' and 'K' are used by the GNU format for a meta file // used to store the path or link name for the next file. // This package transparently handles these types. TypeGNULongName = 'L' TypeGNULongLink = 'K' )
变量(主要用于错误输出)
1 2 3 4 5 6
var ( ErrHeader = errors.New("archive/tar: invalid tar header") // 无效的tar头部 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") // 关闭后写入 )
Devmajor int64// Major device number (valid for TypeChar or TypeBlock)(字符设备或块设备的主设备号) Devminor int64// Minor device number (valid for TypeChar or TypeBlock)(字符设备或块设备的次设备号)
Xattrs map[string]string// Go 1.3 PAXRecords map[string]string// Go 1.10
Format Format // Go 1.10 }
Header的相关方法:
func FileInfoHeader(fi os.FileInfo, link string)(*Header, error) //该方法通过os.FileInfo来创建一个tar.Header,用在对已有文件打包十分方便
type Reader struct { r io.Reader pad int64// Amount of padding (ignored) after current file entry curr fileReader // Reader for current file entry blk block // Buffer to use as temporary local storage
// err is a persistent error. // It is only the responsibility of every exported method of Reader to // ensure that this error is sticky. err error }
type Writer struct { w io.Writer pad int64// Amount of padding to write after current file entry curr fileWriter // Writer for current file entry hdr Header // Shallow copy of Header that is safe for mutations blk block // Buffer to use as temporary local storage
// err is a persistent error. // It is only the responsibility of every exported method of Writer to // ensure that this error is sticky. err error }