send icon indicating copy to clipboard operation
send copied to clipboard

Avoid race condition by using fs.open and fs.fstat, also allow file descriptor to be passed

Open jcready opened this issue 8 years ago • 0 comments

Adds two new options:

  1. fd - If specified, send will ignore the path argument and will use the specified file descriptor. This means that no 'open' event will be emitted.
  2. autoClose - If false, 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 to true (default behavior), on error or end 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

jcready avatar Dec 17 '16 18:12 jcready