本文整理匯總了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())
}