Skip to content

Provide methods for checking if an object is FileHandle (node:fs) #61637

@JustappleJust

Description

@JustappleJust

What is the problem this feature will solve?

Sometimes, package developers want to allow users to specify a file path, fd (a number), or FileHandle as a single parameter for file operations. Unfortunately, there isn’t a reliable method for developers to check if an instance of the FileHandle class is provided. By implementing this feature, developers can easily and consistently check for the presence of a FileHandle instance.

What is the feature you are proposing to solve the problem?

I propose adding the following methods to the support:

  1. Make the FileHandle class accessible from fs.FileHandle or fs.promises.FileHandle, allowing developers to check directly with instanceof.
  2. Implement a static method FileHandle.isFileHandle(), similar to what Buffer does.
  3. If feasible, provide a method in FileHandle(fd) or FileHandle.from(fd) to convert a fd number into a FileHandle.

What alternatives have you considered?

Checking the object’s methods and properties directly is not a smart approach. Obtaining the FileHandle class by opening any file is slow.

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues that request new features to be added to Node.js.

    Type

    No type

    Projects

    Status

    Awaiting Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions