libg3d Reference Manual | ||||
---|---|---|---|---|
#include <g3d/stream.h> G3DStream; G3DStream* g3d_stream_open_file (const gchar *filename, const gchar *mode); G3DStream* g3d_stream_open_structured_file (const gchar *filename, const gchar *subfile); G3DStream* g3d_stream_open_structured_file_from_stream (G3DStream *stream, const gchar *subfile); G3DStream* g3d_stream_open_zip (const gchar *filename, const gchar *subfile); G3DStream* g3d_stream_open_zip_from_stream (G3DStream *stream, const gchar *subfile); G3DStream* g3d_stream_open_gzip_from_stream (G3DStream *stream); G3DStream* g3d_stream_from_buffer (guint8 *buffer, gsize size, const gchar *title, gboolean free_buffer); G3DStream* g3d_stream_zlib_inflate_stream (G3DStream *stream, gsize cmp_size); G3DStream* g3d_stream_new_custom (guint32 flags, const gchar *uri, G3DStreamReadFunc readfunc, G3DStreamReadLineFunc readlinefunc, G3DStreamSeekFunc seekfunc, G3DStreamTellFunc tellfunc, G3DStreamSizeFunc sizefunc, G3DStreamEofFunc eoffunc, G3DStreamCloseFunc closefunc, gpointer data); gint g3d_stream_close (G3DStream *stream); gint g3d_stream_skip (G3DStream *stream, goffset offset); gint g3d_stream_seek (G3DStream *stream, goffset offset, GSeekType whence); goffset g3d_stream_tell (G3DStream *stream); goffset g3d_stream_size (G3DStream *stream); gboolean g3d_stream_eof (G3DStream *stream); gboolean g3d_stream_is_seekable (G3DStream *stream); gchar* g3d_stream_get_uri (G3DStream *stream); guint32 g3d_stream_line (G3DStream *stream); gsize g3d_stream_read (G3DStream *stream, gpointer ptr, gsize size); gchar* g3d_stream_read_line (G3DStream *stream, gchar *buf, gsize size); gint32 g3d_stream_read_int8 (G3DStream *stream); gint32 g3d_stream_read_int16_be (G3DStream *stream); gint32 g3d_stream_read_int16_le (G3DStream *stream); gint32 g3d_stream_read_int32_be (G3DStream *stream); gint32 g3d_stream_read_int32_le (G3DStream *stream); G3DFloat g3d_stream_read_float_be (G3DStream *stream); G3DFloat g3d_stream_read_float_le (G3DStream *stream); G3DDouble g3d_stream_read_double_be (G3DStream *stream); G3DDouble g3d_stream_read_double_le (G3DStream *stream); gint32 g3d_stream_read_cstr (G3DStream *stream, gchar *buffer, gint32 max_len); gint (*G3DStreamCloseFunc) (gpointer data); gboolean (*G3DStreamEofFunc) (gpointer data); gsize (*G3DStreamReadFunc) (gpointer ptr, gsize size, gpointer data); gchar* (*G3DStreamReadLineFunc) (gchar *buf, gsize size, gpointer data); gint (*G3DStreamSeekFunc) (gpointer data, goffset offset, GSeekType whence); goffset (*G3DStreamSizeFunc) (gpointer data); goffset (*G3DStreamTellFunc) (gpointer data);
A stream is an abstraction for data input. It enables plugins to read data from a file, a memory buffer, a container file or some other medium.
G3DStream* g3d_stream_open_file (const gchar *filename, const gchar *mode);
Opens a file with the C stdio routines.
|
the name of the file to open |
|
the mode to open the file, as given to fopen()
|
Returns : |
a newly allocated G3DStream or NULL in case of an error. |
G3DStream* g3d_stream_open_structured_file (const gchar *filename, const gchar *subfile);
Open a file within a Structured File as G3DStream.
|
name of container file |
|
name of (contained) sub-file |
Returns : |
a newly allocated G3DStream or NULL in case of an error. |
G3DStream* g3d_stream_open_structured_file_from_stream (G3DStream *stream, const gchar *subfile);
Open a file within a Structured File which is opened as a stream. At the
moment this only works for streams opened by g3d_stream_open_file()
as
the file is directly opened again.
|
stream of container file |
|
name of (contained) sub-file |
Returns : |
a newly allocated G3DStream or NULL in case of an error. |
G3DStream* g3d_stream_open_zip (const gchar *filename, const gchar *subfile);
Open a file within a Zip archive.
|
name of container file |
|
name of (contained) sub-file |
Returns : |
a newly allocated G3DStream or NULL in case of an error. |
G3DStream* g3d_stream_open_zip_from_stream (G3DStream *stream, const gchar *subfile);
Open a file within a Zip archive which is opened as a stream. At the
moment this only works for streams opened by g3d_stream_open_file()
as
the file is directly opened again.
|
stream of container file |
|
name of (contained) sub-file |
Returns : |
a newly allocated G3DStream or NULL in case of an error. |
G3DStream* g3d_stream_open_gzip_from_stream (G3DStream *stream);
Reads data from a gzip-compressed stream.
|
stream to read from |
Returns : |
a newly allocated G3DStream or NULL in case of an error. |
G3DStream* g3d_stream_from_buffer (guint8 *buffer, gsize size, const gchar *title, gboolean free_buffer);
Use a buffer in memory as G3DStream.
|
memory buffer to use |
|
size of buffer |
|
optional title of stream, may be NULL |
|
whether to free the memory with g_free() on g3d_stream_close()
|
Returns : |
a newly allocated G3DStream or NULL in case of an error. |
G3DStream* g3d_stream_zlib_inflate_stream (G3DStream *stream, gsize cmp_size);
Opens a new stream to decompress zlib-deflated parts of a stream.
|
a parent stream |
|
the compressed size of the deflated part |
Returns : |
a newly allocated G3DStream or NULL in case of an error |
G3DStream* g3d_stream_new_custom (guint32 flags, const gchar *uri, G3DStreamReadFunc readfunc, G3DStreamReadLineFunc readlinefunc, G3DStreamSeekFunc seekfunc, G3DStreamTellFunc tellfunc, G3DStreamSizeFunc sizefunc, G3DStreamEofFunc eoffunc, G3DStreamCloseFunc closefunc, gpointer data);
Creates a new G3DStream with custom callback functions.
|
stream capability flags |
|
URI of new stream, must not be NULL |
|
read callback function |
|
read line callback function, may be NULL in which case
line reading is emulated with g3d_stream_read()
|
|
seek callback function |
|
tell callback function |
|
size callback function |
|
end-of-file callback function |
|
close callback function |
|
opaque data for all callback functions |
Returns : |
a newly allocated G3DStream or NULL in case of an error. |
gint g3d_stream_close (G3DStream *stream);
Closes an open stream.
|
the stream |
Returns : |
0 on success. |
gint g3d_stream_skip (G3DStream *stream, goffset offset);
Skip a number of bytes (>= 0) in stream even if it does not support seeking.
|
stream to skip bytes from |
|
number of bytes to skip |
Returns : |
0 on success, -1 else |
gint g3d_stream_seek (G3DStream *stream, goffset offset, GSeekType whence);
Moves around the current position in the stream.
|
stream to seek in |
|
number of bytes to seek |
|
seek type |
Returns : |
0 on success, -1 else |
goffset g3d_stream_tell (G3DStream *stream);
Tells the current position in the stream.
|
stream to get position from |
Returns : |
current stream position |
goffset g3d_stream_size (G3DStream *stream);
Get the size in bytes of a stream.
|
stream to get size from |
Returns : |
size of stream in bytes |
gboolean g3d_stream_eof (G3DStream *stream);
Checks whether the stream has reached its end.
|
the stream |
Returns : |
TRUE if no more data can be read, FALSE else. |
gboolean g3d_stream_is_seekable (G3DStream *stream);
Get information whether it is possible to seek in a stream.
|
the stream |
Returns : |
TRUE if seekable, FALSE else |
gchar* g3d_stream_get_uri (G3DStream *stream);
Get the URI of a stream
|
the stream |
Returns : |
a non-NULL, zero-terminated string containing the URI of the string. This return value should not be freed. |
guint32 g3d_stream_line (G3DStream *stream);
Get the current line number from stream. This only works if line are
consequently read with g3d_stream_read_line()
, so it's only applicable
for text streams.
|
stream to get line from |
Returns : |
current line number, may be 0 |
gsize g3d_stream_read (G3DStream *stream, gpointer ptr, gsize size);
Reads a number of bytes from the stream.
|
the stream to read from |
|
pointer to memory storage |
|
number of bytes to read |
Returns : |
number of bytes successfully read. |
gchar* g3d_stream_read_line (G3DStream *stream, gchar *buf, gsize size);
Read a line (terminated by a newline character or end of file) from a stream.
|
stream to read a line from |
|
an allocated buffer to be filled |
|
maximum length of line including terminating zero |
Returns : |
the read line or NULL in case of an error. |
gint32 g3d_stream_read_int8 (G3DStream *stream);
Read a 1 byte signed integer from file.
|
the stream to read from |
Returns : |
The read value, 0 in case of error |
gint32 g3d_stream_read_int16_be (G3DStream *stream);
Read a 2 byte big-endian signed integer from file.
|
the stream to read from |
Returns : |
The read value, 0 in case of error |
gint32 g3d_stream_read_int16_le (G3DStream *stream);
Read a 2 byte little-endian signed integer from file.
|
the stream to read from |
Returns : |
The read value, 0 in case of error |
gint32 g3d_stream_read_int32_be (G3DStream *stream);
Read a 4 byte big-endian signed integer from file.
|
the stream to read from |
Returns : |
The read value, 0 in case of error |
gint32 g3d_stream_read_int32_le (G3DStream *stream);
Read a 4 byte little-endian signed integer from file.
|
the stream to read from |
Returns : |
The read value, 0 in case of error |
G3DFloat g3d_stream_read_float_be (G3DStream *stream);
Read a 4 byte big-endian floating point number from file.
|
the stream to read from |
Returns : |
The read value, 0 in case of error |
G3DFloat g3d_stream_read_float_le (G3DStream *stream);
Read a 4 byte little-endian floating point number from file.
|
the stream to read from |
Returns : |
The read value, 0 in case of error |
G3DDouble g3d_stream_read_double_be (G3DStream *stream);
Read a 8 byte big-endian double-precision floating point number from file.
|
the stream to read from |
Returns : |
The read value, 0 in case of error |
G3DDouble g3d_stream_read_double_le (G3DStream *stream);
Read a 8 byte little-endian double-precision floating point number from file.
|
the stream to read from |
Returns : |
The read value, 0 in case of error |
gint32 g3d_stream_read_cstr (G3DStream *stream, gchar *buffer, gint32 max_len);
Read a string (terminated by '\0') from stream
|
the stream to read from |
|
the buffer to fill |
|
maximum number to read from stream |
Returns : |
number of bytes read from stream |
gint (*G3DStreamCloseFunc) (gpointer data);
Callback function for g3d_stream_close()
.
|
opaque stream data |
Returns : |
0 on success, -1 else. |
gboolean (*G3DStreamEofFunc) (gpointer data);
Callback function for g3d_stream_eof()
.
|
opaque stream data |
Returns : |
TRUE on stream end-of-file, FALSE else. |
gsize (*G3DStreamReadFunc) (gpointer ptr, gsize size, gpointer data);
Callback function for g3d_stream_read()
.
|
buffer to read bytes into |
|
number of bytes to read |
|
opaque stream data |
Returns : |
number of bytes actually read. |
gchar* (*G3DStreamReadLineFunc) (gchar *buf, gsize size, gpointer data);
Callback function for g3d_stream_read_line()
.
|
buffer to read bytes into |
|
maximum size of buffer |
|
opaque stream data |
Returns : |
The line buffer or NULL in case of an error. |
gint (*G3DStreamSeekFunc) (gpointer data, goffset offset, GSeekType whence);
Callback function for g3d_stream_seek()
.
|
opaque stream data |
|
seek offset |
|
seek type |
Returns : |
0 on success, -1 else. |
goffset (*G3DStreamSizeFunc) (gpointer data);
Callback function for g3d_stream_size()
.
|
opaque stream data |
Returns : |
size of stream. |
goffset (*G3DStreamTellFunc) (gpointer data);
Callback function for g3d_stream_tell()
.
|
opaque stream data |
Returns : |
current stream position. |