Internet Direct (Indy)
Home
PreviousUpNext
TIdIOHandler.ReadStream Method

Reads data from the IOHandler into a stream.

Pascal
procedure ReadStream(
    AStream: TIdStream; 
    AByteCount: Int64 = -1; 
    AReadUntilDisconnect: Boolean = False
); virtual;
Parameters 
Description 
AStream 
Stream used to store
 
AByteCount 
Type is Int64. Default value is -1.
 
AReadUntilDisconnect 
Type is Boolean. Default value is False. 

ReadStream is a method used to read data from the IOHandler into the stream instance specified in AStream. An EAssertionFailed exception will be raised if AStream is unassigned. 

AByteCount indicates the number of bytes of data to read using the IOHandler, and to store in the stream instance in AStream. 

When AByteCount contains the value cSizeUnknown, the amount of data to read from the IOHandler is determined either by reading the byte count from the IOHandler or by reading data until the connection is closed by the peer. 

When AReadUntilDisconnect contains False, the byte count is read from the IOHandler. The byte count will be an Integer data type when LargeStream contains False, or an Int64 value when LargeStream contains True. This allows the Indy library to maintain compatibility with older VCL versions where stream sizes and positions are not returned as Int64 data types. The byte count (from the argument or read from the IOHandler) is used to pre-allocate the stream size. 

When AReadUntilDisconnect contains True, ReadStream expects the connection for the IOHandler to be closed when no more data is available for the method. 

ReadStream signals the OnWorkBegin, OnWork, and OnWorkEnd event handlers when reading values from the IOHandler. The expected number of bytes for OnWorkBegin is an arbitrarily large value when AReadUntilDisconnect contains True, and will not reflect the actual number of bytes read from the IOHandler. The OnWork event handler is signalled when byte values are extracted and removed from InputBuffer, and not when they are added. 

ReadStream always consumes data from the internal buffer for the IOHandler. Any exisiting data in InputBuffer is used before reading additional data using the ReadFromSource method. The value in RecvBufferSize is used to allocate a TIdBytes buffer that stores data extracted from the InputBuffer and written to the stream instance in AStream. 

ReadStream iteratively calls ReadBytes to extract values from InputBuffer until the expected number of bytes has been read and written to AStream, or until the IOHandler is no longer Connected

If an exception occurs while reading bytes from the IOHandler, any existing data in the InputBuffer is extacted and written to the stream. An EIdConnClosedGracefully is ignored when AReadUntilDisconnect contains true. Use the ClosedGracefully property to determine when the connection for the IOHandler has been closed by the peer. 

Any other exception occurring in the method is re-raised to allow the application to detect the error condition. 

ReadFromStream ensures that the size of the stream in AStream is adjusted to reflect the actual amount of data read from the IOHandler before exiting from the method.

Exceptions 
Description 
EAssertionFailed 
Raised when the stream for the operation is unassigned.
 
Raised for other error conditions during the operation. 
Internet Direct (Indy) version 10.1.5
Copyright © 1993-2006, Chad Z. Hower (aka Kudzu) and the Indy Pit Crew. All rights reserved.
Website http://www.indyproject.org.
Post feedback to the Indy Documentation newsgroup.