如何在Go中读取至少N个字节

huangapple go评论99阅读模式
英文:

How to read at least N bytes in Go

问题

你如何确保在Go语言中从文件读取时至少获取n个字节?该函数似乎返回你获取的字节数,但我宁愿等待更多的字节可用。在不进行大量手动操作的情况下,是否有可能实现这一点?

英文:

How do you ensure you get at least n bytes when reading from a file in Go? The function seems to return the number of bytes you got, but I would rather just wait until more bytes are available. Is this possible without doing a bunch of manual plumbing?

答案1

得分: 3

使用io.ReadAtLeast()函数:http://golang.org/pkg/io/#ReadAtLeast

英文:

Use io.ReadAtLeast() function: http://golang.org/pkg/io/#ReadAtLeast

huangapple
  • 本文由 发表于 2011年10月11日 09:05:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/7720384.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定