[erlang-questions] Package Support/Use

Richard Carlsson richardc@REDACTED
Fri Nov 10 10:36:04 CET 2006

Richard A. O'Keefe wrote:
> For random reading we have
>     file:pread(Device, Location, Count) -> {ok,Data} | {error,Reason}
> As usual, the documentation could stand some work.

It certainly does. The docs also claim that, for pread/3:

     Data = [char()] | binary() | eof

which is bogus. There has been some confusion with the function
pread/2 in the documentation. For pread/3, it should say that:

file:pread(Device, Location, Count) -> {ok,Data} | eof | {error,Reason}
     Data = [char()] | binary()

A quick experiment furthermore indicates that:

     - if Location is beyond the last byte of the file,
       file:pread/3 returns 'eof' (documented for pread/2,
       but not for pread/3)

     - if Count is 0, pread/3 returns 'eof' (weird and undocumented)
       while read/2 returns an empty list if Count is 0.

     - if less than Count bytes can be read, pread/3 silently
       truncates the result (this is only documented for read/2),
       as long as the starting position is legal

Even if pread/3 was cleaned up a bit, I'd also like to have a
function that does not combine seek and read (the part of the
program that does the seek might not be the same as that which
does the read), and that always reports an error if not enough
bytes can be read.


More information about the erlang-questions mailing list