perf(storage): use google_crc32c.value() for simpler crc32c calculati… · googleapis/google-cloud-python@c9846c9 · GitHub
Skip to content

Commit c9846c9

Browse files
authored
perf(storage): use google_crc32c.value() for simpler crc32c calculation (#16761)
## Summary - Simplified CRC32C calculation by using `google_crc32c.value()`. - Improved code readability and reduced complexity in checksum logic.
1 parent 7073be1 commit c9846c9

4 files changed

Lines changed: 8 additions & 15 deletions

File tree

packages/google-cloud-storage/google/cloud/storage/asyncio/retry/writes_resumption_strategy.py

Lines changed: 1 addition & 2 deletions

packages/google-cloud-storage/tests/unit/asyncio/retry/test_reads_resumption_strategy.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import unittest
1818

1919
from google.api_core import exceptions
20-
from google_crc32c import Checksum
20+
import google_crc32c
2121

2222
from google.cloud import _storage_v2 as storage_v2
2323
from google.cloud._storage_v2.types.storage import BidiReadObjectRedirectedError
@@ -77,8 +77,7 @@ def _create_response(
7777
checksummed_data = None
7878
if content is not None:
7979
if crc is None:
80-
c = Checksum(content)
81-
crc = int.from_bytes(c.digest(), "big")
80+
crc = google_crc32c.value(content)
8281
checksummed_data = storage_v2.ChecksummedData(content=content, crc32c=crc)
8382

8483
read_range = None

packages/google-cloud-storage/tests/unit/asyncio/retry/test_writes_resumption_strategy.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,7 @@ def test_generate_requests_checksum_verification(self, strategy):
125125

126126
requests = strategy.generate_requests(state)
127127

128-
expected_crc = google_crc32c.Checksum(chunk_data).digest()
129-
expected_int = int.from_bytes(expected_crc, "big")
128+
expected_int = google_crc32c.value(chunk_data)
130129
assert requests[0].checksummed_data.crc32c == expected_int
131130

132131
def test_generate_requests_flush_logic_exact_interval(self, strategy):

packages/google-cloud-storage/tests/unit/asyncio/test_async_multi_range_downloader.py

Lines changed: 4 additions & 8 deletions

0 commit comments

Comments
 (0)