8 releases

Uses old Rust 2015

0.3.3 Nov 1, 2023
0.3.2 Aug 19, 2023
0.3.1 Nov 3, 2022
0.3.0 Aug 27, 2022
0.1.0 Jul 6, 2016

#2 in #io-read

Download history 1972/week @ 2023-12-19 998/week @ 2023-12-26 1975/week @ 2024-01-02 2339/week @ 2024-01-09 3078/week @ 2024-01-16 3703/week @ 2024-01-23 3468/week @ 2024-01-30 3265/week @ 2024-02-06 3311/week @ 2024-02-13 3293/week @ 2024-02-20 3711/week @ 2024-02-27 3531/week @ 2024-03-05 4074/week @ 2024-03-12 4718/week @ 2024-03-19 2853/week @ 2024-03-26 3539/week @ 2024-04-02

15,569 downloads per month
Used in 69 crates (20 directly)

MIT license

490KB
1K SLoC

positioned-io

This crate allows you to specify an offset for reads and writes, without changing the current position in a file. This is similar to pread() and pwrite() in C.

The major advantages of this type of I/O are:

  • You don't need to seek before doing a random-access read or write, which is convenient.
  • Reads don't modify the file at all, so don't require mutability.

Crates.io Documentation

Example

Read the fifth 512-byte sector of a file:

use std::fs::File;
use positioned_io::ReadAt;

// note that file does not need to be mut
let file = File::open("tests/pi.txt")?;

// read up to 512 bytes
let mut buf = [0; 512];
let bytes_read = file.read_at(2048, &mut buf)?;

Note: If possible use the RandomAccessFile wrapper. On Windows ReadAt directly on File is very slow.

Documentation

https://docs.rs/positioned-io

License

positioned-io is licensed under the MIT license.

Dependencies