当前位置: 首页>>代码示例>>Golang>>正文


Golang CopyProgressPrinter.PrintAndWait方法代码示例

本文整理汇总了Golang中github.com/coreos/pkg/progressutil.CopyProgressPrinter.PrintAndWait方法的典型用法代码示例。如果您正苦于以下问题:Golang CopyProgressPrinter.PrintAndWait方法的具体用法?Golang CopyProgressPrinter.PrintAndWait怎么用?Golang CopyProgressPrinter.PrintAndWait使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/coreos/pkg/progressutil.CopyProgressPrinter的用法示例。


在下文中一共展示了CopyProgressPrinter.PrintAndWait方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: blockDumpAction

func blockDumpAction(cmd *cobra.Command, args []string) {
	if len(args) != 2 {
		cmd.Usage()
		os.Exit(1)
	}
	output, err := getWriterFromArg(args[1])
	if err != nil {
		die("couldn't open output: %v", err)
	}
	srv := createServer()
	defer srv.Close()
	blockvol, err := block.OpenBlockVolume(srv, args[0])
	if err != nil {
		die("couldn't open block volume %s: %v", args[0], err)
	}
	tempsnap := fmt.Sprintf("temp-dump-%d", os.Getpid())
	err = blockvol.SaveSnapshot(tempsnap)
	if err != nil {
		die("couldn't snapshot: %v", err)
	}
	bf, err := blockvol.OpenSnapshot(tempsnap)
	if err != nil {
		die("couldn't open snapshot: %v", err)
	}

	size := int64(bf.Size())
	if progress {
		pb := new(progressutil.CopyProgressPrinter)
		pb.AddCopy(bf, path.Base(args[0]), size, output)
		err := pb.PrintAndWait(os.Stdout, 500*time.Millisecond, nil)
		if err != nil {
			die("couldn't copy: %v", err)
		}
	} else {
		n, err := io.Copy(output, bf)
		if err != nil {
			die("couldn't copy: %v", err)
		}

		if n != size {
			die("short read of %q", args[0])
		}
	}

	err = blockvol.DeleteSnapshot(tempsnap)
	if err != nil {
		die("couldn't delete snapshot: %v", err)
	}
	fmt.Printf("copied %d bytes\n", size)
}
开发者ID:ConfusedReality,项目名称:server_distributed-storage_torus,代码行数:50,代码来源:block_dump_load.go

示例2: blockLoadAction

func blockLoadAction(cmd *cobra.Command, args []string) {
	if len(args) != 2 && len(args) != 3 {
		cmd.Usage()
		os.Exit(1)
	}
	input, err := getReaderFromArg(args[0])
	if err != nil {
		die("couldn't open input: %v", err)
	}
	srv := createServer()
	defer srv.Close()
	fi, err := input.Stat()
	if err != nil {
		die("couldn't stat input file: %v", err)
	}

	size := uint64(fi.Size())
	if len(args) == 3 {
		expSize, err := humanize.ParseBytes(args[2])
		if err != nil {
			die("error parsing size %s: %v", args[2], err)
		}

		if expSize < size {
			die("size must be larger than input file")
		}

		size = expSize
	}

	err = block.CreateBlockVolume(srv.MDS, args[1], size)
	if err != nil {
		die("couldn't create block volume %s: %v", args[1], err)
	}
	blockvol, err := block.OpenBlockVolume(srv, args[1])
	if err != nil {
		die("couldn't open block volume %s: %v", args[1], err)
	}
	f, err := blockvol.OpenBlockFile()
	if err != nil {
		die("couldn't open blockfile %s: %v", args[1], err)
	}

	if progress {
		pb := new(progressutil.CopyProgressPrinter)
		pb.AddCopy(input, path.Base(args[0]), fi.Size(), f)
		err := pb.PrintAndWait(os.Stdout, 500*time.Millisecond, nil)
		if err != nil {
			die("couldn't copy: %v", err)
		}
	} else {
		_, err := io.Copy(f, input)
		if err != nil {
			die("couldn't copy: %v", err)
		}
	}

	err = f.Sync()
	if err != nil {
		die("couldn't sync: %v", err)
	}
	err = f.Close()
	if err != nil {
		die("couldn't close: %v", err)
	}
	fmt.Printf("copied %d bytes\n", fi.Size())
}
开发者ID:ConfusedReality,项目名称:server_distributed-storage_torus,代码行数:67,代码来源:block_dump_load.go


注:本文中的github.com/coreos/pkg/progressutil.CopyProgressPrinter.PrintAndWait方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。