GO語言"bytes"包中"Buffer"類型的用法及代碼示例。
緩衝區是具有讀取和寫入方法的 variable-sized 字節緩衝區。 Buffer 的零值是一個可以使用的空緩衝區。
用法:
type Buffer struct {
// contains filtered or unexported fields
}
例子:
package main
import (
"bytes"
"fmt"
"os"
)
func main() {
var b bytes.Buffer // A Buffer needs no initialization.
b.Write([]byte("Hello "))
fmt.Fprintf(&b, "world!")
b.WriteTo(os.Stdout)
}
輸出:
Hello world!
示例(讀者):
package main
import (
"bytes"
"encoding/base64"
"io"
"os"
)
func main() {
// A Buffer can turn a string or a []byte into an io.Reader.
buf := bytes.NewBufferString("R29waGVycyBydWxlIQ==")
dec := base64.NewDecoder(base64.StdEncoding, buf)
io.Copy(os.Stdout, dec)
}
輸出:
Gophers rule!
相關用法
- GO Buffer.Bytes用法及代碼示例
- GO Buffer.Read用法及代碼示例
- GO Buffer.Len用法及代碼示例
- GO Buffer.Next用法及代碼示例
- GO Buffer.ReadByte用法及代碼示例
- GO Buffer.Cap用法及代碼示例
- GO Buffer.Grow用法及代碼示例
- GO Builder用法及代碼示例
- GO B.RunParallel用法及代碼示例
- GO B.ReportMetric用法及代碼示例
- GO Base用法及代碼示例
- GO ByteOrder用法及代碼示例
- GO BinaryOp用法及代碼示例
- GO PutUvarint用法及代碼示例
- GO Scanner.Scan用法及代碼示例
- GO LeadingZeros32用法及代碼示例
- GO NewFromFiles用法及代碼示例
- GO Regexp.FindString用法及代碼示例
- GO Time.Sub用法及代碼示例
- GO Regexp.FindAllIndex用法及代碼示例
注:本文由純淨天空篩選整理自golang.google.cn大神的英文原創作品 Buffer。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。