func (t *TarFile) AddWithHeader(name string, file []byte, hdr *tar.Header) error {
	if err := t.Writer.WriteHeader(hdr); err != nil {
		return err
	}
	_, err := t.Writer.Write(file)
	return err
}
Add add byte in archive tar
package archivex
import (
	"archive/tar"
	"archive/zip"
	"bufio"
	"compress/gzip"
	"io"
	"io/ioutil"
	"os"
	"path"
	"path/filepath"
	"strings"
	"time"
)
type Archivex interface {
	Create(name string) error
	Add(name string, file []byte) error
	AddFile(name string) error
	AddAll(dir string, includeCurrentFolder bool) error
	Close() error
}
type ArchiveWriteFunc func(info os.FileInfo, file io.Reader, entryName string) (err error)
type ZipFile struct {
	Writer *zip.Writer
	Name   string
}
type TarFile struct {
	Writer     *tar.Writer
	Name       string
	GzWriter   *gzip.Writer
	Compressed bool
}
func (z *ZipFile) Create(name string) error {
	z.Name = name
	file, err := os.Create(z.Name)
	if err != nil {
		return err
	}
	z.Writer = zip.NewWriter(file)
	return nil
}
func (z *ZipFile) Add(name string, file []byte) error {
	iow, err := z.Writer.Create(name)
	if err != nil {
		return err
	}
	_, err = iow.Write(file)
	return err
}
func (z *ZipFile) AddFile(name string) error {
	zippedFile, err := z.Writer.Create(name)
	if err != nil {
		return err
	}
	file, _ := os.Open(filepath.Join(name))
	fileReader := bufio.NewReader(file)
	blockSize := 512 * 1024  
	bytes := make([]byte, blockSize)
	for {
		readedBytes, err := fileReader.Read(bytes)
		if err != nil {
			if err.Error() == "EOF" {
				break
			}
			if err.Error() != "EOF" {
				return err
			}
		}
		if readedBytes >= blockSize {
			zippedFile.Write(bytes)
			continue
		}
		zippedFile.Write(bytes[:readedBytes])
	}
	return nil
}
func (z *ZipFile) AddAll(dir string, includeCurrentFolder bool) error {
	dir = path.Clean(dir)
	return addAll(dir, dir, includeCurrentFolder, func(info os.FileInfo, file io.Reader, entryName string) (err error) {
		header, err := zip.FileInfoHeader(info)
		if err != nil {
			return err
		}
		if !info.IsDir() {
			header.Method = zip.Deflate
		}
		header.Name = entryName
		if info.IsDir() {
			header.Name += "/"
		}
		writer, err := z.Writer.CreateHeader(header)
		if err != nil {
			return err
		}
		if file != nil {
			if _, err := io.Copy(writer, file); err != nil {
				return err
			}
		}
		return nil
	})
}
func (z *ZipFile) Close() error {
	return z.Writer.Close()
}
func (t *TarFile) Create(name string) error {
	if strings.HasSuffix(name, ".tar.gz") {
		t.Compressed = true
	} else {
		t.Compressed = false
	}
	if strings.HasSuffix(name, ".tar.gz") != true && strings.HasSuffix(name, ".tar") != true {
		if strings.HasSuffix(name, ".zip") == true {
			name = strings.Replace(name, ".zip", ".tar.gz", -1)
			t.Compressed = true
		} else {
			name = name + ".tar"
		}
	}
	t.Name = name
	file, err := os.Create(t.Name)
	if err != nil {
		return err
	}
	if t.Compressed {
		t.GzWriter = gzip.NewWriter(file)
		t.Writer = tar.NewWriter(t.GzWriter)
	} else {
		t.Writer = tar.NewWriter(file)
	}
	return nil
}
func (t *TarFile) Add(name string, file []byte) error {
	hdr := &tar.Header{
		Name:    name,
		Size:    int64(len(file)),
		Mode:    0666,
		ModTime: time.Now(),
	}
	if err := t.Writer.WriteHeader(hdr); err != nil {
		return err
	}
	_, err := t.Writer.Write(file)
	return err
}