Skip to content

Commit ef0c62e

Browse files
HemangChothanicojenco
authored andcommitted
docs(storage): add description and example to retrieve the hash of blob (googleapis#75)
Fixes googleapis#54
1 parent 0f4adf3 commit ef0c62e

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

google/cloud/storage/blob.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1874,13 +1874,32 @@ def update_storage_class(self, new_class, client=None):
18741874
crc32c = _scalar_property("crc32c")
18751875
"""CRC32C checksum for this object.
18761876
1877+
This returns the blob's CRC32C checksum. To retrieve the value, first use a
1878+
reload method of the Blob class which loads the blob's properties from the server.
1879+
18771880
See `RFC 4960`_ and `API reference docs`_.
18781881
18791882
If not set before upload, the server will compute the hash.
18801883
18811884
:rtype: str or ``NoneType``
18821885
18831886
.. _RFC 4960: https://tools.ietf.org/html/rfc4960#appendix-B
1887+
1888+
Example:
1889+
Retrieve the crc32c hash of blob.
1890+
1891+
>>> from google.cloud import storage
1892+
>>> client = storage.Client()
1893+
>>> bucket = client.get_bucket("my-bucket-name")
1894+
>>> blob = bucket.blob('my-blob')
1895+
1896+
>>> blob.crc32c # return None
1897+
>>> blob.reload()
1898+
>>> blob.crc32c # return crc32c hash
1899+
1900+
>>> # Another approach
1901+
>>> blob = bucket.get_blob('my-blob')
1902+
>>> blob.crc32c # return crc32c hash
18841903
"""
18851904

18861905
@property
@@ -1954,13 +1973,32 @@ def id(self):
19541973
md5_hash = _scalar_property("md5Hash")
19551974
"""MD5 hash for this object.
19561975
1976+
This returns the blob's MD5 hash. To retrieve the value, first use a
1977+
reload method of the Blob class which loads the blob's properties from the server.
1978+
19571979
See `RFC 1321`_ and `API reference docs`_.
19581980
19591981
If not set before upload, the server will compute the hash.
19601982
19611983
:rtype: str or ``NoneType``
19621984
19631985
.. _RFC 1321: https://tools.ietf.org/html/rfc1321
1986+
1987+
Example:
1988+
Retrieve the md5 hash of blob.
1989+
1990+
>>> from google.cloud import storage
1991+
>>> client = storage.Client()
1992+
>>> bucket = client.get_bucket("my-bucket-name")
1993+
>>> blob = bucket.blob('my-blob')
1994+
1995+
>>> blob.md5_hash # return None
1996+
>>> blob.reload()
1997+
>>> blob.md5_hash # return md5 hash
1998+
1999+
>>> # Another approach
2000+
>>> blob = bucket.get_blob('my-blob')
2001+
>>> blob.md5_hash # return md5 hash
19642002
"""
19652003

19662004
@property

0 commit comments

Comments
 (0)