Skip to content

Gio.DataInputStream

class — extends BufferedInputStream, Seekable

Data input stream implements InputStream and includes functions for reading structured data directly from a binary input stream.

Constructors

new

@classmethod
def new(cls, base_stream: InputStream) -> DataInputStream

Creates a new data input stream for the base_stream.

Parameters:

Methods

get_byte_order

def get_byte_order(self) -> DataStreamByteOrder

Gets the byte order for the data input stream.

get_newline_type

def get_newline_type(self) -> DataStreamNewlineType

Gets the current newline type for the stream.

read_byte

def read_byte(self, cancellable: Cancellable | None = ...) -> int

Reads an unsigned 8-bit/1-byte value from stream.

Parameters:

  • cancellable — optional Cancellable object, None to ignore.

read_int16

def read_int16(self, cancellable: Cancellable | None = ...) -> int

Reads a 16-bit/2-byte value from stream.

In order to get the correct byte order for this read operation, see DataInputStream.get_byte_order and DataInputStream.set_byte_order.

Parameters:

  • cancellable — optional Cancellable object, None to ignore.

read_int32

def read_int32(self, cancellable: Cancellable | 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 DataInputStream.get_byte_order and DataInputStream.set_byte_order.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error IOErrorEnum.CANCELLED will be returned.

Parameters:

  • cancellable — optional Cancellable object, None to ignore.

read_int64

def read_int64(self, cancellable: Cancellable | None = ...) -> int

Reads a 64-bit/8-byte value from stream.

In order to get the correct byte order for this read operation, see DataInputStream.get_byte_order and DataInputStream.set_byte_order.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error IOErrorEnum.CANCELLED will be returned.

Parameters:

  • cancellable — optional Cancellable object, None to ignore.

read_line

def read_line(self, cancellable: Cancellable | None = ...) -> 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 None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error IOErrorEnum.CANCELLED will be returned.

Parameters:

  • cancellable — optional Cancellable object, None to ignore.

read_line_async

def read_line_async(self, io_priority: int, cancellable: Cancellable | None = ..., callback: Callable[[DataInputStream | None, AsyncResult], None] | None = ...) -> None

The asynchronous version of 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 DataInputStream.read_line_finish to get the result of the operation.

Parameters:

  • io_priority — the I/O priority of the request
  • cancellable — optional Cancellable object, None to ignore.
  • callback — callback to call when the request is satisfied.

read_line_finish

def read_line_finish(self, result: AsyncResult) -> tuple[list[int] | None, int]

Finish an asynchronous call started by DataInputStream.read_line_async. Note the warning about string encoding in DataInputStream.read_line applies here as well.

Parameters:

  • result — the AsyncResult that was provided to the callback.

read_line_finish_utf8

def read_line_finish_utf8(self, result: AsyncResult) -> tuple[str | None, int]

Finish an asynchronous call started by DataInputStream.read_line_async.

Parameters:

  • result — the AsyncResult that was provided to the callback.

read_line_utf8

def read_line_utf8(self, cancellable: Cancellable | None = ...) -> tuple[str | None, int]

Reads a UTF-8 encoded line from the data input stream.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error IOErrorEnum.CANCELLED will be returned.

Parameters:

  • cancellable — optional Cancellable object, None to ignore.

read_uint16

def read_uint16(self, cancellable: Cancellable | 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 DataInputStream.get_byte_order and DataInputStream.set_byte_order.

Parameters:

  • cancellable — optional Cancellable object, None to ignore.

read_uint32

def read_uint32(self, cancellable: Cancellable | 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 DataInputStream.get_byte_order and DataInputStream.set_byte_order.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error IOErrorEnum.CANCELLED will be returned.

Parameters:

  • cancellable — optional Cancellable object, None to ignore.

read_uint64

def read_uint64(self, cancellable: Cancellable | 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 DataInputStream.get_byte_order.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error IOErrorEnum.CANCELLED will be returned.

Parameters:

  • cancellable — optional Cancellable object, None to ignore.

read_until

def read_until(self, stop_chars: str, cancellable: Cancellable | None = ...) -> tuple[str, int]

:::warning Deprecated since 2.56 This API is deprecated. :::

Reads a string from the data input stream, up to the first occurrence of any of the stop characters.

Note that, in contrast to 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 DataInputStream.read_until_async. Both functions will be marked as deprecated in a future release. Use DataInputStream.read_upto instead, but note that that function does not consume the stop character.

Parameters:

  • stop_chars — characters to terminate the read.
  • cancellable — optional Cancellable object, None to ignore.

read_until_async

def read_until_async(self, stop_chars: str, io_priority: int, cancellable: Cancellable | None = ..., callback: Callable[[DataInputStream | None, AsyncResult], None] | None = ...) -> None

:::warning Deprecated since 2.56 This API is deprecated. :::

The asynchronous version of DataInputStream.read_until. It is an error to have two outstanding calls to this function.

Note that, in contrast to 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 DataInputStream.read_until_finish to get the result of the operation.

Don't use this function in new code. Its functionality is inconsistent with DataInputStream.read_until. Both functions will be marked as deprecated in a future release. Use DataInputStream.read_upto_async instead.

Parameters:

  • stop_chars — characters to terminate the read.
  • io_priority — the I/O priority of the request
  • cancellable — optional Cancellable object, None to ignore.
  • callback — callback to call when the request is satisfied.

read_until_finish

def read_until_finish(self, result: AsyncResult) -> tuple[str, int]

:::warning Deprecated since 2.56 This API is deprecated. :::

Finish an asynchronous call started by DataInputStream.read_until_async.

Parameters:

  • result — the AsyncResult that was provided to the callback.

read_upto

def read_upto(self, stop_chars: str, stop_chars_len: int, cancellable: Cancellable | None = ...) -> 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 DataInputStream.read_until, this function does not consume the stop character. You have to use DataInputStream.read_byte to get it before calling 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.

Parameters:

  • stop_chars — characters to terminate the read
  • stop_chars_len — length of stop_chars. May be -1 if stop_chars is nul-terminated
  • cancellable — optional Cancellable object, None to ignore

read_upto_async

def read_upto_async(self, stop_chars: str, stop_chars_len: int, io_priority: int, cancellable: Cancellable | None = ..., callback: Callable[[DataInputStream | None, AsyncResult], None] | None = ...) -> None

The asynchronous version of DataInputStream.read_upto. It is an error to have two outstanding calls to this function.

In contrast to DataInputStream.read_until, this function does not consume the stop character. You have to use DataInputStream.read_byte to get it before calling 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 DataInputStream.read_upto_finish to get the result of the operation.

Parameters:

  • stop_chars — characters to terminate the read
  • stop_chars_len — length of stop_chars. May be -1 if stop_chars is nul-terminated
  • io_priority — the I/O priority of the request
  • cancellable — optional Cancellable object, None to ignore
  • callback — callback to call when the request is satisfied

read_upto_finish

def read_upto_finish(self, result: AsyncResult) -> tuple[str, int]

Finish an asynchronous call started by DataInputStream.read_upto_async.

Note that this function does not consume the stop character. You have to use DataInputStream.read_byte to get it before calling DataInputStream.read_upto_async again.

The returned string will always be nul-terminated on success.

Parameters:

  • result — the AsyncResult that was provided to the callback

set_byte_order

def set_byte_order(self, order: DataStreamByteOrder | int) -> None

This function sets the byte order for the given stream. All subsequent reads from the stream will be read in the given order.

Parameters:

set_newline_type

def set_newline_type(self, type: DataStreamNewlineType | int) -> 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.

Parameters:

Properties

byte_order

byte_order: DataStreamByteOrder | int  # read/write

The :byte-order property determines the byte ordering that is used when reading multi-byte entities (such as integers) from the stream.

newline_type

newline_type: DataStreamNewlineType | int  # read/write

The :newline-type property determines what is considered as a line ending when reading complete lines from the stream.