File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ 123;
2+ 456;
3+ 789;
Original file line number Diff line number Diff line change 1+ 143;
2+ 456;
3+ 799;
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python3
2+ # -*- coding: utf-8 -*-
3+
4+ __author__ = 'ipetrash'
5+
6+
7+ import zlib
8+
9+
10+ def crc32_from_bytes (data : bytes ) -> int :
11+ return zlib .crc32 (data ) & 0xFFFFFFFF
12+
13+
14+ def crc32_hex_from_bytes (data : bytes ) -> str :
15+ return "%08X" % crc32_from_bytes (data )
16+
17+
18+ def crc32_hex_from_file (filename ):
19+ with open (filename , 'rb' ) as f :
20+ buf = f .read ()
21+
22+ return crc32_hex_from_bytes (buf )
23+
24+
25+ if __name__ == '__main__' :
26+ print (crc32_from_bytes (b'hello-world' )) # 2983461467
27+ print (crc32_hex_from_bytes (b'hello-world' )) # B1D4025B
28+ print ()
29+ print (crc32_hex_from_file ('1.csv' )) # 7EB0F2B2
30+ print (crc32_hex_from_file ('2.csv' )) # 5D884C77
You can’t perform that action at this time.
0 commit comments