<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../../../style.css">
<title>
Gambas Documentation - GB_STREAM_DESC
</title>
</head>
<table class="none" width="100%" cellpadding="0" cellspacing="0" border="0">
<tr><td align="left">
<font size="-1">
<a href="../../../help+en"><img class="flag" alt="Home" border="0" src="../../../img/lang/en.png" align="center"></a>&nbsp;
<a href="../name+en">Up</a>&nbsp;
<a href="gb_stream+en">Previous</a>&nbsp;
<a href="gb_string+en">Next</a>&nbsp;
</td></tr></table>
<div class="notab">
<h1>
GB_STREAM_DESC
</h1>
<div class="black"><font size="-2"><b>Syntax</b></font></div>
<pre class="syntax">struct GB_STREAM;
<p>
typedef
&nbsp;&nbsp;struct {
&nbsp;&nbsp;&nbsp;&nbsp;int (*<b>open</b>)(struct GB_STREAM *stream, const char *path, int mode, void *data);
&nbsp;&nbsp;&nbsp;&nbsp;int (*<b>close</b>)(struct GB_STREAM *stream);
&nbsp;&nbsp;&nbsp;&nbsp;int (*<b>read</b>)(struct GB_STREAM *stream, char *buffer, long len);
&nbsp;&nbsp;&nbsp;&nbsp;int (*<b>write</b>)(struct GB_STREAM *stream, char *buffer, long len);
&nbsp;&nbsp;&nbsp;&nbsp;int (*<b>seek</b>)(struct GB_STREAM *stream, long long pos, int whence);
&nbsp;&nbsp;&nbsp;&nbsp;int (*<b>tell</b>)(struct GB_STREAM *stream, long long *pos);
&nbsp;&nbsp;&nbsp;&nbsp;int (*<b>flush</b>)(struct GB_STREAM *stream);
&nbsp;&nbsp;&nbsp;&nbsp;int (*<b>eof</b>)(struct GB_STREAM *stream);
&nbsp;&nbsp;&nbsp;&nbsp;int (*<b>lof</b>)(struct GB_STREAM *stream, long long *len);
&nbsp;&nbsp;&nbsp;&nbsp;int (*<b>handle</b>)(struct GB_STREAM *stream);
&nbsp;&nbsp;&nbsp;&nbsp;}
<b>GB_STREAM_DESC</b>;</pre><p>

This describe is a function pointer table that must point at the implementation functions
of a <a href="../../def/stream+en">stream</a>.
<p>
Each <a href="../../def/stream+en">stream</a> has a pointer to such a structure. See <a href="gb_stream+en">GB_STREAM</a> for more details.
<p>
<table class="table" border="0" bordercolor="#000000" cellpadding="4" cellspacing="0">
<tr><th>
Function
</th><th>
What should be done
</th><th>
What should be returned
</th></tr>
<tr class="dark"><td valign="top">
<tt><b>open</b></tt>
</td><td valign="top">
Opens the <a href="../../def/stream+en">stream</a>.
<p>
This function is never called directly by the interpreter, as you must open
the file yourself, by instanciating the <a href="../../comp/gb/stream+en">Stream</a> <a href="../../def/gambas+en">Gambas</a> object, and by filling the <a href="gb_stream+en">GB_STREAM</a>
structure appropriately.
</td><td valign="top">
<tt>TRUE</tt> if the <a href="../../def/stream+en">stream</a> cannot be opened, and <tt>FALSE</tt> if everything is OK.
</td></tr>
<tr><td valign="top">
<tt><b>close</b></tt>
</td><td valign="top">
Closes the <a href="../../def/stream+en">stream</a>.
</td><td valign="top">
<tt>FALSE</tt>.
</td></tr>
<tr class="dark"><td valign="top">
<tt><b>read</b></tt>
</td><td valign="top">
Reads <u>len</u> bytes into the <a href="../../def/stream+en">stream</a>, and fills the <u>buffer</u> with them.
</td><td valign="top">
<tt>TRUE</tt> if there was an error, and <tt>FALSE</tt> if everything is OK.
<p>
The <tt>errno</tt> code is used by the interpreter
to choose the error message.
</td></tr>
<tr><td valign="top">
<tt><b>write</b></tt>
</td><td valign="top">
Writes the <u>len</u> bytes located at <u>buffer</u> to the <a href="../../def/stream+en">stream</a>.
</td><td valign="top">
<tt>TRUE</tt> if there was an error, and <tt>FALSE</tt> if everything is OK.
<p>
The <tt>errno</tt> code is used by the interpreter
to choose the error message.
</td></tr>
<tr class="dark"><td valign="top">
<tt><b>seek</b></tt>
</td><td valign="top">
Seeks into the <a href="../../def/stream+en">stream</a>.
<ul>
<li><u>pos</u> is the position inside the <a href="../../def/stream+en">stream</a>.
<li><u>whence</u> is one the following constants:
<ul>
<li><tt><a href="../../lang/seek+en">SEEK</a>_SET</tt>, to indicate that <u>pos</u> is an absolute position.
<li><tt><a href="../../lang/seek+en">SEEK</a>_CUR</tt>, to indicate that <u>pos</u> is an offset to the current position.
<li><tt><a href="../../lang/seek+en">SEEK</a>_<a href="../../lang/end+en">END</a></tt>, to indicate that <u>pos</u> is an offset from the end of the <a href="../../def/stream+en">stream</a>.
</ul>
</ul>

</td><td valign="top">
<tt>TRUE</tt> if seeking is impossible, and <tt>FALSE</tt> if everything is OK.
</td></tr>
<tr><td valign="top">
<tt><b>tell</b></tt>
</td><td valign="top">
Returns the current <a href="../../def/stream+en">stream</a> position in <u>pos</u>.
</td><td valign="top">
<tt>TRUE</tt> if seeking is impossible, and <tt>FALSE</tt> if everything is OK.
</td></tr>
<tr class="dark"><td valign="top">
<tt><b>flush</b></tt>
</td><td valign="top">
Flushes the <a href="../../def/stream+en">stream</a>.
</td><td valign="top">
<tt>TRUE</tt> if there was an error, and <tt>FALSE</tt> if everything is OK.
<p>
If flushing has no sense for your <a href="../../def/stream+en">stream</a>, then you must return <tt>FALSE</tt>.
</td></tr>
<tr><td valign="top">
<tt><b>eof</b></tt>
</td><td valign="top">
Checks the end of the <a href="../../def/stream+en">stream</a>.
</td><td valign="top">
<tt>TRUE</tt> if the end of the <a href="../../def/stream+en">stream</a> is reached, <tt>FALSE</tt> otherwise.
</td></tr>
<tr class="dark"><td valign="top">
<tt><b>lof</b></tt>
</td><td valign="top">
Returns in <u>len</u> the length of the <a href="../../def/stream+en">stream</a>.
<p>
If this has no sense for your <a href="../../def/stream+en">stream</a>, and if the <tt><b>handle</b></tt> function returns a
system file descriptor, you can let the interpreter returns the maximum number
of bytes that can be read on the <a href="../../def/stream+en">stream</a> for you, by putting <tt>0</tt> in <u>len</u>.
</td><td valign="top">
<tt>FALSE</tt>.
</td></tr>
<tr><td valign="top">
<tt><b>handle</b></tt>
</td><td valign="top">
Returns the underlying system file descriptor.
</td><td valign="top">
The underlying system file descriptor.
</td></tr>
</table>
<p>
<hr><b>See also</b><br>
<a href="../cat/stream+en">Stream Management</a>&nbsp;

</div>
</body>
</html>

