#byte-offset #line-column #offset #byte-stream #numbers #io-read #converter

stream-locate-converter

A Stream reader which can convert between byte offset and line-column numbers. Support any type which implements io::Read.

3 releases

0.1.2 Jul 31, 2024
0.1.1 Jul 31, 2024
0.1.0 Jul 30, 2024

#4 in #byte-offset

Download history 230/week @ 2024-07-25 108/week @ 2024-08-01 22/week @ 2024-09-12 8/week @ 2024-09-19 32/week @ 2024-09-26 30/week @ 2024-10-03 3/week @ 2024-10-10

70 downloads per month

Custom license

11KB
257 lines

stream-locate-converter

Reader offset and line-column location converter.
A Stream reader which can convert between byte offset and line-column numbers. Support any type which implements io::Read.

Example

use stream_locate_converter::Stream;
use stream_locate_converter::location;
use std::fs;

fn main() -> io::Result<()> {
  let file = fs::File::open("foo.rs")?;
  let mut stream = Stream::from(file);

  let offset = location::Offset::new(20);
  let line_index = stream.line_index(offset)?;

  let (line, col) = line_index.one_based().raw();
  println!("The offset is on line {line}, column {col}.");
}

No runtime deps