9 releases

0.3.4 Apr 6, 2025
0.3.3 Nov 1, 2023
0.3.2 Aug 19, 2023
0.3.1 Nov 3, 2022
0.1.0 Jul 6, 2016

#53 in Filesystem

Download history 10342/week @ 2025-01-06 10251/week @ 2025-01-13 10221/week @ 2025-01-20 8680/week @ 2025-01-27 10607/week @ 2025-02-03 11966/week @ 2025-02-10 10181/week @ 2025-02-17 10617/week @ 2025-02-24 11928/week @ 2025-03-03 14516/week @ 2025-03-10 12911/week @ 2025-03-17 12092/week @ 2025-03-24 14848/week @ 2025-03-31 16095/week @ 2025-04-07 14250/week @ 2025-04-14 13932/week @ 2025-04-21

59,587 downloads per month
Used in 82 crates (21 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