Calculate CRC32 checksums (like SFVs)

Reply

Join Date: Jul 2009
Posts: 6
Reputation: dezza is an unknown quantity at this point 
Solved Threads: 0
dezza dezza is offline Offline
Newbie Poster

Calculate CRC32 checksums (like SFVs)

 
0
  #1
Jul 4th, 2009
So far i've got this and it returns something like:

-2087276233
  1. import binascii
  2. def getCRC(filename):
  3. filedata = open(filename).read()
  4. return binascii.crc32(filedata)

Someone told me that I had to use struct.pack or struct.unpack to change it to hex values.

I am not sure which type to convert to and would like some explanation to understand fully instead of coding in blind.

The final result should show the same CRC32 value as if you packed the file in WinRAR, checked it with the numerous SFV-checkers or whatever.

A link just in case:
http://docs.python.org/library/struct.html

Thanks alot in advance!
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 830
Reputation: wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all 
Solved Threads: 94
wildgoose's Avatar
wildgoose wildgoose is offline Offline
Practically a Posting Shark

Re: Calculate CRC32 checksums (like SFVs)

 
0
  #2
Jul 5th, 2009
Post your code! Check your variables are properly set signed/unsigned!
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 6
Reputation: dezza is an unknown quantity at this point 
Solved Threads: 0
dezza dezza is offline Offline
Newbie Poster

Re: Calculate CRC32 checksums (like SFVs)

 
0
  #3
Jul 5th, 2009
Originally Posted by wildgoose View Post
Post your code! Check your variables are properly set signed/unsigned!
  1. import binascii
  2. def getCRC(filename):
  3. filedata = open(filename).read()
  4. return binascii.crc32(filedata)
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,009
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 928
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: Calculate CRC32 checksums (like SFVs)

 
0
  #4
Jul 8th, 2009
You may want to try a binary file read.
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 6
Reputation: dezza is an unknown quantity at this point 
Solved Threads: 0
dezza dezza is offline Offline
Newbie Poster

Re: Calculate CRC32 checksums (like SFVs)

 
0
  #5
Jul 8th, 2009
Originally Posted by vegaseat View Post
You may want to try a binary file read.
Can you define this method? I am not sure I understand what you mean.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 6
Reputation: dezza is an unknown quantity at this point 
Solved Threads: 0
dezza dezza is offline Offline
Newbie Poster

Re: Calculate CRC32 checksums (like SFVs)

 
0
  #6
Jul 18th, 2009
http://dev.jmoiron.net/code/html/cksum.py.html

Can I use this code example to write a more simple approach?

I would prefer it in a single function, but the classes and etc. confuses me, I think he should simplify his code, it also gives a deprecation warning ..
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 6
Reputation: dezza is an unknown quantity at this point 
Solved Threads: 0
dezza dezza is offline Offline
Newbie Poster

Re: Calculate CRC32 checksums (like SFVs)

 
0
  #7
Jul 23rd, 2009
I instead used a crc32.c script for use with subprocess .. Faster, and easier ..
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 1,046
Reputation: jlm699 is a jewel in the rough jlm699 is a jewel in the rough jlm699 is a jewel in the rough jlm699 is a jewel in the rough 
Solved Threads: 263
Sponsor
jlm699's Avatar
jlm699 jlm699 is offline Offline
Knows where his Towel is

Re: Calculate CRC32 checksums (like SFVs)

 
0
  #8
Jul 23rd, 2009
Originally Posted by dezza View Post
Can you define this method? I am not sure I understand what you mean.
Binary read is simply opening the file under the mode 'read' plus 'binary'. Read up on the built-in open method here, and the answer will reveal itself.
1. Use Code Tags.
2. Homework? Show Effort.
3. Keep discussions on the forum: no PMs
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 6
Reputation: dezza is an unknown quantity at this point 
Solved Threads: 0
dezza dezza is offline Offline
Newbie Poster

Re: Calculate CRC32 checksums (like SFVs)

 
0
  #9
Jul 24th, 2009
I have tried both open(filename, 'r') and open(filename, 'rb')

I can get the file loaded into a string and then try
print binascii.crc32(file-in-string)

Still just gives me negative integers, what I want is the 8-char hexvalue.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 1,046
Reputation: jlm699 is a jewel in the rough jlm699 is a jewel in the rough jlm699 is a jewel in the rough jlm699 is a jewel in the rough 
Solved Threads: 263
Sponsor
jlm699's Avatar
jlm699 jlm699 is offline Offline
Knows where his Towel is

Re: Calculate CRC32 checksums (like SFVs)

 
0
  #10
Jul 25th, 2009
Originally Posted by dezza View Post
I have tried both open(filename, 'r') and open(filename, 'rb')

I can get the file loaded into a string and then try
print binascii.crc32(file-in-string)

Still just gives me negative integers, what I want is the 8-char hexvalue.
Use 'rb', and RTFM

Use string formatting to print the hex value, just as the example in the docs shows you.
1. Use Code Tags.
2. Homework? Show Effort.
3. Keep discussions on the forum: no PMs
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC