利用io.Reader/Writers實現進度條的Go(golang)包:ioprogress

jopen 10年前發布 | 37K 次閱讀 Google Go/Golang開發 ioprogress

ioprogress是一個Go (golang)庫利用 io.Reader 和 io.Writer 來繪制進度條。它主要用在CLI 應用中。

687474703a2f2f672e7265636f726469742e636f2f474f35487854313651482e676966.gif

用法

Here is an example of outputting a basic progress bar to the CLI as we're "downloading" from some other io.Reader (perhaps from a network connection):

// Imagine this came from some external source, such as a network connection,
// and that we have the full size of it, such as from a Content-Length HTTP
// header.
var r io.Reader

// Create the progress reader
progressR := &ioprogress.Reader{
    Reader: r,
    Size:   rSize,
}

// Copy all of the reader to some local file f. As it copies, the
// progressR will write progress to the terminal on os.Stdout. This is
// customizable.
io.Copy(f, progressR)

項目主頁:http://www.baiduhome.net/lib/view/home/1417953544308

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!