#reader #io #adapter

concat-reader

Adapter for reading through multiple reader continuously

1 unstable release

0.1.0 Aug 16, 2019

#73 in #adapter

Download history 18/week @ 2024-01-05 17/week @ 2024-01-12 15/week @ 2024-01-19 57/week @ 2024-01-26 104/week @ 2024-02-02 13/week @ 2024-02-09 25/week @ 2024-02-16 277/week @ 2024-02-23 448/week @ 2024-03-01 353/week @ 2024-03-08 338/week @ 2024-03-15 340/week @ 2024-03-22 189/week @ 2024-03-29 375/week @ 2024-04-05 356/week @ 2024-04-12 302/week @ 2024-04-19

1,349 downloads per month
Used in 2 crates

Apache-2.0

26KB
480 lines

concat-reader

Adapter for reading through multiple reader continuously

Build Status Crates.io

concat-reader is a library for Rust that contains utility functions and traits to create concatenated Read objects from any thing that implements IntoIterator.

  use concat_reader::{FileConcatRead, concat_path};
  use std::io::{self, Read, BufRead, BufReader, Write};
  fn main() -> io::Result<()>{
      let files = vec!["/path/to/file_1", "/path/to/file_2", "/path/to/file_3"];
      let mut f = concat_path(files);
      let mut buffered = BufReader::new(f);
      let stdout = io::stdout();
      let mut handle = stdout.lock();
      loop {
          let mut line = String::new();
          let r = buffered.read_line(&mut line)?;
          if r == 0 {
              return Ok(())
          }
          let f = buffered.get_ref().file_path();
          eprintln!("read from {:?}", f);
          handle.write(line.as_bytes())?;
      }
  }

Documentation: https://docs.rs/concat-reader

license

Apache License 2.0

No runtime deps