Delphi Datasnap Stream delivers big data
It is convenient for Datasnap to pass and return the parameters of the Tstream type directly. But a lot of people find that it's not normal to work if it's a little bit bigger.
Datasnap the default cache size is 32k so if the size of the stream exceeds this size it will be automatically divided into multiple packages, which is the basis for the delivery of large amounts of data, if a one-time transmission may be limited by memory.
When you pass a large amount of data, the size obtained is-1, so it is problematic to read the stream's data in a general way.
Because the data of the stream is sent by the original packet, the delivery speed is not much different from other methods without encrypting the packet.
FS is a file stream
function Tmydsserver.putfile (stream:tstream): Boolean;
Const
BufSize = $F 000;
Var
Buffer:tbytes;
Readcount:integer;
Begin
If stream.size = 1 then//size unknown then read until no data
Begin
SetLength (Buffer, BufSize);
Repeat
Readcount: = Stream.read (buffer[0], BufSize);
If Readcount > 0 Then
Fs. WriteBuffer (Buffer[0], readcount);
If Readcount < BufSize Then
Break
Until Readcount < BufSize;
End
else//size is known to copy data directly
Fs. CopyFrom (Stream, 0);
Result: = True;
End
Delphi Datasnap Stream delivers big data