Skip to content

Instantly share code, notes, and snippets.

@rhcarvalho
Created July 25, 2016 13:47
Show Gist options
  • Save rhcarvalho/ab9d88bfb3fdc49625f2e86b6f7afa13 to your computer and use it in GitHub Desktop.
Save rhcarvalho/ab9d88bfb3fdc49625f2e86b6f7afa13 to your computer and use it in GitHub Desktop.
Experiment writing to a tar.gz in Go
//+build ignore
package main
import (
"archive/tar"
"bytes"
"compress/gzip"
"io"
"os"
)
func main() {
var buf bytes.Buffer
tw := tar.NewWriter(&buf)
defer tw.Close()
f, _ := os.Create("foo.tar.gz")
defer f.Close()
gw := gzip.NewWriter(f)
defer gw.Close()
defer io.Copy(gw, &buf)
tw.WriteHeader(&tar.Header{
Name: "foobar",
Mode: 0666,
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment