:right-sidebar: True BufferedInputStream =================================================================== .. currentmodule:: gi.repository.Gio .. class:: BufferedInputStream(**properties: ~typing.Any) :no-contents-entry: Superclasses: :class:`~gi.repository.Gio.FilterInputStream`, :class:`~gi.repository.Gio.InputStream`, :class:`~gi.repository.GObject.Object` Subclasses: :class:`~gi.repository.Gio.DataInputStream` Implemented Interfaces: :class:`~gi.repository.Gio.Seekable` Buffered input stream implements :obj:`~gi.repository.Gio.FilterInputStream` and provides for buffered reads. By default, ``GBufferedInputStream``\'s buffer size is set at 4 kilobytes. To create a buffered input stream, use :obj:`~gi.repository.Gio.BufferedInputStream.new`\, or :obj:`~gi.repository.Gio.BufferedInputStream.new_sized` to specify the buffer's size at construction. To get the size of a buffer within a buffered input stream, use :obj:`~gi.repository.Gio.BufferedInputStream.get_buffer_size`\. To change the size of a buffered input stream's buffer, use :obj:`~gi.repository.Gio.BufferedInputStream.set_buffer_size`\. Note that the buffer's size cannot be reduced below the size of the data within the buffer. Constructors ------------ .. rst-class:: interim-class .. class:: BufferedInputStream :no-index: .. classmethod:: new(base_stream: ~gi.repository.Gio.InputStream) -> ~gi.repository.Gio.InputStream Creates a new :obj:`~gi.repository.Gio.InputStream` from the given ``base_stream``\, with a buffer set to the default size (4 kilobytes). :param base_stream: a :obj:`~gi.repository.Gio.InputStream` .. classmethod:: new_sized(base_stream: ~gi.repository.Gio.InputStream, size: int) -> ~gi.repository.Gio.InputStream Creates a new :obj:`~gi.repository.Gio.BufferedInputStream` from the given ``base_stream``\, with a buffer set to ``size``\. :param base_stream: a :obj:`~gi.repository.Gio.InputStream` :param size: a :obj:`~gi.repository.gsize` Methods ------- .. rst-class:: interim-class .. class:: BufferedInputStream :no-index: .. method:: do_fill(self, count: int, cancellable: ~gi.repository.Gio.Cancellable | None = None) -> int :param count: :param cancellable: .. method:: do_fill_async(self, count: int, io_priority: int, cancellable: ~gi.repository.Gio.Cancellable | None = None, callback: ~typing.Callable[[~gi.repository.GObject.Object | None, ~gi.repository.Gio.AsyncResult, ~typing.Any], None] | None = None, user_data: ~typing.Any = None) -> None :param count: :param io_priority: :param cancellable: :param callback: :param user_data: .. method:: do_fill_finish(self, result: ~gi.repository.Gio.AsyncResult) -> int :param result: .. method:: fill(count: int, cancellable: ~gi.repository.Gio.Cancellable | None = None) -> int Tries to read ``count`` bytes from the stream into the buffer. Will block during this read. If ``count`` is zero, returns zero and does nothing. A value of ``count`` larger than ``G_MAXSSIZE`` will cause a :obj:`~gi.repository.Gio.IOErrorEnum.INVALID_ARGUMENT` error. On success, the number of bytes read into the buffer is returned. It is not an error if this is not the same as the requested size, as it can happen e.g. near the end of a file. Zero is returned on end of file (or if ``count`` is zero), but never otherwise. If ``count`` is -1 then the attempted read size is equal to the number of bytes that are required to fill the buffer. If ``cancellable`` is not ``NULL``\, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error :obj:`~gi.repository.Gio.IOErrorEnum.CANCELLED` will be returned. If an operation was partially finished when the operation was cancelled the partial result will be returned, without an error. On error ``-1`` is returned and ``error`` is set accordingly. For the asynchronous, non-blocking, version of this function, see :obj:`~gi.repository.Gio.BufferedInputStream.fill_async`\. :param count: the number of bytes that will be read from the stream :param cancellable: optional :obj:`~gi.repository.Gio.Cancellable` object, ``NULL`` to ignore .. method:: fill_async(count: int, io_priority: int, cancellable: ~gi.repository.Gio.Cancellable | None = None, callback: ~typing.Callable[[~gi.repository.GObject.Object | None, ~gi.repository.Gio.AsyncResult, ~typing.Any], None] | None = None, user_data: ~typing.Any = None) -> None Reads data into ``stream``\'s buffer asynchronously, up to ``count`` size. ``io_priority`` can be used to prioritize reads. For the synchronous version of this function, see :obj:`~gi.repository.Gio.BufferedInputStream.fill`\. If ``count`` is ``-1`` then the attempted read size is equal to the number of bytes that are required to fill the buffer. :param count: the number of bytes that will be read from the stream :param io_priority: the `I/O priority `__ of the request :param cancellable: optional :obj:`~gi.repository.Gio.Cancellable` object :param callback: a [callback``Gio``\.AsyncReadyCallback] :param user_data: a :obj:`~gi.repository.gpointer` .. method:: fill_finish(result: ~gi.repository.Gio.AsyncResult) -> int Finishes an asynchronous read. :param result: a :obj:`~gi.repository.Gio.AsyncResult` .. method:: get_available() -> int Gets the size of the available data within the stream. .. method:: get_buffer_size() -> int Gets the size of the input buffer. .. method:: peek(buffer: list[int], offset: int) -> int Peeks in the buffer, copying data of size ``count`` into ``buffer``\, offset ``offset`` bytes. :param buffer: a pointer to an allocated chunk of memory :param offset: a :obj:`~gi.repository.gsize` .. method:: peek_buffer() -> list[int] Returns the buffer with the currently available bytes. The returned buffer must not be modified and will become invalid when reading from the stream or filling the buffer. .. method:: read_byte(cancellable: ~gi.repository.Gio.Cancellable | None = None) -> int Tries to read a single byte from the stream or the buffer. Will block during this read. On success, the byte read from the stream is returned. On end of stream ``-1`` is returned but it's not an exceptional error and ``error`` is not set. If ``cancellable`` is not ``NULL``\, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error :obj:`~gi.repository.Gio.IOErrorEnum.CANCELLED` will be returned. If an operation was partially finished when the operation was cancelled the partial result will be returned, without an error. On error ``-1`` is returned and ``error`` is set accordingly. :param cancellable: optional :obj:`~gi.repository.Gio.Cancellable` object, ``NULL`` to ignore .. method:: set_buffer_size(size: int) -> None Sets the size of the internal buffer of ``stream`` to ``size``\, or to the size of the contents of the buffer. The buffer can never be resized smaller than its current contents. :param size: a :obj:`~gi.repository.gsize` Properties ---------- .. rst-class:: interim-class .. class:: BufferedInputStream :no-index: .. attribute:: props.buffer_size :type: int The type of the None singleton. Virtual Methods --------------- .. rst-class:: interim-class .. class:: BufferedInputStream :no-index: .. method:: do_fill(count: int, cancellable: ~gi.repository.Gio.Cancellable | None = None) -> int Tries to read ``count`` bytes from the stream into the buffer. Will block during this read. If ``count`` is zero, returns zero and does nothing. A value of ``count`` larger than ``G_MAXSSIZE`` will cause a :obj:`~gi.repository.Gio.IOErrorEnum.INVALID_ARGUMENT` error. On success, the number of bytes read into the buffer is returned. It is not an error if this is not the same as the requested size, as it can happen e.g. near the end of a file. Zero is returned on end of file (or if ``count`` is zero), but never otherwise. If ``count`` is -1 then the attempted read size is equal to the number of bytes that are required to fill the buffer. If ``cancellable`` is not ``NULL``\, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error :obj:`~gi.repository.Gio.IOErrorEnum.CANCELLED` will be returned. If an operation was partially finished when the operation was cancelled the partial result will be returned, without an error. On error ``-1`` is returned and ``error`` is set accordingly. For the asynchronous, non-blocking, version of this function, see :obj:`~gi.repository.Gio.BufferedInputStream.fill_async`\. :param count: the number of bytes that will be read from the stream :param cancellable: optional :obj:`~gi.repository.Gio.Cancellable` object, ``NULL`` to ignore .. method:: do_fill_async(count: int, io_priority: int, cancellable: ~gi.repository.Gio.Cancellable | None = None, callback: ~typing.Callable[[~gi.repository.GObject.Object | None, ~gi.repository.Gio.AsyncResult, ~typing.Any], None] | None = None, user_data: ~typing.Any = None) -> None Reads data into ``stream``\'s buffer asynchronously, up to ``count`` size. ``io_priority`` can be used to prioritize reads. For the synchronous version of this function, see :obj:`~gi.repository.Gio.BufferedInputStream.fill`\. If ``count`` is ``-1`` then the attempted read size is equal to the number of bytes that are required to fill the buffer. :param count: the number of bytes that will be read from the stream :param io_priority: the `I/O priority `__ of the request :param cancellable: optional :obj:`~gi.repository.Gio.Cancellable` object :param callback: a [callback``Gio``\.AsyncReadyCallback] :param user_data: a :obj:`~gi.repository.gpointer` .. method:: do_fill_finish(result: ~gi.repository.Gio.AsyncResult) -> int Finishes an asynchronous read. :param result: a :obj:`~gi.repository.Gio.AsyncResult` Fields ------ .. rst-class:: interim-class .. class:: BufferedInputStream :no-index: .. attribute:: parent_instance .. attribute:: priv