利用io.Reader/Writers实现进度条的Go(golang)包:ioprogress

jopen 10年前

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.open-open.com/lib/view/home/1417953544308