I am attemptting to get a CRC32c
checksum on my local file so I can compare it to the blob.crc32c provided by the gcloud library. Google says I should be using the crcmod module in order to actually calculate CRC32c
hashes of my data.
modifiedFile.txt
has already been downloaded from a Google Cloud Storage bucket onto my local filesystem.
The goal here is to set should_download
to true only if modifiedFile.txt
has a different CRC32c
on my local client vs my remote server. How do I get them to generate matching CRC32c
in the event that my local filesystem and my gcloud Blob both have the same content?
from crcmod import PredefinedCrc
from gcloud import storage
# blob is a gcloud Blob object
should_download = True
with open('modifiedFile.txt') as f:
hasher = PredefinedCrc('crc-32c')
hasher.update(f.read())
crc32c = hasher.digest()
print crc32c # \207\245.\240
print blob.crc32c # CJKo0A==
should_download = crc32c != blob.crc32c
Unfortunately, it currently always fails as I don't actually know how to compare the checksum I build with crcmod
to the attribute I am seeing in the matching Blob
object.