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


Golang pb.New64函數代碼示例

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


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


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