func tarball(filePaths []string, tarWriter *tar.Writer, dest string) error {
	for _, fpath := range filePaths {
		err := tarFile(tarWriter, fpath, dest)
		if err != nil {
			return err
		}
	}
	return nil
}
tarball writes all files listed in filePaths into tarWriter, which is
writing into a file located at dest.
package archiver
import (
	"archive/tar"
	"bytes"
	"fmt"
	"io"
	"os"
	"path/filepath"
	"strconv"
	"strings"
)
var Tar tarFormat
func init() {
	RegisterFormat("Tar", Tar)
}
type tarFormat struct{}
func (tarFormat) Match(filename string) bool {
	return strings.HasSuffix(strings.ToLower(filename), ".tar") || isTar(filename)
}
const tarBlockSize int = 512
func isTar(tarPath string) bool {
	f, err := os.Open(tarPath)
	if err != nil {
		return false
	}
	defer f.Close()
	buf := make([]byte, tarBlockSize)
	if _, err = io.ReadFull(f, buf); err != nil {
		return false
	}
	return hasTarHeader(buf)
}
func hasTarHeader(buf []byte) bool {
	if len(buf) < tarBlockSize {
		return false
	}
	b := buf[148:156]
	b = bytes.Trim(b, " \x00")  
	if len(b) == 0 {
		return false  
	}
	hdrSum, err := strconv.ParseUint(string(b), 8, 64)
	if err != nil {
		return false
	}
	var usum uint64
	var sum int64
	for i, c := range buf {
		if 148 <= i && i < 156 {
			c = ' '  
		}
		usum += uint64(uint8(c))
		sum += int64(int8(c))
	}
	if hdrSum != usum && int64(hdrSum) != sum {
		return false  
	}
	return true
}
func (tarFormat) Write(output io.Writer, filePaths []string) error {
	return writeTar(filePaths, output, "")
}
func (tarFormat) Make(tarPath string, filePaths []string) error {
	out, err := os.Create(tarPath)
	if err != nil {
		return fmt.Errorf("error creating %s: %v", tarPath, err)
	}
	defer out.Close()
	return writeTar(filePaths, out, tarPath)
}
func writeTar(filePaths []string, output io.Writer, dest string) error {
	tarWriter := tar.NewWriter(output)
	defer tarWriter.Close()
	return tarball(filePaths, tarWriter, dest)
}