In go I have a net.Conn that I wrap with a bufio.Reader. I want to read and parse certain number of lines from the reader, and then obtain back the control over the net.Conn, obtaining back all the temporary data the reader might still have buffered. Is there an easy way to do it?
1条回答 默认 最新
doudengshen5591 2016-06-01 20:50关注You can get the buffered data from a
*bufio.Readerusing the following code:p, _ := br.Peek(br.Buffered())where
pis a[]bytecontaining the buffered data andbris a*bufio.Reader.Many applications use the
*bufio.Readeras anio.Readerafter callingReadLineand related methods. There's no need to get the buffered data in these applications. The reader will continue reading from the buffered data as needed.本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报