Standard library / archive/tar
archive/tar.Writer.WriteHeader()
Start an entry with metadata, writing padding for the prior entry. Name and Size must be appropriate for its type. Expected stdout: 'sub/ true\n'.
Formal Syntax & Structure
go syntaxgo
func (tw *Writer) WriteHeader(hdr *Header) errorParameters & Attributes
| Name | Type | Description |
|---|---|---|
| hdr | *Header | TAR entry metadata, including payload size. |
Return Value
error
Nil on success, otherwise operation error.
Working Example
Example Snippetgo
package main
import ( "archive/tar" "bytes" "fmt")
func must(e error) { if e != nil { panic(e) }}
func main() { var b bytes.Buffer w := tar.NewWriter(&b) must(w.WriteHeader(&tar.Header{Name: "sub/", Typeflag: tar.TypeDir, Mode: 0700})) must(w.Close()) r := tar.NewReader(&b) h, e := r.Next() must(e) fmt.Println(h.Name, h.FileInfo().IsDir())}