TStream
Data stream type
TStream extends TIO to provide methods for reading and writing various types of values to and from a stream.
Note that methods dealing with strings - ReadLine, WriteLine, ReadString and WriteString - assume that strings are represented by bytes in the stream. In future, a more powerful TextStream type will be added capable of decoding text streams in multiple formats.
Methods
Method ReadBytes:Long( buf:Byte Ptr,count:Long )
Reads bytes from a stream
ReadBytes reads count bytes from the stream into the memory block specified by buf.
If count bytes were not successfully read, a TStreamReadException is thrown. This typically occurs due to end of file.
Method WriteBytes:Long( buf:Byte Ptr,count:Long )
Writes bytes to a stream
WriteBytes writes count bytes from the memory block specified by buf to the stream.
If count bytes were not successfully written, a TStreamWriteException is thrown. This typically occurs due to end of file.
Method SkipBytes:Long( count:Long )
Skip bytes in a stream
SkipBytes read count bytes from the stream and throws them away.
If count bytes were not successfully read, a TStreamReadException is thrown. This typically occurs due to end of file.
Method ReadByte:Int()
Read a byte from the stream
If a value could not be read (possibly due to end of file), a TStreamReadException is thrown.
Returns
The read value
Method WriteByte( n:Int )
Write a byte to the stream
If the value could not be written (possibly due to end of file), a TStreamWriteException is thrown.
Method ReadShort:Int()
Read a short (two bytes) from the stream
If a value could not be read (possibly due to end of file), a TStreamReadException is thrown.
Returns
The read value
Method WriteShort( n:Int )
Write a short (two bytes) to the stream
If the value could not be written (possibly due to end of file), a TStreamWriteException is thrown.
Method ReadInt:Int()
Read an int (four bytes) from the stream
If a value could not be read (possibly due to end of file), a TStreamReadException is thrown.
Returns
The read value
Method WriteInt( n:Int )
Write an int (four bytes) to the stream
If the value could not be written (possibly due to end of file), a TStreamWriteException is thrown.
Method ReadLong:Long()
Read a long (eight bytes) from the stream
If a value could not be read (possibly due to end of file), a TStreamReadException is thrown.
Returns
The read value
Method WriteLong( n:Long )
Write a long (eight bytes) to the stream
If the value could not be written (possibly due to end of file), a TStreamWriteException is thrown.
Method ReadFloat#()
Read a float (four bytes) from the stream
If a value could not be read (possibly due to end of file), a TStreamReadException is thrown.
Returns
The read value
Method WriteFloat( n# )
Write a float (four bytes) to the stream
If the value could not be written (possibly due to end of file), a TStreamWriteException is thrown.
Method ReadDouble!()
Read a double (eight bytes) from the stream
If a value could not be read (possibly due to end of file), a TStreamReadException is thrown.
Returns
The read value
Method WriteDouble( n! )
Write a double (eight bytes) to the stream
If the value could not be written (possibly due to end of file), a TStreamWriteException is thrown.
Method ReadLine$()
Read a line of text from the stream
Bytes are read from the stream until a newline character (ascii code 10) or null character (ascii code 0) is read, or end of file is detected.
Carriage return characters (ascii code 13) are silently ignored.
The bytes read are returned in the form of a string, excluding any terminating newline or null character.
Method WriteLine:Int( str$ )
Write a line of text to the stream
A sequence of bytes is written to the stream (one for each character in str) followed by the line terminating sequence "rn".
Returns
True if line successfully written, else False
Method ReadString$( length:Int )
Read characters from the stream
A TStreamReadException is thrown if not all bytes could be read.
Returns
A string composed of length bytes read from the stream
Method WriteString( str$ )
Write characters to the stream
A TStreamWriteException is thrown if not all bytes could be written.