Package tar implements access to tar archives.
- Tar
- Gzip
- Tar files or dirs
go get github.com/hslam/tar
import "github.com/hslam/tar"
package main
import (
"fmt"
"github.com/hslam/tar"
"os"
)
func main() {
name := "file"
targz := "file.tar.gz"
defer os.Remove(name)
defer os.Remove(targz)
file, err := os.Create(name)
if err != nil {
panic(err)
}
contents := "Hello World"
file.Write([]byte(contents))
file.Close()
tar.Targz(targz, name)
os.Remove(name)
tar.Untargz(targz)
f, err := os.Open(name)
if err != nil {
panic(err)
}
defer f.Close()
buf := make([]byte, len(contents))
f.Read(buf)
fmt.Println(string(buf))
}
package main
import (
"fmt"
"github.com/hslam/tar"
"os"
)
func main() {
targz := "file.tar.gz"
defer os.Remove(targz)
tw, err := tar.NewGzipFileWriter(targz)
if err != nil {
panic(err)
}
tw.TarBytes("file", []byte("Hello World"))
tw.Flush()
tw.Close()
tr, err := tar.NewGzipFileReader(targz)
if err != nil {
panic(err)
}
_, _, data, err := tr.NextBytes()
if err != nil {
panic(err)
}
fmt.Println(string(data))
}
Hello World
This package is licensed under a MIT license (Copyright (c) 2020 Meng Huang)
tar was written by Meng Huang.