GO語言"io"包中"TeeReader"函數的用法及代碼示例。
用法:
func TeeReader(r Reader, w Writer) Reader
TeeReader 返回一個讀取器,它將從 r 讀取的內容寫入 w。通過它對 r 執行的所有讀取都與對 w 的相應寫入匹配。沒有內部緩衝 - 寫入必須在讀取完成之前完成。寫入時遇到的任何錯誤都報告為讀取錯誤。
例子:
package main
import (
"io"
"log"
"os"
"strings"
)
func main() {
var r io.Reader = strings.NewReader("some io.Reader stream to be read\n")
r = io.TeeReader(r, os.Stdout)
// Everything read from r will be copied to stdout.
if _, err := io.ReadAll(r); err != nil {
log.Fatal(err)
}
}
輸出:
some io.Reader stream to be read
相關用法
- GO Template用法及代碼示例
- GO TempFile用法及代碼示例
- GO TempDir用法及代碼示例
- GO Template.Delims用法及代碼示例
- GO Time.Sub用法及代碼示例
- GO TrailingZeros8用法及代碼示例
- GO Tx.ExecContext用法及代碼示例
- GO Time.Equal用法及代碼示例
- GO ToTitle用法及代碼示例
- GO Time.After用法及代碼示例
- GO Title用法及代碼示例
- GO TrimRight用法及代碼示例
- GO ToLowerSpecial用法及代碼示例
- GO Time.Format用法及代碼示例
- GO ToUpper用法及代碼示例
- GO Trunc用法及代碼示例
- GO TrailingZeros32用法及代碼示例
- GO To用法及代碼示例
- GO Time.AppendFormat用法及代碼示例
- GO Time.AddDate用法及代碼示例
注:本文由純淨天空篩選整理自golang.google.cn大神的英文原創作品 TeeReader。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。