func DetectCompression(source []byte) Compression {
	for compression, m := range map[Compression][]byte{
		Bzip2: {0x42, 0x5A, 0x68},
		Gzip:  {0x1F, 0x8B, 0x08},
		Xz:    {0xFD, 0x37, 0x7A, 0x58, 0x5A, 0x00},
	} {
		if len(source) < len(m) {
			logrus.Debug("Len too short")
			continue
		}
		if bytes.Equal(m, source[:len(m)]) {
			return compression
		}
	}
	return Uncompressed
}
DetectCompression detects the compression algorithm of the source.
package archive
import (
	"archive/tar"
	"bufio"
	"bytes"
	"compress/bzip2"
	"compress/gzip"
	"fmt"
	"io"
	"io/ioutil"
	"os"
	"os/exec"
	"path/filepath"
	"runtime"
	"strings"
	"syscall"
	"github.com/docker/docker/pkg/fileutils"
	"github.com/docker/docker/pkg/idtools"
	"github.com/docker/docker/pkg/ioutils"
	"github.com/docker/docker/pkg/pools"
	"github.com/docker/docker/pkg/promise"
	"github.com/docker/docker/pkg/system"
	"github.com/sirupsen/logrus"
)
type (
	Compression int
	WhiteoutFormat int
	TarOptions struct {
		IncludeFiles     []string
		ExcludePatterns  []string
		Compression      Compression
		NoLchown         bool
		UIDMaps          []idtools.IDMap
		GIDMaps          []idtools.IDMap
		ChownOpts        *idtools.IDPair
		IncludeSourceDir bool
		WhiteoutFormat WhiteoutFormat
		NoOverwriteDirNonDir bool
		RebaseNames map[string]string
		InUserNS    bool
	}
)
type Archiver struct {
	Untar      func(io.Reader, string, *TarOptions) error
	IDMappings *idtools.IDMappings
}
func NewDefaultArchiver() *Archiver {
	return &Archiver{Untar: Untar, IDMappings: &idtools.IDMappings{}}
}
type breakoutError error
const (
	Uncompressed Compression = iota
	Bzip2
	Gzip
	Xz
)
const (
	AUFSWhiteoutFormat WhiteoutFormat = iota
	OverlayWhiteoutFormat
)
const (
	modeISDIR  = 040000   
	modeISFIFO = 010000   
	modeISREG  = 0100000  
	modeISLNK  = 0120000  
	modeISBLK  = 060000   
	modeISCHR  = 020000   
	modeISSOCK = 0140000  
)
func IsArchivePath(path string) bool {
	file, err := os.Open(path)
	if err != nil {
		return false
	}
	defer file.Close()
	rdr, err := DecompressStream(file)
	if err != nil {
		return false
	}
	r := tar.NewReader(rdr)
	_, err = r.Next()
	return err == nil
}