What is the most efficient way to read a large file in chunks without loading the entire file in memory at once?

后端 未结 1 1279
醉话见心
醉话见心 2020-12-16 12:35

What is the most efficient general purpose way of reading \"large\" files (which may be text or binary), without going into unsafe territory? I was surprised ho

相关标签:
1条回答
  • 2020-12-16 13:17

    I don't think you can write code more efficient than that. fill_buf on a BufReader over a File is basically just a straight call to read(2).

    That said, BufReader isn't really a useful abstraction when you use it like that; it would probably be less awkward to just call file.read(&mut buf) directly.

    0 讨论(0)
提交回复
热议问题