
                         j    S r SSKJr  SSKJr  SSKJr  SSKrSSKJr   " S S\R                  5      r	g)	z.Utilities for representing a part of a stream.    )absolute_import)division)unicode_literalsN)upload_streamc                   v   ^  \ rS rSrSr  SU 4S jjrU 4S jrS	U 4S jjr\R                  4U 4S jjr
SrU =r$ )
ComponentStream   aD  Implements a subset of the io.IOBase API exposing part of a stream.

This class behaves as a contiguous subset of the underlying stream.

This is helpful for composite uploads since even when total_size is specified,
apitools.transfer.Upload looks at the size of the source file to ensure
that all bytes have been uploaded.
c                    > [         TU ]  UUUUS9  X l        U R                  U R                  -   U l        U R
                  R                  U R                  5        g)a  Initializes a ComponentStream instance.

Args:
  stream (io.IOBase): See super class.
  offset (int|None): The position (in bytes) in the wrapped stream that
    corresponds to the first byte of the ComponentStream.
  length (int|None): The total number of bytes readable from the
    ComponentStream.
  digesters (dict[util.HashAlgorithm, hashlib hash object]|None): See super
    class.
  progress_callback (func[int]|None): See super class.
)streamlength	digestersprogress_callbackN)super__init___start_byte_length	_end_byte_streamseek)selfr   offsetr   r   r   	__class__s         :lib/googlecloudsdk/command_lib/storage/component_stream.pyr   ComponentStream.__init__$   s]    $ 
)T#+	 $ - %%4DN 	LLd&&'    c                 :   > [         TU ]  5       U R                  -
  $ )z?Returns the current position relative to the part's start byte.)r   tellr   )r   r   s    r   r   ComponentStream.tellB   s    D&(4+;+;;;r   c                    > US:  a  U R                   n[        XR                  [        TU ]  5       -
  5      n[        TU ]  [        SU5      5      $ )z?Reads `size` bytes from a stream, or all bytes when `size` < 0.r   )r   minr   r   r   readmax)r   sizer   s     r   r!   ComponentStream.readF   sH    ax\\dt^^eIt&A&CCDDD&s1d|44r   c                    > U[         R                  :X  a  XR                  -   nO4U[         R                  :X  a  [        TU ]  5       U-   nOXR                  -   n[        TU ]  U5      U R                  -
  $ )a  Goes to a specific point in the stream.

Args:
  offset (int): The number of bytes to move.
  whence: Specifies the position offset is added to.
    os.SEEK_END: offset is added to the last byte in the FilePart.
    os.SEEK_CUR: offset is added to the current position.
    os.SEEK_SET: offset is added to the first byte in the FilePart.

Returns:
  The new relative position in the stream (int).
)osSEEK_ENDr   SEEK_CURr   r   r   r   )r   r   whencenew_absolute_indexr   s       r   r   ComponentStream.seekM   sl     !NN2	2;;	 D686A!$4$44D&'9:T=M=MMMr   )r   r   )NN))__name__
__module____qualname____firstlineno____doc__r   r   r!   r&   SEEK_SETr   __static_attributes____classcell__)r   s   @r   r   r      s4     !%(<<5 !# N Nr   r   )
r1   
__future__r   r   r   r&   "googlecloudsdk.command_lib.storager   UploadStreamr    r   r   <module>r9      s/    5 &  ' 	 <GNm00 GNr   