:right-sidebar: True DataInputStream =================================================================== .. currentmodule:: gi.repository.Gio .. class:: DataInputStream(**properties: ~typing.Any) :no-contents-entry: Superclasses: :class:`~gi.repository.Gio.BufferedInputStream`, :class:`~gi.repository.Gio.FilterInputStream`, :class:`~gi.repository.Gio.InputStream`, :class:`~gi.repository.GObject.Object` Implemented Interfaces: :class:`~gi.repository.Gio.Seekable` Data input stream implements :obj:`~gi.repository.Gio.InputStream` and includes functions for reading structured data directly from a binary input stream. Constructors ------------ .. rst-class:: interim-class .. class:: DataInputStream :no-index: .. classmethod:: new(base_stream: ~gi.repository.Gio.InputStream) -> ~gi.repository.Gio.DataInputStream Creates a new data input stream for the ``base_stream``\. :param base_stream: a :obj:`~gi.repository.Gio.InputStream`\. Methods ------- .. rst-class:: interim-class .. class:: DataInputStream :no-index: .. method:: get_byte_order() -> ~gi.repository.Gio.DataStreamByteOrder Gets the byte order for the data input stream. .. method:: get_newline_type() -> ~gi.repository.Gio.DataStreamNewlineType Gets the current newline type for the ``stream``\. .. method:: read_byte(cancellable: ~gi.repository.Gio.Cancellable | None = None) -> int Reads an unsigned 8-bit/1-byte value from ``stream``\. :param cancellable: optional :obj:`~gi.repository.Gio.Cancellable` object, :const:`None` to ignore. .. method:: read_int16(cancellable: ~gi.repository.Gio.Cancellable | None = None) -> int Reads a 16-bit/2-byte value from ``stream``\. In order to get the correct byte order for this read operation, see :func:`~gi.repository.Gio.DataInputStream.get_byte_order` and :func:`~gi.repository.Gio.DataInputStream.set_byte_order`. :param cancellable: optional :obj:`~gi.repository.Gio.Cancellable` object, :const:`None` to ignore. .. method:: read_int32(cancellable: ~gi.repository.Gio.Cancellable | None = None) -> int Reads a signed 32-bit/4-byte value from ``stream``\. In order to get the correct byte order for this read operation, see :func:`~gi.repository.Gio.DataInputStream.get_byte_order` and :func:`~gi.repository.Gio.DataInputStream.set_byte_order`. 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. :param cancellable: optional :obj:`~gi.repository.Gio.Cancellable` object, :const:`None` to ignore. .. method:: read_int64(cancellable: ~gi.repository.Gio.Cancellable | None = None) -> int Reads a 64-bit/8-byte value from ``stream``\. In order to get the correct byte order for this read operation, see :func:`~gi.repository.Gio.DataInputStream.get_byte_order` and :func:`~gi.repository.Gio.DataInputStream.set_byte_order`. 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. :param cancellable: optional :obj:`~gi.repository.Gio.Cancellable` object, :const:`None` to ignore. .. method:: read_line(cancellable: ~gi.repository.Gio.Cancellable | None = None) -> ~typing.Tuple[list[int] | None, int] Reads a line from the data input stream. Note that no encoding checks or conversion is performed; the input is not guaranteed to be UTF-8, and may in fact have embedded NUL characters. 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. :param cancellable: optional :obj:`~gi.repository.Gio.Cancellable` object, :const:`None` to ignore. .. method:: read_line_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 The asynchronous version of :func:`~gi.repository.Gio.DataInputStream.read_line`. It is an error to have two outstanding calls to this function. When the operation is finished, ``callback`` will be called. You can then call :func:`~gi.repository.Gio.DataInputStream.read_line_finish` to get the result of the operation. .. versionadded:: 2.20 :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: callback to call when the request is satisfied. :param user_data: the data to pass to callback function. .. method:: read_line_finish(result: ~gi.repository.Gio.AsyncResult) -> ~typing.Tuple[list[int] | None, int] Finish an asynchronous call started by :func:`~gi.repository.Gio.DataInputStream.read_line_async`. Note the warning about string encoding in :func:`~gi.repository.Gio.DataInputStream.read_line` applies here as well. .. versionadded:: 2.20 :param result: the :obj:`~gi.repository.Gio.AsyncResult` that was provided to the callback. .. method:: read_line_finish_utf8(result: ~gi.repository.Gio.AsyncResult) -> ~typing.Tuple[str | None, int] Finish an asynchronous call started by :func:`~gi.repository.Gio.DataInputStream.read_line_async`. .. versionadded:: 2.30 :param result: the :obj:`~gi.repository.Gio.AsyncResult` that was provided to the callback. .. method:: read_line_utf8(cancellable: ~gi.repository.Gio.Cancellable | None = None) -> ~typing.Tuple[str | None, int] Reads a UTF-8 encoded line from the data input stream. 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. .. versionadded:: 2.30 :param cancellable: optional :obj:`~gi.repository.Gio.Cancellable` object, :const:`None` to ignore. .. method:: read_uint16(cancellable: ~gi.repository.Gio.Cancellable | None = None) -> int Reads an unsigned 16-bit/2-byte value from ``stream``\. In order to get the correct byte order for this read operation, see :func:`~gi.repository.Gio.DataInputStream.get_byte_order` and :func:`~gi.repository.Gio.DataInputStream.set_byte_order`. :param cancellable: optional :obj:`~gi.repository.Gio.Cancellable` object, :const:`None` to ignore. .. method:: read_uint32(cancellable: ~gi.repository.Gio.Cancellable | None = None) -> int Reads an unsigned 32-bit/4-byte value from ``stream``\. In order to get the correct byte order for this read operation, see :func:`~gi.repository.Gio.DataInputStream.get_byte_order` and :func:`~gi.repository.Gio.DataInputStream.set_byte_order`. 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. :param cancellable: optional :obj:`~gi.repository.Gio.Cancellable` object, :const:`None` to ignore. .. method:: read_uint64(cancellable: ~gi.repository.Gio.Cancellable | None = None) -> int Reads an unsigned 64-bit/8-byte value from ``stream``\. In order to get the correct byte order for this read operation, see :func:`~gi.repository.Gio.DataInputStream.get_byte_order`. 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. :param cancellable: optional :obj:`~gi.repository.Gio.Cancellable` object, :const:`None` to ignore. .. method:: read_until(stop_chars: str, cancellable: ~gi.repository.Gio.Cancellable | None = None) -> ~typing.Tuple[str, int] Reads a string from the data input stream, up to the first occurrence of any of the stop characters. Note that, in contrast to :func:`~gi.repository.Gio.DataInputStream.read_until_async`, this function consumes the stop character that it finds. Don't use this function in new code. Its functionality is inconsistent with :func:`~gi.repository.Gio.DataInputStream.read_until_async`. Both functions will be marked as deprecated in a future release. Use :func:`~gi.repository.Gio.DataInputStream.read_upto` instead, but note that that function does not consume the stop character. .. deprecated:: 2.56 Use :func:`~gi.repository.Gio.DataInputStream.read_upto` instead, which has more consistent behaviour regarding the stop character. :param stop_chars: characters to terminate the read. :param cancellable: optional :obj:`~gi.repository.Gio.Cancellable` object, :const:`None` to ignore. .. method:: read_until_async(stop_chars: str, 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 The asynchronous version of :func:`~gi.repository.Gio.DataInputStream.read_until`. It is an error to have two outstanding calls to this function. Note that, in contrast to :func:`~gi.repository.Gio.DataInputStream.read_until`, this function does not consume the stop character that it finds. You must read it for yourself. When the operation is finished, ``callback`` will be called. You can then call :func:`~gi.repository.Gio.DataInputStream.read_until_finish` to get the result of the operation. Don't use this function in new code. Its functionality is inconsistent with :func:`~gi.repository.Gio.DataInputStream.read_until`. Both functions will be marked as deprecated in a future release. Use :func:`~gi.repository.Gio.DataInputStream.read_upto_async` instead. .. versionadded:: 2.20 .. deprecated:: 2.56 Use :func:`~gi.repository.Gio.DataInputStream.read_upto_async` instead, which has more consistent behaviour regarding the stop character. :param stop_chars: characters to terminate the read. :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: callback to call when the request is satisfied. :param user_data: the data to pass to callback function. .. method:: read_until_finish(result: ~gi.repository.Gio.AsyncResult) -> ~typing.Tuple[str, int] Finish an asynchronous call started by :func:`~gi.repository.Gio.DataInputStream.read_until_async`. .. versionadded:: 2.20 .. deprecated:: 2.56 Use :func:`~gi.repository.Gio.DataInputStream.read_upto_finish` instead, which has more consistent behaviour regarding the stop character. :param result: the :obj:`~gi.repository.Gio.AsyncResult` that was provided to the callback. .. method:: read_upto(stop_chars: str, stop_chars_len: int, cancellable: ~gi.repository.Gio.Cancellable | None = None) -> ~typing.Tuple[str, int] Reads a string from the data input stream, up to the first occurrence of any of the stop characters. In contrast to :func:`~gi.repository.Gio.DataInputStream.read_until`, this function does not consume the stop character. You have to use :func:`~gi.repository.Gio.DataInputStream.read_byte` to get it before calling :func:`~gi.repository.Gio.DataInputStream.read_upto` again. Note that ``stop_chars`` may contain '\0' if ``stop_chars_len`` is specified. The returned string will always be nul-terminated on success. .. versionadded:: 2.26 :param stop_chars: characters to terminate the read :param stop_chars_len: length of ``stop_chars``\. May be -1 if ``stop_chars`` is nul-terminated :param cancellable: optional :obj:`~gi.repository.Gio.Cancellable` object, :const:`None` to ignore .. method:: read_upto_async(stop_chars: str, stop_chars_len: 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 The asynchronous version of :func:`~gi.repository.Gio.DataInputStream.read_upto`. It is an error to have two outstanding calls to this function. In contrast to :func:`~gi.repository.Gio.DataInputStream.read_until`, this function does not consume the stop character. You have to use :func:`~gi.repository.Gio.DataInputStream.read_byte` to get it before calling :func:`~gi.repository.Gio.DataInputStream.read_upto` again. Note that ``stop_chars`` may contain '\0' if ``stop_chars_len`` is specified. When the operation is finished, ``callback`` will be called. You can then call :func:`~gi.repository.Gio.DataInputStream.read_upto_finish` to get the result of the operation. .. versionadded:: 2.26 :param stop_chars: characters to terminate the read :param stop_chars_len: length of ``stop_chars``\. May be -1 if ``stop_chars`` is nul-terminated :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: callback to call when the request is satisfied :param user_data: the data to pass to callback function .. method:: read_upto_finish(result: ~gi.repository.Gio.AsyncResult) -> ~typing.Tuple[str, int] Finish an asynchronous call started by :func:`~gi.repository.Gio.DataInputStream.read_upto_async`. Note that this function does not consume the stop character. You have to use :func:`~gi.repository.Gio.DataInputStream.read_byte` to get it before calling :func:`~gi.repository.Gio.DataInputStream.read_upto_async` again. The returned string will always be nul-terminated on success. .. versionadded:: 2.24 :param result: the :obj:`~gi.repository.Gio.AsyncResult` that was provided to the callback .. method:: set_byte_order(order: ~gi.repository.Gio.DataStreamByteOrder) -> None This function sets the byte order for the given ``stream``\. All subsequent reads from the ``stream`` will be read in the given ``order``\. :param order: a :obj:`~gi.repository.Gio.DataStreamByteOrder` to set. .. method:: set_newline_type(type: ~gi.repository.Gio.DataStreamNewlineType) -> None Sets the newline type for the ``stream``\. Note that using G_DATA_STREAM_NEWLINE_TYPE_ANY is slightly unsafe. If a read chunk ends in "CR" we must read an additional byte to know if this is "CR" or "CR LF", and this might block if there is no more data available. :param type: the type of new line return as :obj:`~gi.repository.Gio.DataStreamNewlineType`\. Properties ---------- .. rst-class:: interim-class .. class:: DataInputStream :no-index: .. attribute:: props.byte_order :type: ~gi.repository.Gio.DataStreamByteOrder The type of the None singleton. .. attribute:: props.newline_type :type: ~gi.repository.Gio.DataStreamNewlineType The type of the None singleton. Fields ------ .. rst-class:: interim-class .. class:: DataInputStream :no-index: .. attribute:: parent_instance .. attribute:: priv