Standard library / archive/tar

archive/tar.Writer.Flush()

Pad the current entry to a TAR block boundary. Returns an error if declared payload is incomplete. Expected stdout: '1024\n'.

Formal Syntax & Structure

go syntaxgo
func (tw *Writer) Flush() error

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: "a", Size: 1, Mode: 0600}))  _, e := w.Write([]byte("x"))  must(e)  must(w.Flush())  fmt.Println(b.Len())  must(w.Close())}
Go Reference