GIO Reference Manual | ||||
---|---|---|---|---|
Top | Description | Object Hierarchy | Properties |
#include <gio/gio.h> GDataInputStream; enum GDataStreamByteOrder; enum GDataStreamNewlineType; GDataInputStream * g_data_input_stream_new (GInputStream *base_stream); void g_data_input_stream_set_byte_order (GDataInputStream *stream, GDataStreamByteOrder order); GDataStreamByteOrder g_data_input_stream_get_byte_order (GDataInputStream *stream); void g_data_input_stream_set_newline_type (GDataInputStream *stream, GDataStreamNewlineType type); GDataStreamNewlineType g_data_input_stream_get_newline_type (GDataInputStream *stream); guchar g_data_input_stream_read_byte (GDataInputStream *stream, GCancellable *cancellable, GError **error); gint16 g_data_input_stream_read_int16 (GDataInputStream *stream, GCancellable *cancellable, GError **error); guint16 g_data_input_stream_read_uint16 (GDataInputStream *stream, GCancellable *cancellable, GError **error); gint32 g_data_input_stream_read_int32 (GDataInputStream *stream, GCancellable *cancellable, GError **error); guint32 g_data_input_stream_read_uint32 (GDataInputStream *stream, GCancellable *cancellable, GError **error); gint64 g_data_input_stream_read_int64 (GDataInputStream *stream, GCancellable *cancellable, GError **error); guint64 g_data_input_stream_read_uint64 (GDataInputStream *stream, GCancellable *cancellable, GError **error); char * g_data_input_stream_read_line (GDataInputStream *stream, gsize *length, GCancellable *cancellable, GError **error); void g_data_input_stream_read_line_async (GDataInputStream *stream, gint io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); char * g_data_input_stream_read_line_finish (GDataInputStream *stream, GAsyncResult *result, gsize *length, GError **error); char * g_data_input_stream_read_until (GDataInputStream *stream, const gchar *stop_chars, gsize *length, GCancellable *cancellable, GError **error); void g_data_input_stream_read_until_async (GDataInputStream *stream, const gchar *stop_chars, gint io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); char * g_data_input_stream_read_until_finish (GDataInputStream *stream, GAsyncResult *result, gsize *length, GError **error);
GObject +----GInputStream +----GFilterInputStream +----GBufferedInputStream +----GDataInputStream
"byte-order" GDataStreamByteOrder : Read / Write "newline-type" GDataStreamNewlineType : Read / Write
Data input stream implements GInputStream and includes functions for reading structured data directly from a binary input stream.
typedef struct _GDataInputStream GDataInputStream;
An implementation of GBufferedInputStream that allows for high-level data manipulation of arbitrary data (including binary operations).
typedef enum { G_DATA_STREAM_BYTE_ORDER_BIG_ENDIAN, G_DATA_STREAM_BYTE_ORDER_LITTLE_ENDIAN, G_DATA_STREAM_BYTE_ORDER_HOST_ENDIAN } GDataStreamByteOrder;
GDataStreamByteOrder is used to ensure proper endianness of streaming data sources across various machine architectures.
typedef enum { G_DATA_STREAM_NEWLINE_TYPE_LF, G_DATA_STREAM_NEWLINE_TYPE_CR, G_DATA_STREAM_NEWLINE_TYPE_CR_LF, G_DATA_STREAM_NEWLINE_TYPE_ANY } GDataStreamNewlineType;
GDataStreamNewlineType is used when checking for or setting the line endings for a given file.
Selects "LF" line endings, common on most modern UNIX platforms. | |
Selects "CR" line endings. | |
Selects "CR, LF" line ending, common on Microsoft Windows. | |
Automatically try to handle any line ending type. |
GDataInputStream * g_data_input_stream_new (GInputStream *base_stream);
Creates a new data input stream for the base_stream
.
|
a GInputStream. |
Returns : |
a new GDataInputStream. |
void g_data_input_stream_set_byte_order (GDataInputStream *stream, GDataStreamByteOrder order);
This function sets the byte order for the given stream
. All subsequent
reads from the stream
will be read in the given order
.
|
a given GDataInputStream. |
|
a GDataStreamByteOrder to set. |
GDataStreamByteOrder g_data_input_stream_get_byte_order (GDataInputStream *stream);
Gets the byte order for the data input stream.
|
a given GDataInputStream. |
Returns : |
the stream 's current GDataStreamByteOrder.
|
void g_data_input_stream_set_newline_type (GDataInputStream *stream, GDataStreamNewlineType 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 availible.
|
a GDataInputStream. |
|
the type of new line return as GDataStreamNewlineType. |
GDataStreamNewlineType g_data_input_stream_get_newline_type (GDataInputStream *stream);
Gets the current newline type for the stream
.
|
a given GDataInputStream. |
Returns : |
GDataStreamNewlineType for the given stream .
|
guchar g_data_input_stream_read_byte (GDataInputStream *stream, GCancellable *cancellable, GError **error);
Reads an unsigned 8-bit/1-byte value from stream
.
|
a given GDataInputStream. |
|
optional GCancellable object, NULL to ignore.
|
|
GError for error reporting. |
Returns : |
an unsigned 8-bit/1-byte value read from the stream or 0
if an error occurred.
|
gint16 g_data_input_stream_read_int16 (GDataInputStream *stream, GCancellable *cancellable, GError **error);
Reads a 16-bit/2-byte value from stream
.
In order to get the correct byte order for this read operation,
see g_data_stream_get_byte_order()
and g_data_stream_set_byte_order()
.
|
a given GDataInputStream. |
|
optional GCancellable object, NULL to ignore.
|
|
GError for error reporting. |
Returns : |
a signed 16-bit/2-byte value read from stream or 0 if
an error occurred.
|
guint16 g_data_input_stream_read_uint16 (GDataInputStream *stream, GCancellable *cancellable, GError **error);
Reads an unsigned 16-bit/2-byte value from stream
.
In order to get the correct byte order for this read operation,
see g_data_stream_get_byte_order()
and g_data_stream_set_byte_order()
.
|
a given GDataInputStream. |
|
optional GCancellable object, NULL to ignore.
|
|
GError for error reporting. |
Returns : |
an unsigned 16-bit/2-byte value read from the stream or 0 if
an error occurred.
|
gint32 g_data_input_stream_read_int32 (GDataInputStream *stream, GCancellable *cancellable, GError **error);
Reads a signed 32-bit/4-byte value from stream
.
In order to get the correct byte order for this read operation,
see g_data_stream_get_byte_order()
and g_data_stream_set_byte_order()
.
If cancellable
is not NULL
, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error G_IO_ERROR_CANCELLED
will be returned.
|
a given GDataInputStream. |
|
optional GCancellable object, NULL to ignore.
|
|
GError for error reporting. |
Returns : |
a signed 32-bit/4-byte value read from the stream or 0 if
an error occurred.
|
guint32 g_data_input_stream_read_uint32 (GDataInputStream *stream, GCancellable *cancellable, GError **error);
Reads an unsigned 32-bit/4-byte value from stream
.
In order to get the correct byte order for this read operation,
see g_data_stream_get_byte_order()
and g_data_stream_set_byte_order()
.
If cancellable
is not NULL
, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error G_IO_ERROR_CANCELLED
will be returned.
|
a given GDataInputStream. |
|
optional GCancellable object, NULL to ignore.
|
|
GError for error reporting. |
Returns : |
an unsigned 32-bit/4-byte value read from the stream or 0 if
an error occurred.
|
gint64 g_data_input_stream_read_int64 (GDataInputStream *stream, GCancellable *cancellable, GError **error);
Reads a 64-bit/8-byte value from stream
.
In order to get the correct byte order for this read operation,
see g_data_stream_get_byte_order()
and g_data_stream_set_byte_order()
.
If cancellable
is not NULL
, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error G_IO_ERROR_CANCELLED
will be returned.
|
a given GDataInputStream. |
|
optional GCancellable object, NULL to ignore.
|
|
GError for error reporting. |
Returns : |
a signed 64-bit/8-byte value read from stream or 0 if
an error occurred.
|
guint64 g_data_input_stream_read_uint64 (GDataInputStream *stream, GCancellable *cancellable, GError **error);
Reads an unsigned 64-bit/8-byte value from stream
.
In order to get the correct byte order for this read operation,
see g_data_stream_get_byte_order()
.
If cancellable
is not NULL
, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error G_IO_ERROR_CANCELLED
will be returned.
|
a given GDataInputStream. |
|
optional GCancellable object, NULL to ignore.
|
|
GError for error reporting. |
Returns : |
an unsigned 64-bit/8-byte read from stream or 0 if
an error occurred.
|
char * g_data_input_stream_read_line (GDataInputStream *stream, gsize *length, GCancellable *cancellable, GError **error);
Reads a line from the data input stream.
If cancellable
is not NULL
, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error G_IO_ERROR_CANCELLED
will be returned.
|
a given GDataInputStream. |
|
a gsize to get the length of the data read in. |
|
optional GCancellable object, NULL to ignore.
|
|
GError for error reporting. |
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 NULL and error will be set. If there's no
content to read, it will still return NULL , but error won't be set.
|
void g_data_input_stream_read_line_async (GDataInputStream *stream, gint io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data);
The asynchronous version of g_data_input_stream_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 g_data_input_stream_read_line_finish()
to get
the result of the operation.
|
a given GDataInputStream. |
|
the I/O priority of the request. |
|
optional GCancellable object, NULL to ignore.
|
|
callback to call when the request is satisfied. |
|
the data to pass to callback function. |
Since 2.20
char * g_data_input_stream_read_line_finish (GDataInputStream *stream, GAsyncResult *result, gsize *length, GError **error);
Finish an asynchronous call started by
g_data_input_stream_read_line_async()
.
|
a given GDataInputStream. |
|
the GAsyncResult that was provided to the callback. |
|
a gsize to get the length of the data read in. |
|
GError for error reporting. |
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 NULL and error will be set. If there's no
content to read, it will still return NULL , but error won't be set.
|
Since 2,20
char * g_data_input_stream_read_until (GDataInputStream *stream, const gchar *stop_chars, gsize *length, GCancellable *cancellable, GError **error);
Reads a string from the data input stream, up to the first occurrence of any of the stop characters.
|
a given GDataInputStream. |
|
characters to terminate the read. |
|
a gsize to get the length of the data read in. |
|
optional GCancellable object, NULL to ignore.
|
|
GError for error reporting. |
Returns : |
a string with the data that was read before encountering
any of the stop characters. Set length to a gsize to get the length
of the string. This function will return NULL on an error.
|
void g_data_input_stream_read_until_async (GDataInputStream *stream, const gchar *stop_chars, gint io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data);
The asynchronous version of g_data_input_stream_read_until()
.
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 g_data_input_stream_read_until_finish()
to get
the result of the operation.
|
a given GDataInputStream. |
|
characters to terminate the read. |
|
the I/O priority of the request. |
|
optional GCancellable object, NULL to ignore.
|
|
callback to call when the request is satisfied. |
|
the data to pass to callback function. |
Since 2.20
char * g_data_input_stream_read_until_finish (GDataInputStream *stream, GAsyncResult *result, gsize *length, GError **error);
Finish an asynchronous call started by
g_data_input_stream_read_until_async()
.
|
a given GDataInputStream. |
|
the GAsyncResult that was provided to the callback. |
|
a gsize to get the length of the data read in. |
|
GError for error reporting. |
Returns : |
a string with the data that was read before encountering
any of the stop characters. Set length to a gsize to get the length
of the string. This function will return NULL on an error.
|
Since 2.20
"byte-order"
property"byte-order" GDataStreamByteOrder : Read / Write
The byte order.
Default value: G_DATA_STREAM_BYTE_ORDER_BIG_ENDIAN
"newline-type"
property"newline-type" GDataStreamNewlineType : Read / Write
The accepted types of line ending.
Default value: G_DATA_STREAM_NEWLINE_TYPE_LF