1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
//! concat-reader is a library for Rust that contains utility functions and traits to create
//! concatenated [`Read`] objects from any thing that implements [`IntoIterator`].
//!
//! ```no_run
//! 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())?;
//! }
//! }
//! ```
//! [`READ`]: https://doc.rust-lang.org/std/io/trait.Read.html
//! [`IntoIterator`]: https://doc.rust-lang.org/std/iter/trait.IntoIterator.html
use Read;
use Path;
pub use FileConcatReader;
pub use ConcatReader;
/// Concats multiple readers into a single reader.
///
/// ```
/// use concat_reader::concat;
/// use std::io::Read;
///
/// let value1 = "some string".as_bytes();
/// let value2 = "another string".as_bytes();
///
/// let mut buffer = String::new();
/// let mut f = concat(vec![value1, value2]);
/// f.read_to_string(&mut buffer).unwrap();
/// ```
/// Concats multiple file paths into a single reader over all files.
///
/// ```no_run
/// 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())?;
/// }
/// }
/// ```
/// A special [`Read`] trait for concatenated readers.
///
/// This traids adds special function to fetch the current `Read` item and to skip to the next item.
/// `FileConcatRead` is a kind of `ConcatRead` which can provide information about the file currently read.
///
/// # Example
///
/// ```no_run
/// use std::io;
/// use std::io::prelude::*;
/// use std::path::Path;
/// use crate::concat_reader::*;
///
/// 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);
/// assert!(f.file_path().is_none());
/// let mut buffer = [0; 10];
/// f.read(&mut buffer)?;
/// assert_eq!(f.file_path(), Some(Path::new("/path/to/file_1")));
/// Ok(())
/// }