Stream values are a complex type, which refer to a read/write stream. Streams are a very convenient way of performing formatted input and output.
Examples of streams include buffer streams attached to text values, file streams attached to disk files, and pipe streams attached to operating system pipes. There are a wide variety of functions related to streams:
• BuffStream, FileStream, and PipeStream create stream values;
• GetStreamLength and GetStreamType return the length and type indication for a stream (respectively),
• ModemStream opens a serial stream on a modem,
• PeekStream returns a string of bytes from a stream without removing them from the stream, PipeStream returns a stream based on an operating system named pipe,
• SerialStream returns a serial stream that can be used in any of the serial port functions or with any of the stream functions,
• ShiftStream inserts or deletes characters from a stream,
• SpeechStream opens a SAPI text-to-speech stream and returns a handle to it,
• SRead and SWrite perform formatted reads and writes from streams (respectively);
• StreamEnd returns an indication as to whether or not a stream is at the end,
• TempFileStream connects a stream to a temporary file, and
• CloseStream closes a stream.
The SRead and SWrite functions perform formatted reads and writes from streams. These functions don't need to know what type of stream they use - a module could be designed to perform a database record write by writing to a stream. It could be tested on a local file stream, and later connected to an operating system pipe to a network server.
Most streams contain a position pointer that indicates where in the stream the next read or write will take place. This pointer is automatically positioned after a read or write to the stream and may be positioned by the Seek function, which also returns the current position in characters from the beginning of the stream.
Streams also offer faster file access than FRead and FWrite which open and close the file after every access, because a stream leaves a file open. The downside is that if the computer is shut off or loses power before a CloseStream closes the file stream, the opened file will be corrupted.