send
send copied to clipboard
Avoid race condition by using fs.open and fs.fstat, also allow file descriptor to be passed
Adds two new options:
-
fd
- If specified, send will ignore thepath
argument and will use the specified file descriptor. This means that no'open'
event will be emitted. -
autoClose
- Iffalse
, then the file descriptor won't be closed, even if there's an error. It is your responsibility to close it and make sure there's no file descriptor leak. If set totrue
(default behavior), onerror
orend
the file descriptor will be closed automatically.
It also uses fs.open
, fs.fstat
and passes the file descriptor to fs.createReadStream
to ensure there is no race condition where the the file located at the specified path
is unlinked, renamed, or replaced in between the current calls to fs.stat
and fs.createReadStream
which would result in an incorrect response.
I've also renamed onStatError
to onFileSystemError
to more accurately reflect what types of errors it is responsible for handling.
Resolves #122 Resolves #123