zsplit

Crates.iozsplit
lib.rszsplit
version0.4.0
sourcesrc
created_at2021-11-30 14:53:10.399054
updated_at2023-11-23 18:07:59.354777
descriptionSplit text into multiple files by line
homepagehttps://zschoen.dev/projects/zsplit
repositoryhttps://github.com/TheAlgorythm/zsplit
max_upload_size
id489818
size19,004
zSchoen (TheAlgorythm)

documentation

https://docs.rs/crate/zsplit

README

zsplit

LGPL 3.0 License Workflow Status Crates.io crev reviews

Split text into multiple files by line.

This is the library and not the CLI application. It is called zsplit-cli.

Examples

Simple

use zsplit::prelude::*;

let data = "0\n1\n2\n3\n4\n5\n6\n7\n8\n9";
let mut source = std::io::BufReader::new(data.as_bytes());
let mut destinations = vec![
    Destination::buffer(), // first_destination
    Destination::buffer(), // second_destination
    Destination::buffer(), // third_destination
];

split_round_robin(&mut source, &mut destinations).unwrap();

let third_destination = destinations.pop().unwrap();
let second_destination = destinations.pop().unwrap();
let first_destination = destinations.pop().unwrap();

assert_eq!(first_destination.into_utf8_string().unwrap(), "0\n3\n6\n9");
assert_eq!(second_destination.into_utf8_string().unwrap(), "1\n4\n7\n");
assert_eq!(third_destination.into_utf8_string().unwrap(), "2\n5\n8\n");

Visualisation of simple

Unsymmetric Distribution

use zsplit::prelude::*;

let data = "0\n1\n2\n3\n4\n5\n6\n7\n8\n9";
let mut source = std::io::BufReader::new(data.as_bytes());
let mut destinations = vec![
    Destination::buffer_with_lines(3), // first_destination
    Destination::buffer_with_lines(3), // second_destination
    Destination::buffer(), // third_destination
];

split_round_robin(&mut source, &mut destinations).unwrap();

let third_destination = destinations.pop().unwrap();
let second_destination = destinations.pop().unwrap();
let first_destination = destinations.pop().unwrap();

assert_eq!(first_destination.into_utf8_string().unwrap(), "0\n1\n2\n7\n8\n9\n");
assert_eq!(second_destination.into_utf8_string().unwrap(), "3\n4\n5\n");
assert_eq!(third_destination.into_utf8_string().unwrap(), "6\n");

Visualisation of unsymmetric distribution

CREV - Rust code reviews - Raise awareness

Please, spread this info !
Open source code needs a community effort to express trustworthiness.
Start with reading the reviews of the crates you use. Example: web.crev.dev/rust-reviews/crate/num-traits/
Than install the CLI cargo-crev. Read the Getting Started guide.
On your Rust project, verify the trustworthiness of all dependencies, including transient dependencies with cargo crev verify
Write a new review !
Describe the crates you trust. Or warn about the crate versions you think are dangerous.
Help other developers, inform them and share your opinion.
Use the helper on this webpage: web.crev.dev/rust-reviews/review_new

Commit count: 104

cargo fmt