# DO NOT EDIT THIS FILE!
#
# This code is generated off of PyCDP modules. If you need to make
# changes, edit the generator and regenerate all of the modules.

from __future__ import annotations
import typing

from ..context import get_connection_context, get_session_context

import cdp.io
from cdp.io import (
    StreamHandle
)


async def close(
        handle: StreamHandle
    ) -> None:
    '''
    Close the stream, discard any temporary backing storage.

    :param handle: Handle of the stream to close.
    '''
    session = get_session_context('io.close')
    return await session.execute(cdp.io.close(handle))


async def read(
        handle: StreamHandle,
        offset: typing.Optional[int] = None,
        size: typing.Optional[int] = None
    ) -> typing.Tuple[typing.Optional[bool], str, bool]:
    '''
    Read a chunk of the stream

    :param handle: Handle of the stream to read.
    :param offset: *(Optional)* Seek to the specified offset before reading (if not specificed, proceed with offset following the last read). Some types of streams may only support sequential reads.
    :param size: *(Optional)* Maximum number of bytes to read (left upon the agent discretion if not specified).
    :returns: A tuple with the following items:

        0. **base64Encoded** – *(Optional)* Set if the data is base64-encoded
        1. **data** – Data that were read.
        2. **eof** – Set if the end-of-file condition occured while reading.
    '''
    session = get_session_context('io.read')
    return await session.execute(cdp.io.read(handle, offset, size))


async def resolve_blob(
        object_id: cdp.runtime.RemoteObjectId
    ) -> str:
    '''
    Return UUID of Blob object specified by a remote object id.

    :param object_id: Object id of a Blob object wrapper.
    :returns: UUID of the specified Blob.
    '''
    session = get_session_context('io.resolve_blob')
    return await session.execute(cdp.io.resolve_blob(object_id))
