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¶
Creates a new data input stream for the base_stream.
Parameters:
base_stream— aInputStream.
Methods¶
get_byte_order¶
Gets the byte order for the data input stream.
get_newline_type¶
Gets the current newline type for the stream.
read_byte¶
Reads an unsigned 8-bit/1-byte value from stream.
Parameters:
cancellable— optionalCancellableobject,Noneto ignore.
read_int16¶
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— optionalCancellableobject,Noneto ignore.
read_int32¶
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— optionalCancellableobject,Noneto ignore.
read_int64¶
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— optionalCancellableobject,Noneto ignore.
read_line¶
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— optionalCancellableobject,Noneto 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 requestcancellable— optionalCancellableobject,Noneto ignore.callback— callback to call when the request is satisfied.
read_line_finish¶
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— theAsyncResultthat was provided to the callback.
read_line_finish_utf8¶
Finish an asynchronous call started by
DataInputStream.read_line_async.
Parameters:
result— theAsyncResultthat was provided to the callback.
read_line_utf8¶
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— optionalCancellableobject,Noneto ignore.
read_uint16¶
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— optionalCancellableobject,Noneto ignore.
read_uint32¶
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— optionalCancellableobject,Noneto ignore.
read_uint64¶
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— optionalCancellableobject,Noneto ignore.
read_until¶
:::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— optionalCancellableobject,Noneto 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 requestcancellable— optionalCancellableobject,Noneto ignore.callback— callback to call when the request is satisfied.
read_until_finish¶
:::warning Deprecated since 2.56 This API is deprecated. :::
Finish an asynchronous call started by
DataInputStream.read_until_async.
Parameters:
result— theAsyncResultthat 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 readstop_chars_len— length ofstop_chars. May be -1 ifstop_charsis nul-terminatedcancellable— optionalCancellableobject,Noneto 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 readstop_chars_len— length ofstop_chars. May be -1 ifstop_charsis nul-terminatedio_priority— the I/O priority of the requestcancellable— optionalCancellableobject,Noneto ignorecallback— callback to call when the request is satisfied
read_upto_finish¶
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— theAsyncResultthat was provided to the callback
set_byte_order¶
This function sets the byte order for the given stream. All subsequent
reads from the stream will be read in the given order.
Parameters:
order— aDataStreamByteOrderto set.
set_newline_type¶
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:
type— the type of new line return asDataStreamNewlineType.
Properties¶
byte_order¶
The :byte-order property determines the byte ordering that is used when reading multi-byte entities (such as integers) from the stream.
newline_type¶
The :newline-type property determines what is considered as a line ending when reading complete lines from the stream.