10 Streams

Streams provide flexible access to GAP's input and output processing. An input stream takes characters from some source and delivers them to GAP which reads them from the stream. When an input stream has delivered all characters it is at end-of-stream. An output stream receives characters from GAP which writes them to the stream, and delivers them to some destination.

A major use of streams is to provide efficient and flexible access to files. Files can be read and written using Read and AppendTo, however the former only allows a complete file to be read as GAP input and the latter imposes a high time penalty if many small pieces of output are written to a large file. Streams allow input files in other formats to be read and processed, and files to be built up efficiently from small pieces of output. Streams may also be used for other purposes, for example to read from and print to GAP strings, or to read input directly from the user.

Any stream is either a text stream, which translates the end-of-line character ('\n') to or from the system's representation of end-of-line (e.g., new-line under UNIX, carriage-return under MacOS, carriage-return-new-line under DOS), or a binary stream, which does not translate the end-of-line character. The processing of other unprintable characters by text streams is undefined. Binary streams pass them unchanged.

Note that binary streams are @not yet implemented@.

Whereas it is cheap to append to a stream, streams do consume system resources, and only a limited number can be open at any time, therefore it is necessary to close a stream as soon as possible using CloseStream described in Section CloseStream. If creating a stream failed then LastSystemError (see LastSystemError) can be used to get information about the failure.

Sections

  1. Categories for Streams and the StreamsFamily
  2. Operations applicable to All Streams
  3. Operations for Input Streams
  4. Operations for Output Streams
  5. File Streams
  6. User Streams
  7. String Streams
  8. Dummy Streams

[Top] [Previous] [Up] [Next] [Index]

GAP 4 manual
February 2000