Skip to content
/ tar Public

Package tar implements access to tar archives.

License

Notifications You must be signed in to change notification settings

hslam/tar

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tar

PkgGoDev Build Status codecov Go Report Card LICENSE

Package tar implements access to tar archives.

Feature

  • Tar
  • Gzip
  • Tar files or dirs

Get started

Install

go get github.com/hslam/tar

Import

import "github.com/hslam/tar"

Usage

Example

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))
}

Tar bytes example

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))
}

Output

Hello World

License

This package is licensed under a MIT license (Copyright (c) 2020 Meng Huang)

Author

tar was written by Meng Huang.