Skip to content

Commit

Permalink
fix: update clap and fix example
Browse files Browse the repository at this point in the history
  • Loading branch information
nlfiedler committed Jan 12, 2023
1 parent 300a866 commit 06d6b48
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 24 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).
This file follows the convention described at
[Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

## [1.0.7] - 2023-01-11
### Added
- dristic: expose hash on chunk struct.

## [1.0.6] - 2021-01-08
### Added
- rickvanprim: implement `size_hint()` for FastCDC struct.
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fastcdc"
version = "1.0.6"
version = "1.0.7"
authors = ["Nathan Fiedler <[email protected]>"]
edition = "2018"
description = "FastCDC (content defined chunking) in pure Rust."
Expand All @@ -16,4 +16,4 @@ exclude = [
[dev-dependencies]
memmap = "0.7.0"
crypto-hash = "0.3.4"
clap = "3.0.5"
clap = { version = "4.0.32", features = ["cargo"] }
32 changes: 10 additions & 22 deletions examples/dedupe.rs
Original file line number Diff line number Diff line change
@@ -1,32 +1,20 @@
//
// Copyright (c) 2020 Nathan Fiedler
// Copyright (c) 2023 Nathan Fiedler
//
use clap::{App, Arg};
use clap::{arg, command, value_parser, Arg};
use crypto_hash::{hex_digest, Algorithm};
use fastcdc::*;
use memmap::MmapOptions;
use std::fs::File;
use std::str::FromStr;

fn main() {
fn is_integer(v: &str) -> Result<(), String> {
if u64::from_str(&v).is_ok() {
return Ok(());
}
Err(String::from(
"The size must be a valid unsigned 64-bit integer.",
))
}
let matches = App::new("Example of using fastcdc crate.")
let matches = command!("Example of using fastcdc crate.")
.about("Splits a (large) file and computes checksums.")
.arg(
Arg::new("size")
.short('s')
.long("size")
.value_name("SIZE")
.help("The desired average size of the chunks.")
.takes_value(true)
.validator(is_integer),
arg!(
-s --size <SIZE> "The desired average size of the chunks."
)
.value_parser(value_parser!(u64)),
)
.arg(
Arg::new("INPUT")
Expand All @@ -35,9 +23,9 @@ fn main() {
.index(1),
)
.get_matches();
let size = matches.value_of("size").unwrap_or("131072");
let avg_size = u64::from_str(size).unwrap() as usize;
let filename = matches.value_of("INPUT").unwrap();
let size = matches.get_one::<u64>("size").unwrap_or(&131072);
let avg_size = *size as usize;
let filename = matches.get_one::<String>("INPUT").unwrap();
let file = File::open(filename).expect("cannot open file!");
let mmap = unsafe { MmapOptions::new().map(&file).expect("cannot create mmap?") };
let min_size = avg_size / 2;
Expand Down

0 comments on commit 06d6b48

Please sign in to comment.