| Crates.io | buf_read_write |
| lib.rs | buf_read_write |
| version | 0.5.0 |
| created_at | 2024-12-20 20:31:07.391485+00 |
| updated_at | 2024-12-21 10:49:50.435747+00 |
| description | Buffered IO. Like BufWriter and BufReader combined into one, with Seek-support. |
| homepage | |
| repository | https://github.com/avl/buf_read_write |
| max_upload_size | |
| id | 1490502 |
| size | 78,004 |
This crate contains a a buffered io implementation, a combination of std::io::BufReader
and std::io::BufWriter. This allows buffered input and output, for example with a std::fs::File.
The difference between this and regular BufWriter and BufReader is that a single instance can buffer both reads and writes to the same backing object (for example a File).
This crate is meant to be used with file-like objects, and requires the backing implementation
to implement std::io::Seek.
buf_read_write is not a general disk caching library. The buffer is always contiguous.
Let's say you have a large data file stored on disk. The file contains many chunks, each with its own header.
You wish to traverse the file, and rewrite a few fields in each header.
You can do the following sequence of operations:
Only one IO-operation will be emitted (this is of course the point of buffered IO). Note however, that this is true even if the written sub-fields are not adjacent - as long as they fit within the buffer size.
If you do not first read the file, and then write non-contiguous regions, there will be an IO operation for
every such non-contiguous region. The reason is that buf_read_write does not support non-contiguous buffers,
and thus cannot represent a non-contiguous set of updates.
Note, a consequence of this is that the number of bytes actually written can be (much) larger than the number of actually modified bytes. If this is undesirable, make sure to call 'flush' after every write.