file-region 0.1.0

Encapsulates a contiguous byte range of a file
Documentation
  • Coverage
  • 8.33%
    1 out of 12 items documented0 out of 11 items with examples
  • Size
  • Source code size: 13.4 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 307.6 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 8s Average build duration of successful builds.
  • all releases: 8s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • xpe/file-region
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • xpe

file-region

This crate provides a FileRegion type which encapsulates a particular region of a File.

Example

You can find this example at examples/basic.rs and run it with cargo run --example basic.

use file_region::FileRegion;
use std::io::{Read, Seek, SeekFrom, Write};
use tempfile::tempfile;

fn main() -> std::io::Result<()> {
    let mut file = tempfile()?;
    file.write_all(b"Hello, FileRegion.")?;

    let mut region = FileRegion::new(&file, 7..16);
    let mut buffer = [0; 9];
    region.read(0, &mut buffer)?;
    assert_eq!(&buffer, b"FileRegio");

    region.write(0, b"01234")?;

    let mut content = String::new();
    file.seek(SeekFrom::Start(0))?;
    file.read_to_string(&mut content)?;
    assert_eq!(content, "Hello, 01234egion.");

    Ok(())
}