Skip to content

Commit

Permalink
docs(storage): add description and example to retrieve the hash of bl…
Browse files Browse the repository at this point in the history
…ob (#75)

Fixes #54
  • Loading branch information
HemangChothani committed Mar 10, 2020
1 parent 8df0b55 commit 4c1c819
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions google/cloud/storage/blob.py
Expand Up @@ -1874,13 +1874,32 @@ 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.
: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
Expand Down Expand Up @@ -1954,13 +1973,32 @@ 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.
: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
Expand Down

0 comments on commit 4c1c819

Please sign in to comment.