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

#75 in Filesystem

Download history 3700/week @ 2024-08-02 4437/week @ 2024-08-09 3631/week @ 2024-08-16 2586/week @ 2024-08-23 3070/week @ 2024-08-30 3119/week @ 2024-09-06 3088/week @ 2024-09-13 3540/week @ 2024-09-20 3189/week @ 2024-09-27 3629/week @ 2024-10-04 5396/week @ 2024-10-11 5455/week @ 2024-10-18 6171/week @ 2024-10-25 8109/week @ 2024-11-01 7795/week @ 2024-11-08 8239/week @ 2024-11-15

31,203 downloads per month
Used in 72 crates (19 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