Buffer 是 Go 语言一个可组合的缓冲库。
示例代码:
import ( "github.com/djherbis/buffer" "github.com/djherbis/nio" "io/ioutil" ) // Buffer 32KB to Memory, after that buffer to 100MB chunked files buf := buffer.NewUnboundedBuffer(32*1024, 100*1024*1024) nio.Copy(w, r, buf) // Reads from r, writes to buf, reads from buf writes to w (concurrently). // Buffer 32KB to Memory, discard overflow buf = buffer.NewSpill(32*1024, ioutil.Discard) nio.Copy(w, r, buf)