I might be wrong, but this assert appears misguided to me.
(* Current implementation of Eio.File.pread: *)
let pread (t : #ro) ~file_offset bufs =
let got = t#pread ~file_offset bufs in
assert (got > 0 && got <= Cstruct.lenv bufs);
got
Imagine I'm reading a file slice by slice, using successive calls to Eio.File.pread.
When I reach the end of the file (i.e. when I pass a ~file_offset equal to the number of bytes in the file), Eio.File.pread returns a length of 0 and thus the assert fails.
It appears to me that the author expected t#pread to raise End_of_file to indicate EOF.
Either the Eio_posix implementation of Eio.File.ro#pread needs to raise End_of_file, or the assertion should be
assert (got <= Cstruct.lenv bufs);
I might be wrong here! but at the moment I'm having to circumvent Eio.File.pread by making direct calls to t#pread.
Yes, eio_posix needs to change (#581). The assert is here precisely to make sure that all the backends behave the same way (eio_linux already raises End_of_file here).
I might be wrong, but this assert appears misguided to me.
Imagine I'm reading a file slice by slice, using successive calls to
Eio.File.pread
.When I reach the end of the file (i.e. when I pass a
~file_offset
equal to the number of bytes in the file),Eio.File.pread
returns a length of0
and thus theassert
fails.It appears to me that the author expected
t#pread
to raiseEnd_of_file
to indicate EOF.Either the
Eio_posix
implementation ofEio.File.ro#pread
needs to raiseEnd_of_file
, or the assertion should beI might be wrong here! but at the moment I'm having to circumvent
Eio.File.pread
by making direct calls tot#pread
.