文件流:长生不老药

File Stream : Elixir

我经常在 Elixir 论坛看到:

"path/to/file"
|> File.stream!(read_ahead: 100_000)

read_ahead:100_000是什么意思?

它是 stream_mode's. It's meaning is described in erlang 文档之一:

{read_ahead, Size} Activates read data buffering. If read/2 calls are for significantly less than Size bytes, read operations to the operating system are still performed for blocks of Size bytes. The extra data is buffered and returned in subsequent read/2 calls, giving a performance gain as the number of operating system calls is reduced.