def download(
            self,
            file: Union[IO[bytes], asyncio.StreamWriter, None]=None,
            raw: bool=False, rewind: bool=True,
            duration_timeout: Optional[float]=None):
        '''Read the response content into file.

        Args:
            file: A file object or asyncio stream.
            raw: Whether chunked transfer encoding should be included.
            rewind: Seek the given file back to its original offset after
                reading is finished.
            duration_timeout: Maximum time in seconds of which the
                entire file must be read.

        Be sure to call :meth:`start` first.

        Coroutine.
        '''
        if self._session_state != SessionState.request_sent:
            raise RuntimeError('Request not sent')

        if rewind and file and hasattr(file, 'seek'):
            original_offset = file.tell()
        else:
            original_offset = None

        if not hasattr(file, 'drain'):
            self._response.body = file

            if not isinstance(file, Body):
                self._response.body = Body(file)

        read_future = self._stream.read_body(self._request, self._response, file=file, raw=raw)

        try:
            yield from asyncio.wait_for(read_future, timeout=duration_timeout)
        except asyncio.TimeoutError as error:
            raise DurationTimeout(
                'Did not finish reading after {} seconds.'
                    .format(duration_timeout)
            ) from error

        self._session_state = SessionState.response_received

        if original_offset is not None:
            file.seek(original_offset)

        self.event_dispatcher.notify(self.Event.end_response, self._response)
        self.recycle()
def download ( self , file : Union [ IO [ bytes ] , asyncio . StreamWriter , None ] = None , raw : bool = False , rewind : bool = True , duration_timeout : Optional [ float ] = None ) : if self . _session_state != SessionState . request_sent : raise RuntimeError ( 'Request not sent' ) if rewind and file and hasattr ( file , 'seek' ) : original_offset = file . tell ( ) else : original_offset = None if not hasattr ( file , 'drain' ) : self . _response . body = file if not isinstance ( file , Body ) : self . _response . body = Body ( file ) read_future = self . _stream . read_body ( self . _request , self . _response , file = file , raw = raw ) try : yield from asyncio . wait_for ( read_future , timeout = duration_timeout ) except asyncio . TimeoutError as error : raise DurationTimeout ( 'Did not finish reading after {} seconds.' . format ( duration_timeout ) ) from error self . _session_state = SessionState . response_received if original_offset is not None : file . seek ( original_offset ) self . event_dispatcher . notify ( self . Event . end_response , self . _response ) self . recycle ( )
Read the response content into file.

        Args:
            file: A file object or asyncio stream.
            raw: Whether chunked transfer encoding should be included.
            rewind: Seek the given file back to its original offset after
                reading is finished.
            duration_timeout: Maximum time in seconds of which the
                entire file must be read.

        Be sure to call :meth:`start` first.

        Coroutine.