Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/RTL/Delphi/File Management    [ Add a report in this area ]  
Report #:  65522   Status: Closed
TMemoryStream.LoadFromFile throws "Stream read error"
Project:  Delphi Build #:  11.0.2902.10471
Version:    11.2 Submitted By:   Yahoo Serious
Report Type:  Basic functionality failure Date Reported:  8/11/2008 6:12:22 AM
Severity:    Extreme corner case Last Updated: 3/20/2012 2:24:39 AM
Platform:    All versions Internal Tracking #:   263933
Resolution: Fixed (Resolution Comments) Resolved in Build: : 15.0.3577.25507
Duplicate of:  None
Voting and Rating
Overall Rating: No Ratings Yet
0.00 out of 5
Total Votes: None
I encountered a "Stream read error" using TMemoryStream.LoadFromFile. It was non-deterministic (sometimes it was thrown, sometimes it wasn't.)

Some searching led me to a newsgroup-message:
Re: Help! Stream-Read-Error on TMemoryStream.LoadFromFile
Remy Lebeau (TeamB) [Jun 3 2004, 19:34]

Where Gambit explains:
"if it [TMemoryStream] doesn't read the full data in one try, it throws an exception."

I think this asks for a better error description than "Stream read error", e.g. mentioning the file and/or the file size.
Besides, I think this would call for better handling, e.g. using TMemoryStream.CopyFrom like Gambit suggests.
Steps to Reproduce:
Use TMemoryStream.LoadFromFile with a large file (mine is appr. 94 MB)
Use TFileStream.LoadFromFile and TMemoryStream.CopyFrom(TFileStream) like Gambit suggests?


Server Response from: ETNACODE01