U
    <ºcy  ã                   @   sR   d dl mZ d dlmZ d dlmZ dgZedƒG dd„ deeeef  ƒƒZ	dS )é    )ÚTuple)Úfunctional_datapipe)ÚIterDataPipeÚStreamReaderIterDataPipeZread_from_streamc                   @   s"   e Zd ZdZddd„Zdd„ ZdS )r   aÒ  
    Given IO streams and their label names, yields bytes with label
    name in a tuple (functional name: ``read_from_stream``).

    Args:
        datapipe: Iterable DataPipe provides label/URL and byte stream
        chunk: Number of bytes to be read from stream per iteration.
            If ``None``, all bytes will be read util the EOF.

    Example:
        >>> # xdoctest: +SKIP
        >>> from torchdata.datapipes.iter import IterableWrapper, StreamReader
        >>> from io import StringIO
        >>> dp = IterableWrapper([("alphabet", StringIO("abcde"))])
        >>> list(StreamReader(dp, chunk=1))
        [('alphabet', 'a'), ('alphabet', 'b'), ('alphabet', 'c'), ('alphabet', 'd'), ('alphabet', 'e')]
    Nc                 C   s   || _ || _d S ©N)ÚdatapipeÚchunk)Úselfr   r   © r
   úP/tmp/pip-unpacked-wheel-gikjz4vx/torch/utils/data/datapipes/iter/streamreader.pyÚ__init__   s    z!StreamReaderIterDataPipe.__init__c                 c   s:   | j D ].\}}| | j¡}|s(| ¡  q||fV  qqd S r   )r   Úreadr   Úclose)r	   ZfurlÚstreamÚdr
   r
   r   Ú__iter__   s    z!StreamReaderIterDataPipe.__iter__)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r
   r
   r
   r   r      s   
N)
Útypingr   Z%torch.utils.data.datapipes._decoratorr   Z#torch.utils.data.datapipes.datapiper   Ú__all__ÚstrÚbytesr   r
   r
   r
   r   Ú<module>   s
   