dousui6488 2016-06-01 20:38 采纳率: 100%
浏览 241


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.Reader using the following code:

     p, _ := br.Peek(br.Buffered())

    where p is a []byte containing the buffered data and br is a *bufio.Reader.

    Many applications use the *bufio.Reader as an io.Reader after calling ReadLine and 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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?



    • ¥15 mysql报错1415Not allowed to return a result set from a trigger 不知如何修改
    • ¥60 Python输出Excel数据整理,算法较为复杂
    • ¥15 看一下这个,可以商量
    • ¥15 回答几个问题 关于数据库
    • ¥15 设计程序(标签-STM32|关键词-工作模式)
    • ¥15 51单片机串口通信问题,未完成且要修改
    • ¥15 百鸡问题 c++编程问题(相关搜索:输出数据)
    • ¥30 如何在CMD中设置代理
    • ¥15 我有一块薛定谔的硬盘
    • ¥15 微信小游戏开发2D碰撞检测问题