var r bufio.Reader如何檢查是否r沒有更多數據(為空、已耗盡)?我知道這可能需要阻止,直到知道該信息為止。谷歌搜索找不到任何東西。我認為該Peek函數對于查看是否有更多數據很有用,但這似乎只能查看底層緩沖區(如果存在)。我也可以嘗試Read一個字節然后調用UnreadByte,但這非?;靵y和不清楚,有沒有更好的選擇?
2 回答

弒天下
TA貢獻1818條經驗 獲得超8個贊
如果我正確理解你的問題,這會起作用嗎?
// func (*Reader) Size() int
// Size returns the size of the underlying buffer in bytes.
size := r.Size()
// func (*Reader) Buffered() int
// Buffered returns the number of bytes that can be read from the current buffer
buffered := r.Buffered()
- 2 回答
- 0 關注
- 115 瀏覽
添加回答
舉報
0/150
提交
取消