14 releases

0.1.8 Nov 8, 2024
0.1.7 Nov 8, 2024
0.1.6 Oct 13, 2023
0.1.3 Apr 21, 2023
0.0.5 Apr 17, 2023

#132 in Command line utilities

Download history 1/week @ 2024-09-17 5/week @ 2024-09-24 1/week @ 2024-10-29 213/week @ 2024-11-05 18/week @ 2024-11-12 12/week @ 2024-11-19

244 downloads per month

MIT/Apache

105KB
732 lines

biff

Crates.io Code coverage build Linux build Windows build MacOs MIT licensed Apache 2.0 licensed Contributor Covenant

Overview

Compare two files byte by byte.

biff compares two files byte by byte, and if they differ, tells the first byte and line number where they differ. Additionally, when option -l or --verbose is set, biff will display all differing bytes.

biff may also skip some initial bytes in compared files or compare only up to requested number of bytes.

When comparing binary files, biff may check the beginning bytes if they match the specified marker, so only files having such marker will be compared.

There are also some popular cases, when compared files differ only in few bytes, but generally may be considered as similar and this is quite alright. For such comparisons biff may use the absolute total number of acceptable differences (option -a or --absolute) or percentage difference limit (option -p or --percent).

The most popular use case of such similarity comparisons are PDF files generated from the same HTML files using Headless Chrome.

The best fit for biff are test cases with output values being files.

Installation

$ cargo install biff

Usage

Display short description of biff options:

$ biff -h

Display detailed description of biff options:

$ biff --help

Examples

Files are equal

$ cat sample1.txt
Lorem ipsum.
$ cat sample2.txt
Lorem ipsum.

$ biff sample1.txt sample2.txt
$ echo $?
0

Files are equal but starting from the 3rd byte

$ cat sample1.txt
LOrem ipsum.
$ cat sample2.txt
MArem ipsum.

$ biff -i 2 sample1.txt sample2.txt
$ echo $?
0

Files are similar (difference limits)

$ cat sample1.txt
LoreM ipsum.
$ cat sample2.txt
LoRem ipsuM.

$ biff -a 3 sample1.txt sample2.txt
$ echo $?
0

$ biff -p 26.8 sample1.txt sample2.txt
$ echo $?
0

$ biff -q -p 26.8 sample1.txt sample2.txt
$ echo $?
0

Files differ

$ cat sample1.txt
LoreM ipsum.
$ cat sample2.txt
LoRem ipsuM.

$ biff sample1.txt sample2.txt
sample1.txt sample2.txt differ: byte 3, line 1
$ echo $?
1

$ biff -b sample1.txt sample2.txt
sample1.txt sample2.txt differ: byte 3, line 1 is 114 82
$ echo $?
1

$ biff -bx sample1.txt sample2.txt
sample1.txt sample2.txt differ: byte 3, line 1 is 72 52
$ echo $?
1

$ biff -q sample1.txt sample2.txt
$ echo $?
1

$ biff -l sample1.txt sample2.txt
3    114  82
5    77  109
11   109  77
$ echo $?
1

$ biff -p 0.1 sample1.txt sample2.txt
sample1.txt sample2.txt differ: limit 0.1% exceeded by value 25.000%
$ echo $?
1

$ biff -a 1 sample1.txt sample2.txt
sample1.txt sample2.txt differ: limit 1 exceeded by value 3
$ echo $?
1

License

Licensed under either of

at your option.

Contribution

Any contributions to biff are greatly appreciated. All contributions intentionally submitted for inclusion in the work by you, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~1MB
~16K SLoC