File tree Expand file tree Collapse file tree 3 files changed +30
-20
lines changed
google/cloud/storage/_experimental/asyncio Expand file tree Collapse file tree 3 files changed +30
-20
lines changed Original file line number Diff line number Diff line change 1+ import google_crc32c
2+
3+ from google .cloud .storage import exceptions
4+
5+ def raise_if_no_fast_crc32c ():
6+ """Check if the C-accelerated version of google-crc32c is available.
7+
8+ If not, raise an error to prevent silent performance degradation.
9+
10+ raises google.api_core.exceptions.NotFound: If the C extension is not available.
11+ returns: True if the C extension is available.
12+ rtype: bool
13+
14+ """
15+ if google_crc32c .implementation != "c" :
16+ raise exceptions .NotFound (
17+ "The google-crc32c package is not installed with C support. "
18+ "Bidi reads require the C extension for data integrity checks."
19+ "For more information, see https://github.com/googleapis/python-crc32c."
20+ )
Original file line number Diff line number Diff line change 2121if you want to use these Rapid Storage APIs.
2222
2323"""
24+ import time
2425from typing import Optional , Union
26+
2527from google .api_core import exceptions
26- from google_crc32c import Checksum , implementation as crc32c_impl
28+ from google_crc32c import Checksum
29+
30+ from ._utils import raise_if_no_fast_crc32c
2731from google .cloud import _storage_v2
2832from google .cloud .storage ._experimental .asyncio .async_grpc_client import (
2933 AsyncGrpcClient ,
@@ -102,14 +106,7 @@ def __init__(
102106 :param write_handle: (Optional) An existing handle for writing the object.
103107 If provided, opening the bidi-gRPC connection will be faster.
104108 """
105- # Verify that the fast, C-accelerated version of crc32c is available.
106- # If not, raise an error to prevent silent performance degradation.
107- if crc32c_impl != "c" :
108- raise exceptions .NotFound (
109- "The google-crc32c package is not installed with C support. "
110- "Bidi reads require the C extension for data integrity checks."
111- "For more information, see https://github.com/googleapis/python-crc32c."
112- )
109+ raise_if_no_fast_crc32c ()
113110 self .client = client
114111 self .bucket_name = bucket_name
115112 self .object_name = object_name
Original file line number Diff line number Diff line change 1414
1515from __future__ import annotations
1616import asyncio
17- import google_crc32c
17+ from typing import List , Optional , Tuple
18+
1819from google .api_core import exceptions
1920from google_crc32c import Checksum
2021
21- from typing import List , Optional , Tuple
22-
22+ from ._utils import raise_if_no_fast_crc32c
2323from google .cloud .storage ._experimental .asyncio .async_read_object_stream import (
2424 _AsyncReadObjectStream ,
2525)
@@ -160,14 +160,7 @@ def __init__(
160160 :param read_handle: (Optional) An existing read handle.
161161 """
162162
163- # Verify that the fast, C-accelerated version of crc32c is available.
164- # If not, raise an error to prevent silent performance degradation.
165- if google_crc32c .implementation != "c" :
166- raise exceptions .NotFound (
167- "The google-crc32c package is not installed with C support. "
168- "Bidi reads require the C extension for data integrity checks."
169- "For more information, see https://github.com/googleapis/python-crc32c."
170- )
163+ raise_if_no_fast_crc32c ()
171164
172165 self .client = client
173166 self .bucket_name = bucket_name
You can’t perform that action at this time.
0 commit comments