gio.DataInputStream

gio.DataInputStream — Data Input Stream

Synopsis

class gio.DataInputStream(gio.BufferedInputStream):
    gio.DataInputStream(base_stream)
def get_byte_order()
def get_newline_type()
def read_byte(cancellable=None)
def read_int16(cancellable=None)
def read_int32(cancellable=None)
def read_int64(cancellable=None)
def read_line(cancellable=None)
def read_line_async(callback, io_priority=glib.PRIORITY_DEFAULT, cancellable=None, user_data=None)
def read_line_finish(result)
def read_uint16(cancellable=None)
def read_uint32(cancellable=None)
def read_uint64(cancellable=None)
def read_until(stop_chars, cancellable=None)
def read_until_async(stop_chars, callback, io_priority=glib.PRIORITY_DEFAULT, cancellable=None, user_data=None)
def read_until_finish(result)
def set_byte_order(order)
def set_newline_type(type)

Ancestry

+-- gobject.GObject
  +-- gio.InputStream
    +-- gio.FilterInputStream
      +-- gio.BufferedInputStream
        +-- gio.DataInputStream

gio.DataInputStream Properties

"byte-order"Read - WriteThe byte order. Default value: gio.DATA_STREAM_BYTE_ORDER_BIG_ENDIAN.
"newline-type"Read - WriteThe accepted types of line ending. Default value: gio.DATA_STREAM_NEWLINE_TYPE_LF.

Description

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

Constructor

    gio.DataInputStream(base_stream)

base_stream :

a gio.InputStream.

Returns :

a new gio.DataInputStream

Creates a new gio.DataInputStream from the given base_stream.

Methods

gio.DataInputStream.get_byte_order

    def get_byte_order()

Returns :

the stream's current Gio Data Stream Byte Order Constants.

The get_byte_order() method gets the byte order for the data input stream.

gio.DataInputStream.get_newline_type

    def get_newline_type()

Returns :

Gio Data Stream Newline Type Constants for the given stream.

The get_newline_type() method gets the current newline type for the stream.

gio.DataInputStream.read_byte

    def read_byte(cancellable=None)

cancellable :

optional gio.Cancellable object, None to ignore.

Returns :

an unsigned 8-bit/1-byte value read from the stream or 0 if an error occurred.

The read_byte() method reads an unsigned 8-bit/1-byte value from stream.

gio.DataInputStream.read_int16

    def read_int16(cancellable=None)

cancellable :

optional gio.Cancellable object, None to ignore.

Returns :

a signed 16-bit/2-byte value read from stream or 0 if an error occurred.

The read_int16() method reads a 16-bit/2-byte value from stream.

In order to get the correct byte order for this read operation, see gio.DataInputStream.get_byte_order() and gio.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 gio.ERROR_CANCELLED will be returned.

gio.DataInputStream.read_int32

    def read_int32(cancellable=None)

cancellable :

optional gio.Cancellable object, None to ignore.

Returns :

a signed 32-bit/4-byte value read from the stream or 0 if an error occurred.

The read_int32() method reads a signed 32-bit/4-byte value from stream.

In order to get the correct byte order for this read operation, see gio.DataInputStream.get_byte_order() and gio.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 gio.ERROR_CANCELLED will be returned.

gio.DataInputStream.read_int64

    def read_int64(cancellable=None)

cancellable :

optional gio.Cancellable object, None to ignore.

Returns :

a signed 64-bit/8-byte value read from the stream or 0 if an error occurred.

The read_int64() method reads a signed 64-bit/8-byte value from stream.

In order to get the correct byte order for this read operation, see gio.DataInputStream.get_byte_order() and gio.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 gio.ERROR_CANCELLED will be returned.

gio.DataInputStream.read_line

    def read_line(cancellable=None)

cancellable :

optional gio.Cancellable object, None to ignore.

Returns :

a string with the line that was read in (without the newlines). Set length to a gsize to get the length of the read line. On an error, it will return None and error will be set. If there's no content to read, it will still return None, but error won't be set.

The read_line() reads a 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 gio.ERROR_CANCELLED will be returned. If an operation was partially finished when the operation was cancelled the partial result will be returned, without an error.

gio.DataInputStream.read_line_async

    def read_line_async(callback, io_priority=glib.PRIORITY_DEFAULT, cancellable=None, user_data=None)

callback :

a GAsyncReadyCallback to call when the request is satisfied.

io_priority :

the Glib Priority Constants of the request.

cancellable :

optional gio.Cancellable object, None to ignore.

user_data :

the data to pass to callback function.

The read_line_async() method is the asynchronous version of gio.DataInputStream.read_line(). It is an error to have two outstanding calls to this function.

For the synchronous version of this function, see gio.DataInputStream.read_line().

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 gio.ERROR_CANCELLED will be set

gio.DataInputStream.read_line_finish

    def read_line_finish(result)

result :

a gio.AsyncResult.

Returns :

a string with the line that was read in (without the newlines). On an error, it will return None and error will be set. If there's no content to read, it will still return None, but error won't be set.

The read_line_finish() method finishes an asynchronous file append operation started with gio.DataInputStream.read_line_async().

gio.DataInputStream.read_uint16

    def read_uint16(cancellable=None)

cancellable :

optional gio.Cancellable object, None to ignore.

Returns :

a signed 16-bit/2-byte value read from stream or 0 if an error occurred.

The read_uint16() method reads a 16-bit/2-byte value from stream.

In order to get the correct byte order for this read operation, see gio.DataInputStream.get_byte_order() and gio.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 gio.ERROR_CANCELLED will be returned.

gio.DataInputStream.read_uint32

    def read_uint32(cancellable=None)

cancellable :

optional gio.Cancellable object, None to ignore.

Returns :

a signed 32-bit/4-byte value read from the stream or 0 if an error occurred.

The read_uint32() method reads a signed 32-bit/4-byte value from stream.

In order to get the correct byte order for this read operation, see gio.DataInputStream.get_byte_order() and gio.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 gio.ERROR_CANCELLED will be returned.

gio.DataInputStream.read_uint64

    def read_uint64(cancellable=None)

cancellable :

optional gio.Cancellable object, None to ignore.

Returns :

a signed 64-bit/8-byte value read from the stream or 0 if an error occurred.

The read_uint64() method reads a signed 64-bit/8-byte value from stream.

In order to get the correct byte order for this read operation, see gio.DataInputStream.get_byte_order() and gio.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 gio.ERROR_CANCELLED will be returned.

gio.DataInputStream.read_until

    def read_until(stop_chars, cancellable=None)

stop_chars :

characters to terminate the read.

cancellable :

optional gio.Cancellable object, None to ignore.

Returns :

a string with the data that was read before encountering any of the stop characters. This function will return NULL on an error.

The read_until() reads a string from the data input stream, up to the first occurrence of any of the stop characters.

gio.DataInputStream.read_until_async

    def read_until_async(stop_chars, callback, io_priority=glib.PRIORITY_DEFAULT, cancellable=None, user_data=None)

stop_chars :

characters to terminate the read.

callback :

a GAsyncReadyCallback to call when the request is satisfied.

io_priority :

the Glib Priority Constants of the request.

cancellable :

optional gio.Cancellable object, None to ignore.

user_data :

the data to pass to callback function.

The read_until_async() method it's the asynchronous version of gio.DataInputStream.read_until(). It is an error to have two outstanding calls to this function.

For the synchronous version of this function, see gio.DataInputStream.read_until().

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 gio.ERROR_CANCELLED will be set

When the operation is finished, callback will be called. You can then call gio.DataInputStream.read_until_finish() to get the result of the operation.

gio.DataInputStream.read_until_finish

    def read_until_finish(result)

result :

a gio.AsyncResult.

Returns :

a string with the data that was read before encountering any of the stop characters. This function will return None on an error.

The read_until_finish() method finishes an asynchronous file append operation started with gio.DataInputStream.read_until_async().

gio.DataInputStream.set_byte_order

    def set_byte_order(order)

order :

a Gio Data Stream Byte Order Constants to set.

The set_byte_order() method sets the byte order for the given stream. All subsequent reads from the stream will be read in the given order.

gio.DataInputStream.set_newline_type

    def set_newline_type(type)

type :

a Gio Data Stream Newline Type Constants to set.

The set_newline_type() method sets the newline type for the stream.

Note

Note that using gio.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 availible.