本文整理汇总了Golang中github.com/cheggaaa/pb.New64函数的典型用法代码示例。如果您正苦于以下问题:Golang New64函数的具体用法?Golang New64怎么用?Golang New64使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New64函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: upload
func upload(c cli.Command) {
var path string
switch len(c.Args()) {
case 1:
path = c.Arg(0).String()
case 2:
container = c.Arg(0).String()
path = c.Arg(1).String()
}
if blank(container) || blank(path) {
log.Fatal(errorNotEnough)
}
f, err := os.Open(path)
if err != nil {
log.Fatal(err)
}
stat, err := os.Stat(path)
if err != nil {
log.Fatal(err)
}
ext := filepath.Ext(path)
mimetype := mime.TypeByExtension(ext)
bar := pb.New64(stat.Size()).SetUnits(pb.U_BYTES)
bar.Start()
reader := io.TeeReader(f, bar)
if err := api.Container(container).Upload(reader, stat.Name(), mimetype); err != nil {
log.Fatal(err)
}
fmt.Printf("uploaded to %s\n", container)
}
开发者ID:ernado,项目名称:selectel,代码行数:32,代码来源:main.go
示例2: initUnknownBar
func initUnknownBar() {
bar = pb.New64(0).SetUnits(pb.U_BYTES).SetRefreshRate(time.Millisecond * 10)
bar.ShowSpeed = true
bar.ShowCounters = true
bar.ShowBar = false
bar.Start()
}
开发者ID:Depado,项目名称:goploader,代码行数:7,代码来源:main.go
示例3: NewCopy
func NewCopy(albumID, title, url string) (*Copy, error) {
resp, err := http.Get(url)
if err != nil {
return nil, err
}
if resp.StatusCode != 200 {
resp.Body.Close()
return nil, fmt.Errorf("GET %s -> %s (Invalid status code)", url, resp.Status)
}
contentType := resp.Header.Get("content-type")
contentSize := resp.ContentLength
if !strings.HasPrefix(contentType, "image/") {
resp.Body.Close()
return nil, fmt.Errorf("GET %s -> %s (Invalid content type)", url, contentType)
}
progressBar := pb.New64(contentSize)
progressBar.SetUnits(pb.U_BYTES)
progressBar.Prefix(title)
return &Copy{
AlbumID: albumID,
Title: title,
URL: url,
ContentType: contentType,
ContentLength: contentSize,
client: NewClient(),
response: resp,
reader: progressBar.NewProxyReader(bufio.NewReaderSize(resp.Body, 4096*10)),
progressBar: progressBar,
}, nil
}
开发者ID:speedland,项目名称:service,代码行数:31,代码来源:command_copy.go
示例4: NewUploader
func NewUploader(albumID, title, path string) (*Uploader, error) {
contentType, err := getContentType(path)
if err != nil {
return nil, err
}
contentSize, err := getContentSize(path)
if err != nil {
return nil, err
}
file, err := os.Open(path)
if err != nil {
return nil, err
}
progressBar := pb.New64(contentSize)
progressBar.SetUnits(pb.U_BYTES)
progressBar.Prefix(title)
return &Uploader{
AlbumID: albumID,
Title: title,
FilePath: path,
ContentType: contentType,
ContentLength: contentSize,
client: NewClient(),
file: file,
reader: progressBar.NewProxyReader(bufio.NewReaderSize(file, 4096*10)),
progressBar: progressBar,
}, nil
}
开发者ID:speedland,项目名称:service,代码行数:28,代码来源:command_upload.go
示例5: TestThatProgressBarCanRewindProgress
func TestThatProgressBarCanRewindProgress(t *testing.T) {
nBytesToDownload := int64(1 << 8)
progressBar := pb.New64(nBytesToDownload).SetUnits(pb.U_BYTES)
progressBar.Output = new(DevNullWriter)
progressBar.Start()
reader := bytes.NewReader(make([]byte, nBytesToDownload))
dst := make([]byte, 1<<7)
bcr := &byteCountingReader{
R: reader,
}
read, _ := bcr.Read(dst)
if 1<<7 != read {
t.Fatalf("Expected to read %d bytes but read %d byte[s]", 1<<7, read)
}
// Pretend a failure happened, rewind progress
progressBar.Add64(int64(0 - bcr.bytesRead))
// reset variables
reader = bytes.NewReader(make([]byte, nBytesToDownload))
bcr = &byteCountingReader{
R: reader,
}
read, _ = bcr.Read(dst)
read, _ = bcr.Read(dst)
if len(dst) != read || nBytesToDownload != int64(bcr.bytesRead) {
t.Fatalf("Expected to read %d bytes but read %d byte[s] and "+
"to accumulate %d bytes but accumulated %d byte[s]", len(dst), read,
nBytesToDownload, bcr.bytesRead)
}
}
开发者ID:clyang,项目名称:skicka,代码行数:33,代码来源:skicka_test.go
示例6: Start
// Start starts showing progress
func (t *TextProgress) Start(label string, total float64) {
t.pbar = pb.New64(int64(total))
t.pbar.ShowSpeed = true
t.pbar.Units = pb.U_BYTES
t.pbar.Prefix(label)
t.pbar.Start()
}
开发者ID:pedronis,项目名称:snappy,代码行数:8,代码来源:progress.go
示例7: main
func main() {
stdout := os.Stdout
os.Stdout = os.Stderr
executable, err := exec.LookPath("dd")
if err != nil {
fmt.Printf("ddp: failed to find dd: %s\n", err)
os.Exit(1)
}
// Create pipe attached to a reader:
output, input, err := os.Pipe()
if err != nil {
panic(err)
}
// Setup process with _the_ three file descriptors:
files := []*os.File{
os.Stdin,
stdout,
input,
}
process, err := os.StartProcess(executable, os.Args, &os.ProcAttr{
Files: files,
})
if err != nil {
fmt.Printf("ddp: failed to start dd: %s\n", err)
os.Exit(1)
}
Trap(process)
target := GuessTargetSize(os.Args)
bar := pb.New64(target)
bar.SetUnits(pb.U_BYTES)
bar.ShowSpeed = true
bar.Output = os.Stderr
started := false
OutputScanner(io.Reader(output), os.Stderr, func(bytes int64) {
if !started {
started = true
bar.Start()
}
bar.Set64(bytes)
})
Interrupter(process, pb.DEFAULT_REFRESH_RATE)
state, err := process.Wait()
if err != nil {
panic(err)
}
if started && state.Success() {
bar.Finish()
}
output.Close()
if !state.Success() {
os.Exit(1)
}
}
开发者ID:koenbollen,项目名称:ddp,代码行数:60,代码来源:main.go
示例8: printBytes
func printBytes(bytesRead chan int, total int64, done chan bool) {
var r int
var n int64
var ok bool
bar := pb.New64(total)
bar.ShowSpeed = true
bar.ShowFinalTime = true
bar.SetUnits(pb.U_BYTES)
bar.Start()
for {
r, ok = <-bytesRead
n += int64(r)
bar.Set64(n)
if !ok {
break
}
}
bar.Finish()
done <- true
}
开发者ID:Lavos,项目名称:gbvideo,代码行数:26,代码来源:cli.go
示例9: acquireProgressBar
func acquireProgressBar(t time.Duration) (*pb.ProgressBar, <-chan time.Time) {
pb := pb.New64(int64(t.Seconds()))
pb.ShowCounters = false
pb.ShowPercent = false
pb.Start()
return pb, time.Tick(time.Second)
}
开发者ID:hagen1778,项目名称:fasthttploader,代码行数:7,代码来源:loader.go
示例10: newBar
func newBar(count int64) *pb.ProgressBar {
bar := pb.New64(count)
bar.ShowTimeLeft = true
bar.ShowSpeed = true
return bar
}
开发者ID:postfix,项目名称:goml-examples,代码行数:8,代码来源:mnist-softmax.go
示例11: main
func main() {
if len(os.Args) != 3 {
logrus.Fatalln("Usage: ddgo <src> <dest>")
}
src := os.Args[1]
dst := os.Args[2]
fd, err := os.OpenFile(src, os.O_RDONLY, 0)
if err != nil {
logrus.Fatalln("failed to open src:", err)
}
defer fd.Close()
srcLen, err := fd.Seek(0, 2)
if err != nil {
logrus.Fatalln(err)
}
_, err = fd.Seek(0, 0)
if err != nil {
logrus.Fatalln(err)
}
bar := pb.New64(srcLen)
bar.SetUnits(pb.U_BYTES)
bar.ShowSpeed = true
bar.ShowTimeLeft = true
out, err := os.OpenFile(dst, os.O_WRONLY|syscall.O_DIRECT, 0777)
if err != nil {
logrus.Fatalln("failed to open dst:", err)
}
defer out.Close()
dstLen, err := out.Seek(0, 2)
if err != nil {
logrus.Fatalln(err)
}
_, err = out.Seek(0, 0)
if err != nil {
logrus.Fatalln(err)
}
if dstLen < srcLen {
bar.Total = dstLen
}
bar.Start()
if dstLen < srcLen {
logrus.Warnln("destination device too small, not all bytes will be copied")
_, err = io.Copy(io.MultiWriter(bar, out), io.LimitReader(fd, dstLen))
} else {
_, err = io.Copy(io.MultiWriter(bar, out), fd)
}
if err != nil {
logrus.Fatalln("copy failed:", err)
}
bar.Finish()
fd.Close()
out.Close()
}
开发者ID:mastercactapus,项目名称:ddgo,代码行数:58,代码来源:main.go
示例12: CreateFileProgress
func CreateFileProgress(f *os.File) (*pb.ProgressBar, error) {
if fi, err := f.Stat(); err == nil {
bar := pb.New64(fi.Size())
bar.SetUnits(pb.U_BYTES)
return bar, nil
} else {
return nil, err
}
}
开发者ID:danieldk,项目名称:dparnn,代码行数:9,代码来源:io.go
示例13: newProgressBar
func (client *s3client) newProgressBar(total int64) *pb.ProgressBar {
progress := pb.New64(total)
progress.Output = client.progressOutput
progress.ShowSpeed = true
progress.Units = pb.U_BYTES
progress.NotPrint = true
return progress.SetWidth(80)
}
开发者ID:Pivotal-DataFabric,项目名称:s3-resource,代码行数:10,代码来源:s3client.go
示例14: getProgressBar
func getProgressBar(nBytes int64) *pb.ProgressBar {
if quiet {
return nil
}
progressBar := pb.New64(nBytes).SetUnits(pb.U_BYTES)
progressBar.ShowBar = true
progressBar.Output = os.Stderr
progressBar.Start()
return progressBar
}
开发者ID:clyang,项目名称:skicka,代码行数:11,代码来源:download.go
示例15: Start
func (pm *ProgressMeter) Start(total int64) {
pm.bar = pb.New64(total)
pm.bar.Prefix(pm.prefix)
pm.bar.SetMaxWidth(70)
pm.bar.SetUnits(pb.U_BYTES)
pm.bar.SetRefreshRate(200 * time.Millisecond)
pm.bar.Output = pm.out
pm.bar.Start()
pm.total = total
}
开发者ID:convox,项目名称:rack,代码行数:11,代码来源:progress.go
示例16: ShowProgressBar
func ShowProgressBar(totalBytes int64) *pb.ProgressBar {
log.Debugf("Creating progress bar for %d bytes", totalBytes)
bar := pb.New64(totalBytes)
bar.SetMaxWidth(70)
bar.ShowCounters = false
bar.ShowSpeed = true
bar.SetUnits(pb.U_BYTES)
bar.Format("[##-]")
bar.Prefix(" ")
bar.Start()
return bar
}
开发者ID:rootwzrd,项目名称:appstax-cli,代码行数:12,代码来源:term.go
示例17: NewProgressBar
// NewProgressBar initializes new progress bar based on size of file
func NewProgressBar(file *os.File) *pb.ProgressBar {
fi, err := file.Stat()
total := int64(0)
if err == nil {
total = fi.Size()
}
bar := pb.New64(total)
bar.SetUnits(pb.U_BYTES)
return bar
}
开发者ID:RapidMVP,项目名称:pgfutter,代码行数:13,代码来源:progressbar.go
示例18: initBar
func initBar(f *os.File) {
fi, err := f.Stat()
if err != nil {
fmt.Println("Could not stat", f.Name())
os.Exit(1)
}
bar = pb.New64(fi.Size()).SetUnits(pb.U_BYTES).SetRefreshRate(time.Millisecond * 10)
bar.ShowPercent = true
bar.ShowSpeed = true
bar.ShowTimeLeft = true
bar.Start()
}
开发者ID:Depado,项目名称:goploader,代码行数:12,代码来源:main.go
示例19: uncompressFromHttp
func (m *SymlinkWebotsManager) uncompressFromHttp(v WebotsVersion, addr string) error {
dest := path.Join(m.workpath, v.String())
err := os.RemoveAll(dest)
if err != nil {
return err
}
err = os.MkdirAll(dest, 0775|os.ModeSetgid)
if err != nil {
return err
}
resp, err := http.Get(addr)
if err != nil {
return err
}
var netReader io.Reader = resp.Body
if resp.ContentLength >= 0 {
//adds a progress bar
progress := make(chan int64)
go func() {
bar := pb.New64(resp.ContentLength)
bar.Format("[=>_]")
bar.Start()
for n := range progress {
bar.Add64(n)
}
bar.FinishPrint(fmt.Sprintf("Downloaded and extracted %s", addr))
}()
netReader = &ProgressReader{
reader: resp.Body,
progress: progress,
}
defer close(progress)
}
tarReader := tar.NewReader(bzip2.NewReader(netReader))
for {
fileHeader, err := tarReader.Next()
if err == io.EOF {
break
}
if err != nil {
return err
}
err = m.extractFile(v, fileHeader, tarReader)
if err != nil {
return fmt.Errorf("Cannot extract %s: %s", fileHeader.Name, err)
}
}
return nil
}
开发者ID:biorob,项目名称:webots-manager,代码行数:52,代码来源:webots_instance_manager.go
示例20: newProgressBar
// newProgressBar - instantiate a progress bar.
func newProgressBar(total int64) *progressBar {
// Progress bar speific theme customization.
console.SetColor("Bar", color.New(color.FgGreen, color.Bold))
pgbar := progressBar{}
// get the new original progress bar.
bar := pb.New64(total)
// Set new human friendly print units.
bar.SetUnits(pb.U_BYTES)
// Refresh rate for progress bar is set to 125 milliseconds.
bar.SetRefreshRate(time.Millisecond * 125)
// Do not print a newline by default handled, it is handled manually.
bar.NotPrint = true
// Show current speed is true.
bar.ShowSpeed = true
// Custom callback with colorized bar.
bar.Callback = func(s string) {
console.Print(console.Colorize("Bar", "\r"+s))
}
// Use different unicodes for Linux, OS X and Windows.
switch runtime.GOOS {
case "linux":
// Need to add '\x00' as delimiter for unicode characters.
bar.Format("┃\x00▓\x00█\x00░\x00┃")
case "darwin":
// Need to add '\x00' as delimiter for unicode characters.
bar.Format(" \x00▓\x00 \x00░\x00 ")
default:
// Default to non unicode characters.
bar.Format("[=> ]")
}
// Start the progress bar.
if bar.Total > 0 {
bar.Start()
}
// Copy for future
pgbar.ProgressBar = bar
// Return new progress bar here.
return &pgbar
}
开发者ID:balamurugana,项目名称:mc,代码行数:51,代码来源:progress-bar.go
注:本文中的github.com/cheggaaa/pb.New64函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论