Golang archive/tar.Write() function example

package archive/tar

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.

tar.Write() usage example

 for _, file := range files {
 headerinfo := &tar.Header{
 Name: file.Name,
 Size: int64(len(file.Body)),
 }
 if err := tarwriter.WriteHeader(headerinfo); err != nil {
 fmt.Println(err)
 }
 if _, err := tarwriter.Write([]byte(file.Body)); err != nil {
 fmt.Println(err)
 }
  }

Reference :

http://golang.org/pkg/archive/tar/#Writer.Write

Advertisement