#io #seek #read #file #part #allowing #partition

io_partition

A library allowing to use just a part of a Read + Seek object

4 stable releases

1.1.1 Feb 11, 2021
1.0.1 Feb 9, 2021
1.0.0 Mar 9, 2020

#615 in Concurrency

Download history 307/week @ 2023-12-12 248/week @ 2023-12-19 581/week @ 2023-12-26 597/week @ 2024-01-02 416/week @ 2024-01-09 115/week @ 2024-01-16 169/week @ 2024-01-23 276/week @ 2024-01-30 111/week @ 2024-02-06 93/week @ 2024-02-13 103/week @ 2024-02-20 90/week @ 2024-02-27 394/week @ 2024-03-05 171/week @ 2024-03-12 106/week @ 2024-03-19 696/week @ 2024-03-26

1,388 downloads per month
Used in 13 crates (4 directly)

CC0 license

21KB
366 lines

io_partition

This rust crate allow to take a part of an object that implement Read + Seek (typically a file), by specifing it's offset and lenght. It can also build similar item with an Arc<Mutex>, ensuring coherency of the pointer in the file, allowing to access the same file concurrently (althougth it isn't optimized for speed, as it have to unlock the Mutex and seek to the good position).

This mutex can however be locked for single-threader access, allowing near-native performance.


lib.rs:

This rust crate allow to take a part of an object that implement Read + Seek (typically a file), by specifying it's offset and lenght. It can also build similar item with an Arc<Mutex>, ensuring coherency of the pointer in the file, allowing to access the same file concurrently (althougth it isn't optimized for speed, as it have to unlock the Mutex and seek to the good position).

Examples

use std::io::{Cursor, Read};
use io_partition::Partition;
let file = Cursor::new(&[0, 2, 4, 6, 8, 10, 12]);

let mut sub_file = Partition::new(file, 2, 3).unwrap();
let mut buffer = [0, 0, 0, 0, 0];
assert_eq!(sub_file.read(&mut buffer).unwrap(), 3);
assert_eq!(buffer, [4, 6, 8, 0, 0]);

Dependencies

~320–780KB
~18K SLoC