:right-sidebar: True InputStream =================================================================== .. currentmodule:: gi.repository.Gio .. class:: InputStream(**properties: ~typing.Any) :no-contents-entry: Superclasses: :class:`~gi.repository.GObject.Object` Subclasses: :class:`~gi.repository.Gio.FileInputStream`, :class:`~gi.repository.Gio.FilterInputStream`, :class:`~gi.repository.Gio.MemoryInputStream`, :class:`~gi.repository.Gio.UnixInputStream` ``GInputStream`` is a base class for implementing streaming input. It has functions to read from a stream (:obj:`~gi.repository.Gio.InputStream.read`\), to close a stream (:obj:`~gi.repository.Gio.InputStream.close`\) and to skip some content (:obj:`~gi.repository.Gio.InputStream.skip`\). To copy the content of an input stream to an output stream without manually handling the reads and writes, use :obj:`~gi.repository.Gio.OutputStream.splice`\. See the documentation for :obj:`~gi.repository.Gio.IOStream` for details of thread safety of streaming APIs. All of these functions have async variants too. Methods ------- .. rst-class:: interim-class .. class:: InputStream :no-index: .. method:: clear_pending() -> None Clears the pending flag on ``stream``\. .. method:: close(cancellable: ~gi.repository.Gio.Cancellable | None = None) -> bool Closes the stream, releasing resources related to it. Once the stream is closed, all other operations will return :const:`~gi.repository.Gio.IOErrorEnum.CLOSED`. Closing a stream multiple times will not return an error. Streams will be automatically closed when the last reference is dropped, but you might want to call this function to make sure resources are released as early as possible. Some streams might keep the backing store of the stream (e.g. a file descriptor) open after the stream is closed. See the documentation for the individual stream for details. On failure the first error that happened will be reported, but the close operation will finish as much as possible. A stream that failed to close will still return :const:`~gi.repository.Gio.IOErrorEnum.CLOSED` for all operations. Still, it is important to check and report the error to the user. If ``cancellable`` is not :const:`None`, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error :const:`~gi.repository.Gio.IOErrorEnum.CANCELLED` will be returned. Cancelling a close will still leave the stream closed, but some streams can use a faster close that doesn't block to e.g. check errors. :param cancellable: optional :obj:`~gi.repository.Gio.Cancellable` object, :const:`None` to ignore. .. method:: close_async(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 Requests an asynchronous closes of the stream, releasing resources related to it. When the operation is finished ``callback`` will be called. You can then call :func:`~gi.repository.Gio.InputStream.close_finish` to get the result of the operation. For behaviour details see :func:`~gi.repository.Gio.InputStream.close`. The asynchronous methods have a default fallback that uses threads to implement asynchronicity, so they are optional for inheriting classes. However, if you override one you must override all. :param io_priority: the `I/O priority `__ of the request :param cancellable: optional cancellable object :param callback: a :obj:`~gi.repository.Gio.AsyncReadyCallback` to call when the request is satisfied :param user_data: the data to pass to callback function .. method:: close_finish(result: ~gi.repository.Gio.AsyncResult) -> bool Finishes closing a stream asynchronously, started from :func:`~gi.repository.Gio.InputStream.close_async`. :param result: a :obj:`~gi.repository.Gio.AsyncResult`\. .. method:: do_close_async(self, 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 io_priority: :param cancellable: :param callback: :param user_data: .. method:: do_close_finish(self, result: ~gi.repository.Gio.AsyncResult) -> bool :param result: .. method:: do_close_fn(self, cancellable: ~gi.repository.Gio.Cancellable | None = None) -> bool :param cancellable: .. method:: do_read_async(self, 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) -> list[int] | None :param io_priority: :param cancellable: :param callback: :param user_data: .. method:: do_read_finish(self, result: ~gi.repository.Gio.AsyncResult) -> int :param result: .. method:: do_read_fn(self, buffer: ~typing.Any, count: int, cancellable: ~gi.repository.Gio.Cancellable | None = None) -> int :param buffer: :param count: :param cancellable: .. method:: do_skip(self, count: int, cancellable: ~gi.repository.Gio.Cancellable | None = None) -> int :param count: :param cancellable: .. method:: do_skip_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_skip_finish(self, result: ~gi.repository.Gio.AsyncResult) -> int :param result: .. method:: has_pending() -> bool Checks if an input stream has pending actions. .. method:: is_closed() -> bool Checks if an input stream is closed. .. method:: read(cancellable: ~gi.repository.Gio.Cancellable | None = None) -> ~typing.Tuple[int, list[int]] Tries to read ``count`` bytes from the stream into the buffer starting at ``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 :const:`~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. The returned ``buffer`` is not a nul-terminated string, it can contain nul bytes at any position, and this function doesn't nul-terminate the ``buffer``\. If ``cancellable`` is not :const:`None`, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error :const:`~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, :const:`None` to ignore. .. method:: read_all(cancellable: ~gi.repository.Gio.Cancellable | None = None) -> ~typing.Tuple[bool, list[int], int] Tries to read ``count`` bytes from the stream into the buffer starting at ``buffer``\. Will block during this read. This function is similar to :func:`~gi.repository.Gio.InputStream.read`, except it tries to read as many bytes as requested, only stopping on an error or end of stream. On a successful read of ``count`` bytes, or if we reached the end of the stream, :const:`True` is returned, and ``bytes_read`` is set to the number of bytes read into ``buffer``\. If there is an error during the operation :const:`False` is returned and ``error`` is set to indicate the error status. As a special exception to the normal conventions for functions that use :obj:`~gi.repository.GLib.Error`\, if this function returns :const:`False` (and sets ``error``\) then ``bytes_read`` will be set to the number of bytes that were successfully read before the error was encountered. This functionality is only available from C. If you need it from another language then you must write your own loop around :func:`~gi.repository.Gio.InputStream.read`. :param cancellable: optional :obj:`~gi.repository.Gio.Cancellable` object, :const:`None` to ignore. .. method:: read_all_async(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) -> list[int] Request an asynchronous read of ``count`` bytes from the stream into the buffer starting at ``buffer``\. This is the asynchronous equivalent of :func:`~gi.repository.Gio.InputStream.read_all`. Call :func:`~gi.repository.Gio.InputStream.read_all_finish` to collect the result. Any outstanding I/O request with higher priority (lower numerical value) will be executed before an outstanding request with lower priority. Default priority is %G_PRIORITY_DEFAULT. .. versionadded:: 2.44 :param io_priority: the `I/O priority `__ of the request :param cancellable: optional :obj:`~gi.repository.Gio.Cancellable` object, :const:`None` to ignore :param callback: a :obj:`~gi.repository.Gio.AsyncReadyCallback` to call when the request is satisfied :param user_data: the data to pass to callback function .. method:: read_all_finish(result: ~gi.repository.Gio.AsyncResult) -> ~typing.Tuple[bool, int] Finishes an asynchronous stream read operation started with :func:`~gi.repository.Gio.InputStream.read_all_async`. As a special exception to the normal conventions for functions that use :obj:`~gi.repository.GLib.Error`\, if this function returns :const:`False` (and sets ``error``\) then ``bytes_read`` will be set to the number of bytes that were successfully read before the error was encountered. This functionality is only available from C. If you need it from another language then you must write your own loop around :func:`~gi.repository.Gio.InputStream.read_async`. .. versionadded:: 2.44 :param result: a :obj:`~gi.repository.Gio.AsyncResult` .. method:: read_async(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) -> list[int] Request an asynchronous read of ``count`` bytes from the stream into the buffer starting at ``buffer``\. When the operation is finished ``callback`` will be called. You can then call :func:`~gi.repository.Gio.InputStream.read_finish` to get the result of the operation. During an async request no other sync and async calls are allowed on ``stream``\, and will result in :const:`~gi.repository.Gio.IOErrorEnum.PENDING` errors. A value of ``count`` larger than %G_MAXSSIZE will cause a :const:`~gi.repository.Gio.IOErrorEnum.INVALID_ARGUMENT` error. On success, the number of bytes read into the buffer will be passed to the callback. 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, but generally we try to read as many bytes as requested. Zero is returned on end of file (or if ``count`` is zero), but never otherwise. Any outstanding i/o request with higher priority (lower numerical value) will be executed before an outstanding request with lower priority. Default priority is %G_PRIORITY_DEFAULT. The asynchronous methods have a default fallback that uses threads to implement asynchronicity, so they are optional for inheriting classes. However, if you override one you must override all. :param io_priority: the `I/O priority `__ of the request. :param cancellable: optional :obj:`~gi.repository.Gio.Cancellable` object, :const:`None` to ignore. :param callback: a :obj:`~gi.repository.Gio.AsyncReadyCallback` to call when the request is satisfied :param user_data: the data to pass to callback function .. method:: read_bytes(count: int, cancellable: ~gi.repository.Gio.Cancellable | None = None) -> ~gi.repository.GLib.Bytes Like :func:`~gi.repository.Gio.InputStream.read`, this tries to read ``count`` bytes from the stream in a blocking fashion. However, rather than reading into a user-supplied buffer, this will create a new :obj:`~gi.repository.GLib.Bytes` containing the data that was read. This may be easier to use from language bindings. If count is zero, returns a zero-length :obj:`~gi.repository.GLib.Bytes` and does nothing. A value of ``count`` larger than %G_MAXSSIZE will cause a :const:`~gi.repository.Gio.IOErrorEnum.INVALID_ARGUMENT` error. On success, a new :obj:`~gi.repository.GLib.Bytes` is returned. It is not an error if the size of this object is not the same as the requested size, as it can happen e.g. near the end of a file. A zero-length :obj:`~gi.repository.GLib.Bytes` is returned on end of file (or if ``count`` is zero), but never otherwise. If ``cancellable`` is not :const:`None`, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error :const:`~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 :const:`None` is returned and ``error`` is set accordingly. .. versionadded:: 2.34 :param count: maximum number of bytes that will be read from the stream. Common values include 4096 and 8192. :param cancellable: optional :obj:`~gi.repository.Gio.Cancellable` object, :const:`None` to ignore. .. method:: read_bytes_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 Request an asynchronous read of ``count`` bytes from the stream into a new :obj:`~gi.repository.GLib.Bytes`\. When the operation is finished ``callback`` will be called. You can then call :func:`~gi.repository.Gio.InputStream.read_bytes_finish` to get the result of the operation. During an async request no other sync and async calls are allowed on ``stream``\, and will result in :const:`~gi.repository.Gio.IOErrorEnum.PENDING` errors. A value of ``count`` larger than %G_MAXSSIZE will cause a :const:`~gi.repository.Gio.IOErrorEnum.INVALID_ARGUMENT` error. On success, the new :obj:`~gi.repository.GLib.Bytes` will be passed to the callback. It is not an error if this is smaller than the requested size, as it can happen e.g. near the end of a file, but generally we try to read as many bytes as requested. Zero is returned on end of file (or if ``count`` is zero), but never otherwise. Any outstanding I/O request with higher priority (lower numerical value) will be executed before an outstanding request with lower priority. Default priority is %G_PRIORITY_DEFAULT. .. versionadded:: 2.34 :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, :const:`None` to ignore. :param callback: a :obj:`~gi.repository.Gio.AsyncReadyCallback` to call when the request is satisfied :param user_data: the data to pass to callback function .. method:: read_bytes_finish(result: ~gi.repository.Gio.AsyncResult) -> ~gi.repository.GLib.Bytes Finishes an asynchronous stream read-into-:obj:`~gi.repository.GLib.Bytes` operation. .. versionadded:: 2.34 :param result: a :obj:`~gi.repository.Gio.AsyncResult`\. .. method:: read_finish(result: ~gi.repository.Gio.AsyncResult) -> int Finishes an asynchronous stream read operation. :param result: a :obj:`~gi.repository.Gio.AsyncResult`\. .. method:: set_pending() -> bool Sets ``stream`` to have actions pending. If the pending flag is already set or ``stream`` is closed, it will return :const:`False` and set ``error``\. .. method:: skip(count: int, cancellable: ~gi.repository.Gio.Cancellable | None = None) -> int Tries to skip ``count`` bytes from the stream. Will block during the operation. This is identical to :func:`~gi.repository.Gio.InputStream.read`, from a behaviour standpoint, but the bytes that are skipped are not returned to the user. Some streams have an implementation that is more efficient than reading the data. This function is optional for inherited classes, as the default implementation emulates it using read. If ``cancellable`` is not :const:`None`, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error :const:`~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. :param count: the number of bytes that will be skipped from the stream :param cancellable: optional :obj:`~gi.repository.Gio.Cancellable` object, :const:`None` to ignore. .. method:: skip_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 Request an asynchronous skip of ``count`` bytes from the stream. When the operation is finished ``callback`` will be called. You can then call :func:`~gi.repository.Gio.InputStream.skip_finish` to get the result of the operation. During an async request no other sync and async calls are allowed, and will result in :const:`~gi.repository.Gio.IOErrorEnum.PENDING` errors. A value of ``count`` larger than %G_MAXSSIZE will cause a :const:`~gi.repository.Gio.IOErrorEnum.INVALID_ARGUMENT` error. On success, the number of bytes skipped will be passed to the callback. 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, but generally we try to skip as many bytes as requested. Zero is returned on end of file (or if ``count`` is zero), but never otherwise. Any outstanding i/o request with higher priority (lower numerical value) will be executed before an outstanding request with lower priority. Default priority is %G_PRIORITY_DEFAULT. The asynchronous methods have a default fallback that uses threads to implement asynchronicity, so they are optional for inheriting classes. However, if you override one, you must override all. :param count: the number of bytes that will be skipped from the stream :param io_priority: the `I/O priority `__ of the request :param cancellable: optional :obj:`~gi.repository.Gio.Cancellable` object, :const:`None` to ignore. :param callback: a :obj:`~gi.repository.Gio.AsyncReadyCallback` to call when the request is satisfied :param user_data: the data to pass to callback function .. method:: skip_finish(result: ~gi.repository.Gio.AsyncResult) -> int Finishes a stream skip operation. :param result: a :obj:`~gi.repository.Gio.AsyncResult`\. Virtual Methods --------------- .. rst-class:: interim-class .. class:: InputStream :no-index: .. method:: do_close_async(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 Requests an asynchronous closes of the stream, releasing resources related to it. When the operation is finished ``callback`` will be called. You can then call :func:`~gi.repository.Gio.InputStream.close_finish` to get the result of the operation. For behaviour details see :func:`~gi.repository.Gio.InputStream.close`. The asynchronous methods have a default fallback that uses threads to implement asynchronicity, so they are optional for inheriting classes. However, if you override one you must override all. :param io_priority: the `I/O priority `__ of the request :param cancellable: optional cancellable object :param callback: a :obj:`~gi.repository.Gio.AsyncReadyCallback` to call when the request is satisfied :param user_data: the data to pass to callback function .. method:: do_close_finish(result: ~gi.repository.Gio.AsyncResult) -> bool Finishes closing a stream asynchronously, started from :func:`~gi.repository.Gio.InputStream.close_async`. :param result: a :obj:`~gi.repository.Gio.AsyncResult`\. .. method:: do_close_fn(cancellable: ~gi.repository.Gio.Cancellable | None = None) -> bool The type of the None singleton. :param cancellable: .. method:: do_read_async(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) -> list[int] | None Request an asynchronous read of ``count`` bytes from the stream into the buffer starting at ``buffer``\. When the operation is finished ``callback`` will be called. You can then call :func:`~gi.repository.Gio.InputStream.read_finish` to get the result of the operation. During an async request no other sync and async calls are allowed on ``stream``\, and will result in :const:`~gi.repository.Gio.IOErrorEnum.PENDING` errors. A value of ``count`` larger than %G_MAXSSIZE will cause a :const:`~gi.repository.Gio.IOErrorEnum.INVALID_ARGUMENT` error. On success, the number of bytes read into the buffer will be passed to the callback. 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, but generally we try to read as many bytes as requested. Zero is returned on end of file (or if ``count`` is zero), but never otherwise. Any outstanding i/o request with higher priority (lower numerical value) will be executed before an outstanding request with lower priority. Default priority is %G_PRIORITY_DEFAULT. The asynchronous methods have a default fallback that uses threads to implement asynchronicity, so they are optional for inheriting classes. However, if you override one you must override all. :param io_priority: the `I/O priority `__ of the request. :param cancellable: optional :obj:`~gi.repository.Gio.Cancellable` object, :const:`None` to ignore. :param callback: a :obj:`~gi.repository.Gio.AsyncReadyCallback` to call when the request is satisfied :param user_data: the data to pass to callback function .. method:: do_read_finish(result: ~gi.repository.Gio.AsyncResult) -> int Finishes an asynchronous stream read operation. :param result: a :obj:`~gi.repository.Gio.AsyncResult`\. .. method:: do_read_fn(buffer: ~typing.Any, count: int, cancellable: ~gi.repository.Gio.Cancellable | None = None) -> int The type of the None singleton. :param buffer: :param count: :param cancellable: .. method:: do_skip(count: int, cancellable: ~gi.repository.Gio.Cancellable | None = None) -> int Tries to skip ``count`` bytes from the stream. Will block during the operation. This is identical to :func:`~gi.repository.Gio.InputStream.read`, from a behaviour standpoint, but the bytes that are skipped are not returned to the user. Some streams have an implementation that is more efficient than reading the data. This function is optional for inherited classes, as the default implementation emulates it using read. If ``cancellable`` is not :const:`None`, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error :const:`~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. :param count: the number of bytes that will be skipped from the stream :param cancellable: optional :obj:`~gi.repository.Gio.Cancellable` object, :const:`None` to ignore. .. method:: do_skip_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 Request an asynchronous skip of ``count`` bytes from the stream. When the operation is finished ``callback`` will be called. You can then call :func:`~gi.repository.Gio.InputStream.skip_finish` to get the result of the operation. During an async request no other sync and async calls are allowed, and will result in :const:`~gi.repository.Gio.IOErrorEnum.PENDING` errors. A value of ``count`` larger than %G_MAXSSIZE will cause a :const:`~gi.repository.Gio.IOErrorEnum.INVALID_ARGUMENT` error. On success, the number of bytes skipped will be passed to the callback. 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, but generally we try to skip as many bytes as requested. Zero is returned on end of file (or if ``count`` is zero), but never otherwise. Any outstanding i/o request with higher priority (lower numerical value) will be executed before an outstanding request with lower priority. Default priority is %G_PRIORITY_DEFAULT. The asynchronous methods have a default fallback that uses threads to implement asynchronicity, so they are optional for inheriting classes. However, if you override one, you must override all. :param count: the number of bytes that will be skipped from the stream :param io_priority: the `I/O priority `__ of the request :param cancellable: optional :obj:`~gi.repository.Gio.Cancellable` object, :const:`None` to ignore. :param callback: a :obj:`~gi.repository.Gio.AsyncReadyCallback` to call when the request is satisfied :param user_data: the data to pass to callback function .. method:: do_skip_finish(result: ~gi.repository.Gio.AsyncResult) -> int Finishes a stream skip operation. :param result: a :obj:`~gi.repository.Gio.AsyncResult`\. Fields ------ .. rst-class:: interim-class .. class:: InputStream :no-index: .. attribute:: parent_instance .. attribute:: priv