--- asyncio-stream.rst 2016-01-13 04:42:56.222183442 +0500 +++ asyncio-stream.rst.new 2016-01-13 04:46:02.429144245 +0500 @@ -113,35 +113,87 @@ .. coroutinemethod:: read(n=-1) - Read up to *n* bytes. If *n* is not provided, or set to ``-1``, - read until EOF and return all read bytes. + Read up to *n* bytes from the stream. - If the EOF was received and the internal buffer is empty, - return an empty ``bytes`` object. + If *n* is not provided, or set to -1, read until EOF and return all read + bytes. If the EOF was received and the internal buffer is empty, return + an empty ``bytes`` object. + + If *n* is zero, return empty ``bytes`` object immediatelly. + + If *n* is positive, this function try to read *n* bytes, and may return + less or equal bytes than requested, but at least one byte. If EOF was + received before any byte is read, this function returns empty byte + object. + + Returned value is not limited with limit, configured at stream creation. + + If stream was paused, this function will automatically resume it if + needed. This method is a :ref:`coroutine `. .. coroutinemethod:: readline() - Read one line, where "line" is a sequence of bytes ending with ``\n``. + Read chunk of data from the stream until newline (``b'\n'``) is found. - If EOF is received, and ``\n`` was not found, the method will - return the partial read bytes. + On success, return chunk that ends with newline. If only partial + line can be read due to EOF, return incomplete line without + terminating newline. When EOF was reached while no bytes read, empty + ``bytes`` object is returned. + + If limit is reached, ValueError will be raised. In that case, if + newline was found, complete line including newline will be removed + from internal buffer. Else, internal buffer will be cleared. Limit is + compared against part of the line without newline. - If the EOF was received and the internal buffer is empty, - return an empty ``bytes`` object. + If stream was paused, this function will automatically resume it if + needed. This method is a :ref:`coroutine `. .. coroutinemethod:: readexactly(n) - Read exactly *n* bytes. Raise an :exc:`IncompleteReadError` if the end of - the stream is reached before *n* can be read, the - :attr:`IncompleteReadError.partial` attribute of the exception contains - the partial read bytes. + Read exactly *n* bytes. + + Raise an :exc:`IncompleteReadError` if EOF is reached before *n* bytes can be + read. The :attr:`IncompleteReadError.partial` attribute of the exception will + contain the partial read bytes. + + If *n* is zero, return empty bytes object. + + Returned value is not limited with limit, configured at stream creation. + + If stream was paused, this function will automatically resume it if + needed. + + This method is a :ref:`coroutine `. + + .. coroutinemethod:: readuntil(separator=b'\n') + + Read chunk of data from the stream until *separator* is found. + + On success, chunk and its separator will be removed from internal buffer + (i.e. consumed). Returned chunk will include separator at the end. + + Configured stream limit is used to check result. Limit means maximal + length of chunk that can be returned, not counting the separator. + + If EOF occurs and complete separator still not found, + :exc:`IncompleteReadError`(, None) will be raised and internal + buffer becomes empty. This partial data may contain a partial separator. + + If chunk cannot be read due to overlimit, :exc:`LimitOverrunError` will be raised + and data will be left in internal buffer, so it can be read again, in + some different way. + + If stream was paused, this function will automatically resume it if + needed. This method is a :ref:`coroutine `. + Available since Asyncio 3.4.4 / Python 3.4.X and 3.5.X ???????????????????????????????????????? + .. method:: at_eof() Return ``True`` if the buffer is empty and :meth:`feed_eof` was called.