Closed rizo closed 5 years ago
This is now ready for review, @dbuenzli.
As discussed in #78, the read function decides how to input the file by checking the length with lseek
and catching ESPIPE
.
Thanks your patch is in as 61526bf67f218fd730db8ac1914994
This adds support for reading the content of character devices and named pipes with
Bos.OS.File.read
. Of course, feel free to make any changes you see necessary, or reject entirely.Note that currently
Bos.OS.File.read_lines
already supports those files (indirectly viaPervasives.input_line
), so this would makeBos.OS.File.read
consistent with that behaviour.There's an obvious risk of a potential memory leak in case someone uses a device that does not terminate (i.e.
/dev/random
ormkfifo pipe; yes > pipe
). But I think this is generally understandable.The implementation relies onUnix.stat
to obtain the file kind. It's called twice (when the file is opened and when it's closed). This (neglectable?) cost could be avoided, but I didn't want to change the code too much.