1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Upload or download gzipped and bzipped images with put/pull -j/-b

This commit is contained in:
Solomon Hykes 2013-02-12 22:23:14 -08:00
parent f20deac47f
commit 059837c92a
3 changed files with 47 additions and 8 deletions

View file

@ -41,9 +41,16 @@ func New(root string) (*Store, error) {
}, nil
}
type Compression uint32
func (store *Store) Import(name string, archive io.Reader, stderr io.Writer, parent *Image) (*Image, error) {
layer, err := store.Layers.AddLayer(archive, stderr)
const (
Uncompressed Compression = iota
Bzip2
Gzip
)
func (store *Store) Import(name string, archive io.Reader, stderr io.Writer, parent *Image, compression Compression) (*Image, error) {
layer, err := store.Layers.AddLayer(archive, stderr, compression)
if err != nil {
return nil, err
}

View file

@ -82,13 +82,19 @@ func (store *LayerStore) layerPath(id string) string {
}
func (store *LayerStore) AddLayer(archive io.Reader, stderr io.Writer) (string, error) {
func (store *LayerStore) AddLayer(archive io.Reader, stderr io.Writer, compression Compression) (string, error) {
tmp, err := store.Mktemp()
defer os.RemoveAll(tmp)
if err != nil {
return "", err
}
untarCmd := exec.Command("tar", "-C", tmp, "-x")
extractFlags := "-x"
if compression == Bzip2 {
extractFlags += "j"
} else if compression == Gzip {
extractFlags += "z"
}
untarCmd := exec.Command("tar", "-C", tmp, extractFlags)
untarW, err := untarCmd.StdinPipe()
if err != nil {
return "", err