positioned-io2

Crates.iopositioned-io2
lib.rspositioned-io2
version0.3.4
sourcesrc
created_at2022-07-12 10:04:05.027271
updated_at2022-07-12 10:04:24.803333
descriptionReading and writing at an offset
homepage
repositoryhttps://github.com/surban/positioned-io2
max_upload_size
id624305
size1,066,898
Sebastian Urban (surban)

documentation

README

positioned-io2

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

Fork

This is a fork of positioned-io, which seem to have become unmaintained.

Example

Read the fifth 512-byte sector of a file:

use std::fs::File;
use positioned_io2::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.

License

positioned-io2 is licensed under the MIT license.

Commit count: 140

cargo fmt