#file-copy #copy #file

is_copy

Determine whether two files are copies of each other

7 releases

0.1.6 Jan 6, 2023
0.1.5 Dec 26, 2022

#3 in #copy-file

34 downloads per month
Used in mmt

MIT/Apache

8KB
102 lines

is_copy

Determine whether two files are copies of each other

Usage

Add this to your Cargo.toml:

[dependencies]
is_copy = "0.1"

Examples

Create and determin file using is_copy:

use is_copy::is_file_copy;

let path_a = Path::new("./data/file_a.txt");
let path_b = Path::new("./data/file_b.txt");

let is_copy = is_file_copy(path_a, path_b);
println!("{:?} and {:?} is copy: {}", is_copy);

License

Licensed under either of

at your option.

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.


lib.rs:

Usage

Add this to your Cargo.toml:

[dependencies]
is_copy = "0.1"

Examples

Create and determin file using is_copy:

use std::{
    fs::{self, copy, File},
    io::Write,
    path::{Path, PathBuf},
};
use is_copy::is_file_copy;

let path_data = Path::new("./data");
if path_data.exists() {
    fs::remove_dir_all(path_data).unwrap();
}
fs::create_dir_all(path_data).unwrap();
let path_a = path_data.join("file_a.txt");
let path_a_copy = path_data.join("file_a_copy.txt");
let path_b = path_data.join("file_b.txt");
let mut file_a = File::create(&path_a).unwrap();
let mut file_b = File::create(&path_b).unwrap();
file_a.write_all(b"this is file a").unwrap();
file_b.write_all(b"this is file b").unwrap();
for i in 0..1_000 {
    let line = format!("this is line {}\n", i);
    file_a.write_all(line.as_bytes()).unwrap();
    file_b.write_all(line.as_bytes()).unwrap();
}
copy(&path_a, &path_a_copy).unwrap();
assert!(is_file_copy(&path_a, &path_a_copy));
assert!(!is_file_copy(&path_a, &path_b));

Dependencies

~87KB