Download scripts/simple_compare.py from PLM-Team/Pretrain-Dataset: direct link, hf CLI and curl.
- Browser
- Download file 2.02 kB
-
https://huggingface.co/datasets/PLM-Team/Pretrain-Dataset/resolve/main/scripts/simple_compare.py
- Command line
-
hf download hf://datasets/PLM-Team/Pretrain-Dataset/scripts/simple_compare.py
-
curl -L -o simple_compare.py https://huggingface.co/datasets/PLM-Team/Pretrain-Dataset/resolve/main/scripts/simple_compare.py
2.02 kB
| #!/usr/bin/env python3 | |
| """ | |
| Simple script to compare two .bin files for exact equality. | |
| Usage: python simple_compare.py file1.bin file2.bin | |
| """ | |
| import sys | |
| import os | |
| import hashlib | |
| def compare_bin_files(file1, file2): | |
| """Compare two .bin files for exact equality""" | |
| # Check if files exist | |
| if not os.path.exists(file1): | |
| print(f"β File 1 does not exist: {file1}") | |
| return False | |
| if not os.path.exists(file2): | |
| print(f"β File 2 does not exist: {file2}") | |
| return False | |
| # Get file sizes | |
| size1 = os.path.getsize(file1) | |
| size2 = os.path.getsize(file2) | |
| print(f"File 1: {file1} ({size1:,} bytes)") | |
| print(f"File 2: {file2} ({size2:,} bytes)") | |
| # Quick size check | |
| if size1 != size2: | |
| print(f"β Files have different sizes: {size1:,} vs {size2:,}") | |
| return False | |
| # Calculate hashes | |
| print("Calculating hashes...") | |
| hash1 = hashlib.sha256() | |
| hash2 = hashlib.sha256() | |
| with open(file1, 'rb') as f1, open(file2, 'rb') as f2: | |
| while True: | |
| chunk1 = f1.read(8192) # 8KB chunks | |
| chunk2 = f2.read(8192) | |
| if not chunk1 and not chunk2: | |
| break # Both files ended | |
| if chunk1: | |
| hash1.update(chunk1) | |
| if chunk2: | |
| hash2.update(chunk2) | |
| hash1_hex = hash1.hexdigest() | |
| hash2_hex = hash2.hexdigest() | |
| print(f"File 1 hash: {hash1_hex}") | |
| print(f"File 2 hash: {hash2_hex}") | |
| if hash1_hex == hash2_hex: | |
| print("β Files are identical") | |
| return True | |
| else: | |
| print("β Files are different") | |
| return False | |
| def main(): | |
| if len(sys.argv) != 3: | |
| print("Usage: python simple_compare.py file1.bin file2.bin") | |
| sys.exit(1) | |
| file1 = sys.argv[1] | |
| file2 = sys.argv[2] | |
| result = compare_bin_files(file1, file2) | |
| sys.exit(0 if result else 1) | |
| if __name__ == "__main__": | |
| main() |