dir_lines_streamer

Crates.iodir_lines_streamer
lib.rsdir_lines_streamer
version0.2.0
sourcesrc
created_at2019-01-09 16:43:59.879029
updated_at2019-01-28 21:02:52.587409
descriptionRead files inside a directory line-by-line, one file after the other (in human-alphabetical order)
homepagehttps://github.com/ElementAI/dir_lines_streamer
repositoryhttps://github.com/ElementAI/dir_lines_streamer
max_upload_size
id107631
size25,921
Nicolas Bigaouette (nbigaouette)

documentation

README

dir_lines_streamer

dir_lines_streamer is a Rust crate allowing reading files inside a directory line-by-line, one file after the other (in human-alphabetical order).

# Cargo.toml
[dependencies]
dir_lines_streamer = "0.1"

Example

Let's say you have a directory containing files split by logrotate that you want to read line-by-line:

ls fixtures/non-empty-dir/
messages        messages.1      messages.10     messages.2      messages.20

Note how the alphabetical ordering sorts messages.10 before messages.2.

This crate allows creating a structure that implements the trait Iterator<Item = String> which returns the lines of the files.

use failure; // Crate failure 0.1
use dir_lines_streamer::DirectoryLinesStreamer;

let streamer_result: Result<DirectoryLinesStreamer, failure::Error> = DirectoryLinesStreamer::from_dir("fixtures/non-empty-dir");

// Read all lines of all files inside the directory and store them in a Vec<String>
let lines: Vec<String> = streamer.collect();

println!("lines: {:#?}", lines);

This will print:

lines: [
    "line one from messages\n",
    "line two from messages\n",
    "line three from messages\n",
    "line one from messages.1\n",
    "line two from messages.1\n",
    "line three from messages.1\n",
    "line one from messages.2\n",
    "line two from messages.2\n",
    "line three from messages.2\n",
    "line one from messages.10\n",
    "line two from messages.10\n",
    "line three from messages.10\n",
    "line one from messages.20\n",
    "line two from messages.20\n",
    "line three from messages.20\n"
]

License

Licensed under either of

at your option.

Copyright (c) Element AI Inc., 2018, by Nicolas Bigaouette. All rights reserved.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Commit count: 9

cargo fmt