Skip to content

Commit

Permalink
behead: add --flexible option
Browse files Browse the repository at this point in the history
when reading CSV files to omit num col check for performance.

Also set writes to be always flexibile for even more performance.
  • Loading branch information
jqnatividad committed Nov 16, 2023
1 parent ec80ec5 commit b469f9c
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/cmd/behead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Usage:
Common options:
-h, --help Display this message
-f, --flexible Do not validate if the CSV has different number of
fields per record, increasing performance.
-o, --output <file> Write output to <file> instead of stdout.
"#;

Expand All @@ -16,16 +18,18 @@ use crate::{config::Config, util, CliResult};

#[derive(Deserialize)]
struct Args {
arg_input: Option<String>,
flag_output: Option<String>,
arg_input: Option<String>,
flag_flexible: bool,
flag_output: Option<String>,
}

pub fn run(argv: &[&str]) -> CliResult<()> {
let args: Args = util::get_args(USAGE, argv)?;
let conf = Config::new(&args.arg_input).no_headers(false);

let mut rdr = conf.reader()?;
let mut wtr = Config::new(&args.flag_output).writer()?;
let mut rdr = conf.flexible(args.flag_flexible).reader()?;
// write is always flexible for performance
let mut wtr = Config::new(&args.flag_output).flexible(true).writer()?;
let mut record = csv::ByteRecord::new();

while rdr.read_byte_record(&mut record)? {
Expand Down

0 comments on commit b469f9c

Please sign in to comment.