
    }i                     ,    d Z ddlZddlZ G d d      Zy)zThis module implements a `Buffer` class for handling in-memory data storage, downloading streams, 
and redirecting content to standard output (stdout).    Nc                   *    e Zd Zd Zd Zd Zd Zd Zy)Bufferc                 6    t        j                         | _        y)zA
        Initializes the in-memory buffer to store data.
        NioBytesIObufferselfs    ;/usr/local/lib/python3.12/dist-packages/pytubefix/buffer.py__init__zBuffer.__init__	        jjl    c                    t        |d      r1t        |j                        r|j                  | j                         yt	        |t
              r+| j                  j                  |j                  d             yt        d      )z
        Downloads data directly into the buffer. Accepts objects with the `stream_to_buffer`
        method or strings.

        Args:
            source: Object or data to be written to the buffer.
        stream_to_bufferzutf-8zFThe provided object is not compatible for downloading into the buffer.N)	hasattrcallabler   r	   
isinstancestrwriteencode	TypeError)r   sources     r   download_in_bufferzBuffer.download_in_buffer   s_     6-.8F<S<S3T##DKK0$KKfmmG45deer   c                     | j                   j                  d       t        j                  j                   j	                  | j                   j                                y)z;
        Redirects the buffer's content to stdout.
        r   N)r	   seeksysstdoutr   readr
   s    r   redirect_to_stdoutzBuffer.redirect_to_stdout   s;     	

 0 0 23r   c                 l    | j                   j                  d       | j                   j                         S )z-
        Reads the buffer's content.
        r   )r	   r   r   r
   s    r   r   zBuffer.read%   s)     	{{!!r   c                 6    t        j                         | _        y)z.
        Clears the buffer for reuse.
        Nr   r
   s    r   clearzBuffer.clear,   r   r   N)__name__
__module____qualname__r   r   r    r   r#    r   r   r   r      s    #f4"#r   r   )__doc__r   r   r   r'   r   r   <module>r)      s   8  	(# (#r   