CRC32 on files

Nikolai Kirsebom nikolai.kirsebom at siemens.no
Fri Jan 4 15:24:43 CET 2002


Script I'm using to generate CRC on set of files:

#
# Generate CRC32 on file
#

import zlib
import array
import sys
import os

if __name__ == '__main__':
    if len(sys.argv) < 2:
        print "Usage: python GenCrc.py filename filename ..."
    for fn in sys.argv[1:]:
        fileSize = os.stat(fn)[6]
        f = open(fn, "rb")
        v = array.array('B')
        try:
            v.fromfile(f, fileSize)
            i = zlib.crc32(v.tostring())
            print "Crc32 of %s is :%d:" % (fn, i)
        except:
            print "Not able to read / generate CRC for file :%s:" %
(fn)


Nikolai

On Fri, 4 Jan 2002 02:03:18 -0500, "Adonis Vargas"
<deltapigz at telocity.com> wrote:

>how do i run a CRC32 checksum on a file with python? or do i have the
>concept all wrong.
>pardon my ignorance, first time i even touch upon this subject.
>
>thanks in advance.
>
>Adonis
>
>




More information about the Python-list mailing list