github.com/reds/docker@v1.11.2-rc1/layer/empty.go (about)

     1  package layer
     2  
     3  import (
     4  	"archive/tar"
     5  	"bytes"
     6  	"io"
     7  	"io/ioutil"
     8  )
     9  
    10  // DigestSHA256EmptyTar is the canonical sha256 digest of empty tar file -
    11  // (1024 NULL bytes)
    12  const DigestSHA256EmptyTar = DiffID("sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef")
    13  
    14  type emptyLayer struct{}
    15  
    16  // EmptyLayer is a layer that corresponds to empty tar.
    17  var EmptyLayer = &emptyLayer{}
    18  
    19  func (el *emptyLayer) TarStream() (io.ReadCloser, error) {
    20  	buf := new(bytes.Buffer)
    21  	tarWriter := tar.NewWriter(buf)
    22  	tarWriter.Close()
    23  	return ioutil.NopCloser(buf), nil
    24  }
    25  
    26  func (el *emptyLayer) ChainID() ChainID {
    27  	return ChainID(DigestSHA256EmptyTar)
    28  }
    29  
    30  func (el *emptyLayer) DiffID() DiffID {
    31  	return DigestSHA256EmptyTar
    32  }
    33  
    34  func (el *emptyLayer) Parent() Layer {
    35  	return nil
    36  }
    37  
    38  func (el *emptyLayer) Size() (size int64, err error) {
    39  	return 0, nil
    40  }
    41  
    42  func (el *emptyLayer) DiffSize() (size int64, err error) {
    43  	return 0, nil
    44  }
    45  
    46  func (el *emptyLayer) Metadata() (map[string]string, error) {
    47  	return make(map[string]string), nil
    48  }