8841b389e3
In the uncommon circumstance that calls to `read()` end up reading any number of bytes other than 4096, the subsequently read bytes become misaligned, causing blocks of zeroes to be written unnecessarily. To illustrate, imagine you have a 12KiB file: [x][x][x][x][ ][ ][ ][ ][x][x][x][x] └──4096──┘ └──4096──┘ └──4096──┘ The first and last block are filled with some data, whereas the middle block is empty and will therefore result in only zeroes being read. In order for the empty block to be skipped with `seek()`, the entire buffer has to be filled with zeroes. If, for example, the first `read()` ends up putting only 3KiB into the buffer, the empty block in the middle won't be detected properly, as the buffer will now always contain some data. What results are four misaligned reads: [x][x][x][x][ ][ ][ ][ ][x][x][x][x] ├─────┘ ├────────┘ ├────────┘ │ 1 2 3 4 This is fixed by ensuring chunks of 4KiB are always read into the buffer, except when the last block is truncated. In order to prevent frequent small reads, the incoming reader is also buffered via `io::BufReader`. Signed-off-by: Max Carrara <m.carrara@proxmox.com> |
||
---|---|---|
.. | ||
debian | ||
src | ||
Cargo.toml |