Pretrain-Dataset / scripts /simple_compare.py
jjw0126's picture
Batch upload - simple_compare.py
3f9d5d2 verified
raw
history blame
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()