Created
July 25, 2016 13:47
-
-
Save rhcarvalho/ab9d88bfb3fdc49625f2e86b6f7afa13 to your computer and use it in GitHub Desktop.
Experiment writing to a tar.gz in Go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//+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