imho ReadBuffer/WriteBuffer are over-engineered. They appear to be implemented to code around potential bugs (or perhaps an idiosyncrasy) in a stream implementation.<br><br>If I ask a stream to read/write N bytes then that is what the stream should do. If it needs to break the request into smaller "chunks" to satisfy the request then that should be transparent to the consumer code.<br>
<br>I would call this "chunking" rather than "buffered". Buffered read/write I/IO typically works on blocks LARGER than the individual requests, not smaller. i.e. you ask to read 4 bytes but a larger buffer of (e.g.) 1KB is read so that future requests can be satisfied from the buffer, and asking to write 4 bytes just stuffs a buffer which is only *actually* written when then buffer is full, both designed to minimise I/O.<br>
<br>"Chunking" does the opposite.<br><div><br><br><br><div class="gmail_quote">On 30 June 2012 21:54, Todd Martin <span dir="ltr"><<a href="mailto:todd.martin.nz@gmail.com" target="_blank">todd.martin.nz@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">TStrings.SaveToStream calls Stream.WriteBuffer()<br>
whereas<br>
TStrings.LoadFromStream calls Stream.Read()<br>
<br>
No buffering and no error message, if the buffer is not read in completely!<br>
<br>
procedure TStrings.SaveToStream(Stream: TStream; Encoding: TEncoding);<br>
var<br>
Buffer, Preamble: TBytes;<br>
begin<br>
if Encoding = nil then<br>
Encoding := FDefaultEncoding;<br>
Buffer := Encoding.GetBytes(GetTextStr);<br>
if FWriteBOM then<br>
begin<br>
Preamble := Encoding.GetPreamble;<br>
if Length(Preamble) > 0 then<br>
Stream.WriteBuffer(Preamble[0], Length(Preamble));<br>
end;<br>
Stream.WriteBuffer(Buffer[0], Length(Buffer));<br>
end;<br>
<br>
<br>
procedure TStrings.LoadFromStream(Stream: TStream; Encoding: TEncoding);<br>
var<br>
Size, PreambleSize: Integer;<br>
Buffer: TBytes;<br>
begin<br>
BeginUpdate;<br>
try<br>
Size := Stream.Size - Stream.Position;<br>
SetLength(Buffer, Size);<br>
Stream.Read(Buffer[0], Size);<br>
PreambleSize:= TEncoding.GetBufferEncoding(Buffer, Encoding,<br>
FDefaultEncoding);<br>
SetEncoding(Encoding); // Keep Encoding in case the stream is saved<br>
SetTextStr(Encoding.GetString(Buffer, PreambleSize, Length(Buffer) -<br>
PreambleSize));<br>
finally<br>
EndUpdate;<br>
end;<br>
end;<br>
<br>
<br>
_______________________________________________<br>
NZ Borland Developers Group - Delphi mailing list<br>
Post: <a href="mailto:delphi@listserver.123.net.nz">delphi@listserver.123.net.nz</a><br>
Admin: <a href="http://delphi.org.nz/mailman/listinfo/delphi" target="_blank">http://delphi.org.nz/mailman/listinfo/delphi</a><br>
Unsubscribe: send an email to <a href="mailto:delphi-request@listserver.123.net.nz">delphi-request@listserver.123.net.nz</a> with Subject: unsubscribe<br>
</blockquote></div><br></div>