Closed stirlingstout closed 2 weeks ago
Fixed
On further reflection, I think that having two methods makes things more confusing because, if you are at the start of the file readToEnd
and readAll
are the same (so lots of 'Which one should I use, Sir?' followed by 'Why?'). Also the need for the (revised) readToEnd
is pretty rare - and you can easily do it as a loop yourself in Elan if needed.
So I will reduce the read...
methods back to just:
readLine()
readWholeFile()
Also, for symmetry, I am adding writeWholeFile
- in both cases this automatically closes the file.
Looking at the source for
text-reader
it looked as though thereadToEnd
function doesn't, but does more areadAll
, and testing confirms this.So
var f set to openFileForReading()
var line set to f.readLine()
print line
set line to f.readLine()
print line
let rest to f.readToEnd()
print rest
call f.close()
prints the first line of the file, the second line of the file, then all of the file including the first and second lines.
I think it's unlikely you'd ever want to do this, but it is possible, and I think the mismatch between name and implementation is the major problem.
Suggestions:
readToEnd
start at thecurrentLine
until the end of the file's contents and do the join. This would make the behavior match the name and callingreadToEnd
on a just opened file does the same as areadAll
readToEnd
toreadAll
and add areadToEnd
that does just read from the current position to the end of the file.Incidentally the test above demonstrates the issue about line terminators mentioned in #833 since it prints the first two lines with both a terminator from the string being printed and the terminator from
print
: