Ruby IO#read 单次读取的最大长度
如何确定当前平台上单次读取中 IO#read 可以获得的最大长度?
irb(main):301:0> File.size('C:/large.file') / 1024 / 1024
=> 2145
irb(main):302:0> s = IO.read 'C:/large.file'
IOError: file too big for single read
How can i determine the max length IO#read can get in a single read on the current platform?
irb(main):301:0> File.size('C:/large.file') / 1024 / 1024
=> 2145
irb(main):302:0> s = IO.read 'C:/large.file'
IOError: file too big for single read
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该消息来自 io.c,remain_size 。当文件(剩余)大小大于或等于
LONG_MAX
时发出。该值取决于编译 Ruby 的平台。至少在 Ruby 1.8.7 中,Fixnums 的最大值恰好是该值的一半 (-1),因此您可以通过
You should not see the limit 来获得限制,而不要依赖它。
That message comes from io.c, remain_size. It is emitted when the (remaining) size of the file is greater or equal to
LONG_MAX
. That value depends on the platform your Ruby has been compiled with.At least in Ruby 1.8.7, the maximum value for Fixnums happens to be just half of that value (-1), so you could get the limit by
You should rather not rely on that.