From df04e0fb8a32dfe14a08569f3c13133ed75ae102 Mon Sep 17 00:00:00 2001 From: HemangChothani Date: Tue, 25 Feb 2020 17:51:14 +0530 Subject: [PATCH 1/2] docs(storage): add examples to retrieve hash of blob --- google/cloud/storage/blob.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/google/cloud/storage/blob.py b/google/cloud/storage/blob.py index 0d412447b..911fef58d 100644 --- a/google/cloud/storage/blob.py +++ b/google/cloud/storage/blob.py @@ -1881,6 +1881,22 @@ def update_storage_class(self, new_class, client=None): :rtype: str or ``NoneType`` .. _RFC 4960: https://tools.ietf.org/html/rfc4960#appendix-B + + Example: + Retrieve the crc32c hash of blob. + + >>> from google.cloud import storage + >>> client = storage.Client() + >>> bucket = client.get_bucket("my-bucket-name") + >>> blob = bucket.blob('my-blob') + + >>> blob.crc32c #return None + >>> blob.reload() + >>> blob.crc32c # return crc32c hash + + >>> # Another approach + >>> blob = bucket.get_blob('my-blob') + >>> blob.crc32c # return crc32c hash """ @property @@ -1961,6 +1977,22 @@ def id(self): :rtype: str or ``NoneType`` .. _RFC 1321: https://tools.ietf.org/html/rfc1321 + + Example: + Retrieve the md5 hash of blob. + + >>> from google.cloud import storage + >>> client = storage.Client() + >>> bucket = client.get_bucket("my-bucket-name") + >>> blob = bucket.blob('my-blob') + + >>> blob.md5_hash #return None + >>> blob.reload() + >>> blob.md5_hash # return md5 hash + + >>> # Another approach + >>> blob = bucket.get_blob('my-blob') + >>> blob.md5_hash # return md5 hash """ @property From 53a0912bef64cbf9ae7d5b70a5a4b44971c47a38 Mon Sep 17 00:00:00 2001 From: HemangChothani Date: Fri, 28 Feb 2020 11:39:49 +0530 Subject: [PATCH 2/2] docs(storage): add description --- google/cloud/storage/blob.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/google/cloud/storage/blob.py b/google/cloud/storage/blob.py index 911fef58d..d29e1e1a8 100644 --- a/google/cloud/storage/blob.py +++ b/google/cloud/storage/blob.py @@ -1874,6 +1874,9 @@ def update_storage_class(self, new_class, client=None): crc32c = _scalar_property("crc32c") """CRC32C checksum for this object. + This returns the blob's CRC32C checksum. To retrieve the value, first use a + reload method of the Blob class which loads the blob's properties from the server. + See `RFC 4960`_ and `API reference docs`_. If not set before upload, the server will compute the hash. @@ -1890,7 +1893,7 @@ def update_storage_class(self, new_class, client=None): >>> bucket = client.get_bucket("my-bucket-name") >>> blob = bucket.blob('my-blob') - >>> blob.crc32c #return None + >>> blob.crc32c # return None >>> blob.reload() >>> blob.crc32c # return crc32c hash @@ -1970,6 +1973,9 @@ def id(self): md5_hash = _scalar_property("md5Hash") """MD5 hash for this object. + This returns the blob's MD5 hash. To retrieve the value, first use a + reload method of the Blob class which loads the blob's properties from the server. + See `RFC 1321`_ and `API reference docs`_. If not set before upload, the server will compute the hash. @@ -1986,7 +1992,7 @@ def id(self): >>> bucket = client.get_bucket("my-bucket-name") >>> blob = bucket.blob('my-blob') - >>> blob.md5_hash #return None + >>> blob.md5_hash # return None >>> blob.reload() >>> blob.md5_hash # return md5 hash