fs.truncate accepts an fd but it's poorly documented #15753
Labels
fs
Issues and PRs related to the fs subsystem / file system.
good first issue
Issues that are suitable for first-time contributors.
As I just found out from #15409, you can call
fs.truncate
with anfd
:But this behavior is surprising, since there's
fs.ftruncate
forfd
s and it's easy to overlook the note in the documentation forfs.truncate
.Options:
fs.truncate
to make it more obvious that it also takesfd
s. For instance,path <string> | <Buffer>
needs to be replaced with something likepathOrFd <string> | <Buffer> | <number>
, andAsynchronous truncate(2).
needs to be replaced with something likeAsynchronous truncate(2) or ftruncate(2) depending on the argument
.fd
support infs.truncate
. This would be my preference, since it would avoid having two functions that can do the same thing, and it would make code such asfs.truncate(f)
more readable because it would be obvious thatf
is a path and not anfd
.The text was updated successfully, but these errors were encountered: