code: func NewACI(dir string, manifest string, entries []*ACIEntry) (*os.File, error) {
  	var im schema.ImageManifest
  	if err := im.UnmarshalJSON([]byte(manifest)); err != nil {
  		return nil, errwrap.Wrap(errors.New("invalid image manifest"), err)
  	}
  
  	tf, err := ioutil.TempFile(dir, "")
  	if err != nil {
  		return nil, err
  	}
  	defer os.Remove(tf.Name())
  
  	tw := tar.NewWriter(tf)
  	aw := NewImageWriter(im, tw)
  
  	for _, entry := range entries {
  		// Add default mode
  		if entry.Header.Mode == 0 {
  			if entry.Header.Typeflag == tar.TypeDir {
  				entry.Header.Mode = 0755
  			} else {
  				entry.Header.Mode = 0644
  			}
  		}
  		// Add calling user uid and gid or tests will fail
  		entry.Header.Uid = os.Getuid()
  		entry.Header.Gid = os.Getgid()
  		sr := strings.NewReader(entry.Contents)
  		if err := aw.AddFile(entry.Header, sr); err != nil {
  			return nil, err
  		}
  	}
  
  	if err := aw.Close(); err != nil {
  		return nil, err
  	}
  	return tf, nil
  }
docs: // NewACI creates a new ACI in the given directory with the given image
  // manifest and entries.
  // Used for testing.