Skip to content

fs: support special files in promises.readFile

Rodrigo Muino Tomonari requested to merge github/fork/TimothyGu/fs-promise into master

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():

https://github.com/nodejs/node/blob/6ced651b6c3da64727bce260ecf55b8d86ec6cc3/lib/internal/fs/read_file_context.js#L74-L88

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), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines

Merge request reports

Loading