Standard library / archive/tar
archive/tar.NewWriter()
Construct a TAR writer over a destination stream. Write a header and exactly its declared payload before moving on. Close writes end markers. Expected stdout: '1024\n'.
Formal Syntax & Structure
go syntaxgo
func NewWriter(w io.Writer) *WriterParameters & Attributes
| Name | Type | Description |
|---|---|---|
| w | io.Writer | Destination stream; close the archive writer separately. |
Return Value
*Writer
Writer for constructing an archive.
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.Close()); fmt.Println(b.Len()) }