简体   繁体   中英

CRC32 of binary data in python without last 4 bytes

I am trying to get the CRC32 of some binary data, except for the last 4 bytes.

My code so far:

with open('filename.ext','rb') as f:
    fileContent = f.read()
    file_size, = struct.unpack("i",f.read(:4))
    print hex(file_size)

I know that the :4 is wrong and I am still looking for how not to read the last 4 bytes and then get the crc32 for the other data.

You can use indexing like this:

fileContent[:-4]

to skip the last 4 bytes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM