fs-maybe-open
Open a file unless it's already a file descriptor.
usage
const maybeOpen = fs = { }
The maybeOpen
function has the same signature as fs.open(path, flags[, mode], callback)
. Except:
- If
path
is a file descriptor, opening is a noop - The open
callback
also receives amaybeClose(callback, err, ...args)
function, which callsfs.close
for you ifpath
was a filename. An error fromfs.close
(if any) will be combined with your error (if any).
install
With npm do:
npm install fs-maybe-open
license
MIT © Vincent Weevers