Re: KI_FILE count precondition
Eric Bezault <ericb-D6Qt/9opevxWk0Htik3J/[email protected]>
| Newsgroups | gmane.comp.lang.eiffel.gobo.general |
|---|---|
| Message-ID | <[email protected]> |
Bernd Schoeller wrote: > On Thu, 18 Jan 2007 17:30:19 +0100, Eric Bezault <ericb-D6Qt/9opevxWk0Htik3J/[email protected]> > wrote: > >> Bernd Schoeller wrote: >>> Can anybody motivate for me the reason of the 'is_closed' precondition >>> in >>> KI_FILE? >> If the file is not closed, then we might be writing >> to it. The new characters may still be in the buffer >> or already on disk. What does `count' means in that >> case? > > Well - on an open file, the count should be exactly what is visible > through the open file handle. What do you mean by "visible" if the file is write-only? > The code in question reads the content of file into a string, a common > task that should be reasonably easy to implement. > > Currently, it looks as follows: > > file.reset(filename) > filesize := file.count > file.open_read > if file.is_open_read then > file.read_string(filesize) > s := file.last_string > file.close > end If this code is in Gobo then it needs to be fixed. Indeed there is no guarantee that `read_string' will read `filesize' characters. It could well be implemented to read only one character even if the file is much bigger. So we need a loop until the end of file is reached. Therefore the value of `filesize' that you provide is arbitrary. Even more under Windows with the %R%N end-of-line. > This looks a little complex to me and still has problems. I am a little > afraid to just call > > file.read_string(Platform.Maximum_integer) > > as, looking at the implementation in KL_TEXT_INPUT_FILE, this might create > a buffer of that size. > > It would be best if there was a 'read_string(-1)' that would just read in > everything available. This -1 is very ugly. This might be common practice in other languages, but in Eiffel I would prefer to have a new feature `read_all' or `read_to_end' or something like that. Then I wonder whether this routine should write to `last_string' or to a string given as argument (like `read_to_string'). -- Eric Bezault mailto:ericb-D6Qt/9opevxWk0Htik3J/[email protected] http://www.gobosoft.com