fs: support special files in promises.readFile
A size of 0 may indicate that the file is a Linux special file, which may still have content when read()
. Instead of returning early, use the same approach as fs.readFile()
:
Additionally, only the return code of 0 indicates end of file, and we should not use bytesRead !== chunkSize
as a indication of EOF. Per POSIX:
The value returned may be less than nbyte if the number of bytes left in the file is less than nbyte, if the read() request was interrupted by a signal, or if the file is a pipe or FIFO or special file and has fewer than nbyte bytes immediately available for reading. For example, a read() from a file associated with a terminal may return one typed line of data.
Refs: http://pubs.opengroup.org/onlinepubs/9699919799/functions/read.html Refs: https://groups.google.com/forum/#!topic/nodejs-dev/rxZ_RoH1Gn0 Fixes: https://github.com/nodejs/node/issues/21331
Checklist
-
make -j4 test
(UNIX), orvcbuild test
(Windows) passes -
tests and/or benchmarks are included -
commit message follows commit guidelines