當前位置: 首頁>>代碼示例>>Golang>>正文


Golang archive.NewTempArchive函數代碼示例

本文整理匯總了Golang中github.com/docker/docker/pkg/archive.NewTempArchive函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewTempArchive函數的具體用法?Golang NewTempArchive怎麽用?Golang NewTempArchive使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewTempArchive函數的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TempLayerArchive

// TempLayerArchive creates a temporary archive of the given image's filesystem layer.
//   The archive is stored on disk and will be automatically deleted as soon as has been read.
//   If output is not nil, a human-readable progress bar will be written to it.
func (graph *Graph) TempLayerArchive(id string, sf *streamformatter.StreamFormatter, output io.Writer) (*archive.TempArchive, error) {
	image, err := graph.Get(id)
	if err != nil {
		return nil, err
	}
	tmp, err := graph.mktemp()
	if err != nil {
		return nil, err
	}
	defer os.RemoveAll(tmp)
	a, err := graph.TarLayer(image)
	if err != nil {
		return nil, err
	}
	progressReader := progressreader.New(progressreader.Config{
		In:        a,
		Out:       output,
		Formatter: sf,
		Size:      0,
		NewLines:  false,
		ID:        stringid.TruncateID(id),
		Action:    "Buffering to disk",
	})
	defer progressReader.Close()
	return archive.NewTempArchive(progressReader, tmp)
}
開發者ID:previousnext,項目名稱:kube-ingress,代碼行數:29,代碼來源:graph.go

示例2: commitChanges

//krgo commit -r rootfs
//commit current changes in a new properly formated branch ready for pushing
func commitChanges(rootfs, message string) error {
	if !isGitRepo(rootfs) {
		return fmt.Errorf("%v not a git repository", rootfs)
	}
	gitRepo, _ := newGitRepo(rootfs)

	layerData, err := gitRepo.exportUncommitedChangeSet()
	if err != nil {
		return err
	}
	defer layerData.Close()

	//Load image data
	image, err := image.LoadImage(gitRepo.Path) //reading json file in rootfs
	if err != nil {
		return err
	}

	//fill new infos
	image.Parent = image.ID
	image.ID = utils.GenerateRandomID()
	image.Created = time.Now()
	image.Comment = message

	layer, err := archive.NewTempArchive(layerData, "")
	if err != nil {
		return err
	}
	image.Size = layer.Size
	os.RemoveAll(layer.Name())

	if err := image.SaveSize(rootfs); err != nil {
		return err
	}

	jsonRaw, err := json.Marshal(image)
	if err != nil {
		return err
	}

	err = ioutil.WriteFile(path.Join(rootfs, "json"), jsonRaw, 0600)
	if err != nil {
		return err
	}

	//commit the changes in a new branch
	n, _ := gitRepo.countBranch()
	br := newBranch(n, image.ID)
	if _, err = gitRepo.checkoutB(br); err != nil {
		return err
	}
	if _, err := gitRepo.addAllAndCommit(message); err != nil {
		return err
	}

	fmt.Printf("Changes commited in %v\n", br)
	fmt.Printf("Image ID: %v\nParent: %v\nChecksum: %v\nLayer size: %v\n", image.ID, image.Parent, image.Size)

	return nil
}
開發者ID:HowardMei,項目名稱:krgo,代碼行數:62,代碼來源:commit.go

示例3: TempLayerArchive

// TempLayerArchive creates a temporary archive of the given image's filesystem layer.
//   The archive is stored on disk and will be automatically deleted as soon as has been read.
//   If output is not nil, a human-readable progress bar will be written to it.
//   FIXME: does this belong in Graph? How about MktempFile, let the caller use it for archives?
func (graph *Graph) TempLayerArchive(id string, compression archive.Compression, sf *utils.StreamFormatter, output io.Writer) (*archive.TempArchive, error) {
	image, err := graph.Get(id)
	if err != nil {
		return nil, err
	}
	tmp, err := graph.Mktemp("")
	if err != nil {
		return nil, err
	}
	a, err := image.TarLayer()
	if err != nil {
		return nil, err
	}
	progress := utils.ProgressReader(a, 0, output, sf, false, utils.TruncateID(id), "Buffering to disk")
	defer progress.Close()
	return archive.NewTempArchive(progress, tmp)
}
開發者ID:TencentSA,項目名稱:docker-1.3,代碼行數:21,代碼來源:graph.go


注:本文中的github.com/docker/docker/pkg/archive.NewTempArchive函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。