TStream: Methods  


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

ReadBytesReads bytes from a stream
WriteBytesWrites bytes to a stream
SkipBytesSkip bytes in a stream
ReadByteRead a byte from the stream
WriteByteWrite a byte to the stream
ReadShortRead a short (two bytes) from the stream
WriteShortWrite a short (two bytes) to the stream
ReadIntRead an int (four bytes) from the stream
WriteIntWrite an int (four bytes) to the stream
ReadLongRead a long (eight bytes) from the stream
WriteLongWrite a long (eight bytes) to the stream
ReadFloatRead a float (four bytes) from the stream
WriteFloatWrite a float (four bytes) to the stream
ReadDoubleRead a double (eight bytes) from the stream
WriteDoubleWrite a double (eight bytes) to the stream
ReadLineRead a line of text from the stream
WriteLineWrite a line of text to the stream
ReadStringRead characters from the stream
WriteStringWrite characters to the stream

Method reference

Method ReadBytes( buf:Byte Ptr,count )
DescriptionReads bytes from a stream
Information 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( buf:Byte Ptr,count )
DescriptionWrites bytes to a stream
Information 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( count )
DescriptionSkip bytes in a stream
Information 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()
ReturnsThe read value
DescriptionRead a byte from the stream
Information If a value could not be read (possibly due to end of file), a TStreamReadException is thrown.

Method WriteByte( n )
DescriptionWrite a byte to the stream
Information If the value could not be written (possibly due to end of file), a TStreamWriteException is thrown.

Method ReadShort()
ReturnsThe read value
DescriptionRead a short (two bytes) from the stream
Information If a value could not be read (possibly due to end of file), a TStreamReadException is thrown.

Method WriteShort( n )
DescriptionWrite a short (two bytes) to the stream
Information If the value could not be written (possibly due to end of file), a TStreamWriteException is thrown.

Method ReadInt()
ReturnsThe read value
DescriptionRead an int (four bytes) from the stream
Information If a value could not be read (possibly due to end of file), a TStreamReadException is thrown.

Method WriteInt( n )
DescriptionWrite an int (four bytes) to the stream
Information If the value could not be written (possibly due to end of file), a TStreamWriteException is thrown.

Method ReadLong:Long()
ReturnsThe read value
DescriptionRead a long (eight bytes) from the stream
Information If a value could not be read (possibly due to end of file), a TStreamReadException is thrown.

Method WriteLong( n:Long )
DescriptionWrite a long (eight bytes) to the stream
Information If the value could not be written (possibly due to end of file), a TStreamWriteException is thrown.

Method ReadFloat#()
ReturnsThe read value
DescriptionRead a float (four bytes) from the stream
Information If a value could not be read (possibly due to end of file), a TStreamReadException is thrown.

Method WriteFloat( n# )
DescriptionWrite a float (four bytes) to the stream
Information If the value could not be written (possibly due to end of file), a TStreamWriteException is thrown.

Method ReadDouble!()
ReturnsThe read value
DescriptionRead a double (eight bytes) from the stream
Information If a value could not be read (possibly due to end of file), a TStreamReadException is thrown.

Method WriteDouble( n! )
DescriptionWrite a double (eight bytes) to the stream
Information If the value could not be written (possibly due to end of file), a TStreamWriteException is thrown.

Method ReadLine$()
DescriptionRead a line of text from the stream
Information 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( str$ )
ReturnsTrue if line successfully written, else False
DescriptionWrite a line of text to the stream
InformationA sequence of bytes is written to the stream (one for each character in str) followed by the line terminating sequence "rn".

Method ReadString$( length )
ReturnsA string composed of length bytes read from the stream
DescriptionRead characters from the stream
Information A TStreamReadException is thrown if not all bytes could be read.

Method WriteString( str$ )
DescriptionWrite characters to the stream
Information A TStreamWriteException is thrown if not all bytes could be written.