Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion doc/api/fs.md
Original file line number Diff line number Diff line change
Expand Up @@ -1617,10 +1617,13 @@ This is the synchronous version of [`fs.chown()`][].

See also: chown(2).

## `fs.close(fd, callback)`
## `fs.close(fd[, callback])`
<!-- YAML
added: v0.0.2
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/00000
Comment thread
jasnell marked this conversation as resolved.
Outdated
description: A default callback is now use if one is not provided.
Comment thread
jasnell marked this conversation as resolved.
Outdated
- version: v10.0.0
pr-url: https://github.com/nodejs/node/pull/12562
description: The `callback` parameter is no longer optional. Not passing
Expand All @@ -1641,6 +1644,9 @@ to the completion callback.
Calling `fs.close()` on any file descriptor (`fd`) that is currently in use
through any other `fs` operation may lead to undefined behavior.

If the `callback` argument is omitted, a default callback function that rethrows
any error as an uncaught exception will be used.

## `fs.closeSync(fd)`
<!-- YAML
added: v0.1.21
Expand Down
6 changes: 5 additions & 1 deletion lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,11 @@ function readFileSync(path, options) {
return buffer;
}

function close(fd, callback) {
function defaultCloseCallback(err) {
if (err != null) throw err;
}

function close(fd, callback = defaultCloseCallback) {
validateInt32(fd, 'fd', 0);
callback = makeCallback(callback);
Comment thread
jasnell marked this conversation as resolved.
Outdated

Expand Down