本文整理汇总了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)
}
示例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())
}