duanba4254
2014-02-12 20:52
浏览 11
已采纳

为什么ReadRequest使用bufio.Reader?

The method http.ReadRequest takes a bufio.Reader instead of an io.Reader. What is the reason behind this?

图片转代码服务由CSDN问答提供 功能建议

http.ReadRequest 方法采用 bufio.Reader 而不是 io.Reader 。 造成这种情况的原因是什么?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doubo1883 2014-02-12 22:31
    已采纳

    It will use buffered reader anyway. But it will not automatically wrap your io.Reader into buffer because of bufio.Reader nature - it can grab more data from underlying io.Reader that algorithm actually need. And, since underlying io.Reader cannot push back that exceed data, it will remain in that buffer. In case of autowrap that buffer would be lost after request was read and your io.Reader become corrupted. Thus, it ask you to explicitly wrap your reader to prevent data loss.

    点赞 打赏 评论

相关推荐