|
| 1 | +# Copyright 2025 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | +""" |
| 15 | +NOTE: |
| 16 | +This is _experimental module for upcoming support for Rapid Storage. |
| 17 | +(https://cloud.google.com/blog/products/storage-data-transfer/high-performance-storage-innovations-for-ai-hpc#:~:text=your%20AI%20workloads%3A-,Rapid%20Storage,-%3A%20A%20new) |
| 18 | +
|
| 19 | +APIs may not work as intended and are not stable yet. Feature is not |
| 20 | +GA(Generally Available) yet, please contact your TAM(Technical Account Manager) |
| 21 | +if you want to use these APIs. |
| 22 | +
|
| 23 | +""" |
| 24 | + |
| 25 | +from typing import Any, Optional |
| 26 | +from google.cloud import _storage_v2 |
| 27 | +from google.cloud.storage._experimental.asyncio.async_grpc_client import AsyncGrpcClient |
| 28 | +from google.cloud.storage._experimental.asyncio.async_abstract_object_stream import ( |
| 29 | + _AsyncAbstractObjectStream, |
| 30 | +) |
| 31 | + |
| 32 | + |
| 33 | +class _AsyncReadObjectStream(_AsyncAbstractObjectStream): |
| 34 | + """Class representing a gRPC bidi-stream for reading data from a GCS ``Object``. |
| 35 | +
|
| 36 | + This class provides a unix socket-like interface to a GCS ``Object``, with |
| 37 | + methods like ``open``, ``close``, ``send``, and ``recv``. |
| 38 | +
|
| 39 | + :type client: :class:`~google.cloud.storage.asyncio.AsyncGrpcClient.grpc_client` |
| 40 | + :param client: async grpc client to use for making API requests. |
| 41 | +
|
| 42 | + :type bucket_name: str |
| 43 | + :param bucket_name: The name of the GCS ``bucket`` containing the object. |
| 44 | +
|
| 45 | + :type object_name: str |
| 46 | + :param object_name: The name of the GCS ``object`` to be read. |
| 47 | +
|
| 48 | + :type generation_number: int |
| 49 | + :param generation_number: (Optional) If present, selects a specific revision of |
| 50 | + this object. |
| 51 | +
|
| 52 | + :type read_handle: bytes |
| 53 | + :param read_handle: (Optional) An existing handle for reading the object. |
| 54 | + If provided, opening the bidi-gRPC connection will be faster. |
| 55 | + """ |
| 56 | + |
| 57 | + def __init__( |
| 58 | + self, |
| 59 | + client: AsyncGrpcClient.grpc_client, |
| 60 | + bucket_name: str, |
| 61 | + object_name: str, |
| 62 | + generation_number: Optional[int] = None, |
| 63 | + read_handle: Optional[bytes] = None, |
| 64 | + ) -> None: |
| 65 | + if client is None: |
| 66 | + raise ValueError("client must be provided") |
| 67 | + if bucket_name is None: |
| 68 | + raise ValueError("bucket_name must be provided") |
| 69 | + if object_name is None: |
| 70 | + raise ValueError("object_name must be provided") |
| 71 | + |
| 72 | + super().__init__( |
| 73 | + bucket_name=bucket_name, |
| 74 | + object_name=object_name, |
| 75 | + generation_number=generation_number, |
| 76 | + ) |
| 77 | + self.client: AsyncGrpcClient.grpc_client = client |
| 78 | + self.read_handle: Optional[bytes] = read_handle |
| 79 | + |
| 80 | + async def open(self) -> None: |
| 81 | + pass |
| 82 | + |
| 83 | + async def close(self) -> None: |
| 84 | + pass |
| 85 | + |
| 86 | + async def send( |
| 87 | + self, bidi_read_object_request: _storage_v2.BidiReadObjectRequest |
| 88 | + ) -> None: |
| 89 | + pass |
| 90 | + |
| 91 | + async def recv(self) -> Any: |
| 92 | + pass |
0 commit comments