2015-11-18 22:15:00 +00:00
|
|
|
package layer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"archive/tar"
|
|
|
|
"bytes"
|
|
|
|
"io"
|
2015-11-26 00:39:54 +00:00
|
|
|
"io/ioutil"
|
2015-11-18 22:15:00 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// DigestSHA256EmptyTar is the canonical sha256 digest of empty tar file -
|
|
|
|
// (1024 NULL bytes)
|
|
|
|
const DigestSHA256EmptyTar = DiffID("sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef")
|
|
|
|
|
|
|
|
type emptyLayer struct{}
|
|
|
|
|
|
|
|
// EmptyLayer is a layer that corresponds to empty tar.
|
|
|
|
var EmptyLayer = &emptyLayer{}
|
|
|
|
|
2015-11-26 00:39:54 +00:00
|
|
|
func (el *emptyLayer) TarStream() (io.ReadCloser, error) {
|
2015-11-18 22:15:00 +00:00
|
|
|
buf := new(bytes.Buffer)
|
|
|
|
tarWriter := tar.NewWriter(buf)
|
|
|
|
tarWriter.Close()
|
2015-11-26 00:39:54 +00:00
|
|
|
return ioutil.NopCloser(buf), nil
|
2015-11-18 22:15:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (el *emptyLayer) ChainID() ChainID {
|
|
|
|
return ChainID(DigestSHA256EmptyTar)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (el *emptyLayer) DiffID() DiffID {
|
|
|
|
return DigestSHA256EmptyTar
|
|
|
|
}
|
|
|
|
|
|
|
|
func (el *emptyLayer) Parent() Layer {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (el *emptyLayer) Size() (size int64, err error) {
|
|
|
|
return 0, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (el *emptyLayer) DiffSize() (size int64, err error) {
|
|
|
|
return 0, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (el *emptyLayer) Metadata() (map[string]string, error) {
|
|
|
|
return make(map[string]string), nil
|
|
|
|
}
|