<p id="mathjaxlink" class="pcenter"><a href="chap10.html">[MathJax off]</a></p>
<p><a id="X7EADF566874177D8" name="X7EADF566874177D8"></a></p>
<div class="ChapSects"><a href="chap10_mj.html#X7EADF566874177D8">10 <span class="Heading">Examples of usage</span></a>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap10_mj.html#X7EC25CA68794860A">10.1 <span class="Heading">Writing and reading a file</span></a>
</span>
</div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap10_mj.html#X7AECE665813D6E4D">10.2 <span class="Heading">Using filtering programs to read and write files</span></a>
</span>
</div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap10_mj.html#X7A8A180D7B335151">10.3 <span class="Heading">Using filters when reading or writing files sequentially</span></a>
</span>
</div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap10_mj.html#X7BD2BF7F87573C69">10.4 <span class="Heading">Accessing a web page</span></a>
</span>
</div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap10_mj.html#X81BD8400832EE20B">10.5 <span class="Heading">(Un-)Pickling</span></a>
</span>
</div>
</div>
<h3>10 <span class="Heading">Examples of usage</span></h3>
<p>For larger examples see the <code class="file">example</code> directory of the package. You find there a small server using the TCP/IP protocol and a corresponding client and another small server using the UDP protocol and a corresponding client.</p>
<p>Further, there is an example for the usage of <code class="code">File</code> objects, that read from or write to strings.</p>
<p>Another example there shows starting up a child process and piping a few megabytes through it using <code class="func">IO_Popen2</code> (<a href="chap4_mj.html#X7E05CF6481CBC0A1"><span class="RefLink">4.4-4</span></a>).</p>
<p>In the following, we present a few explicit, interactive short examples for the usage of the functions in this package. Note that you have to load the <strong class="pkg">IO</strong> package with the command <code class="code">LoadPackage("IO");</code> before trying these examples.</p>
<p>There is nothing special about this, the numbers are numbers of bytes written. Note that only after the <code class="func">IO_Flush</code> (<a href="chap4_mj.html#X7873A49F7CC7ECFB"><span class="RefLink">4.2-10</span></a>) command the data is actually written to disk. Before that, it resides in the write buffer of the file. Note further, that the <code class="func">IO_Flush</code> (<a href="chap4_mj.html#X7873A49F7CC7ECFB"><span class="RefLink">4.2-10</span></a>) call here would not have been necessary, since the <code class="func">IO_Close</code> (<a href="chap4_mj.html#X820DA9C97C2E80BA"><span class="RefLink">4.2-16</span></a>) call flushes the buffer anyway.</p>
<p>The file can again be read with the following sequence of commands:</p>
<p>Note here that reading line-wise can only be done efficiently by using buffered I/O. You can mix calls to <code class="func">IO_Read</code> (<a href="chap4_mj.html#X84F3D862836BF17C"><span class="RefLink">4.2-6</span></a>) and to <code class="func">IO_ReadLine</code> (<a href="chap4_mj.html#X8738708E7B9DF8DB"><span class="RefLink">4.2-3</span></a>). The end of file is indicated by an empty string returned by one of the read functions.</p>
<h4>10.2 <span class="Heading">Using filtering programs to read and write files</span></h4>
<p>If you want to write a big amount of data to file you might want to compress it on the fly without using much disk space. This can be achieved with the following command:</p>
<h4>10.3 <span class="Heading">Using filters when reading or writing files sequentially</span></h4>
<p>If you want to process bigger amounts of data you might not want to store all of it in a single <strong class="pkg">GAP</strong> string. In that case you might want to access a file on disk sequentially through a filter:</p>
<h4>10.4 <span class="Heading">Accessing a web page</span></h4>
<p>The <strong class="pkg">IO</strong> package has an HTTP client implementation. Using this you can access web pages and other web downloads from within <strong class="pkg">GAP</strong>. Here is an example:</p>
<p>Note that this works for a certain amount of builtin objects. If you want to archive your own objects or more sophisticated objects you have to use extend the functionality as explained in Section <a href="chap5_mj.html#X7B1C9A9C7D3C0312"><span class="RefLink">5.3</span></a>. However, it works for lists and records and they may be arbitrarily self-referential.</p>
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.