Skip to content

fs: add windowsHandle option to file streams#63851

Open
PickBas wants to merge 2 commits into
nodejs:mainfrom
JaneaSystems:win-pipe-handle
Open

fs: add windowsHandle option to file streams#63851
PickBas wants to merge 2 commits into
nodejs:mainfrom
JaneaSystems:win-pipe-handle

Conversation

@PickBas

@PickBas PickBas commented Jun 11, 2026

Copy link
Copy Markdown

On Windows, a value passed as fd to fs.createReadStream() / fs.createWriteStream() is treated as a CRT file descriptor. When the value is actually a raw Win32 HANDLE, for example an inherited anonymous pipe handle received from another process, it fails with EBADF, since libuv operates on CRT file descriptors.

This adds a windowsHandle option to both stream constructors that wraps the HANDLE in a CRT file descriptor via _open_osfhandle(), so the stream can read from or write to it normally.

Fixes: #57288

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/gyp

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. fs Issues and PRs related to the fs subsystem / file system. needs-ci PRs that need a full CI run. labels Jun 11, 2026
Fixes: nodejs#57288
Signed-off-by: PickBas <sayed.kirill@gmail.com>
@PickBas PickBas marked this pull request as ready for review June 11, 2026 13:53
Comment thread src/node_file.cc Outdated
}

intptr_t value =
static_cast<intptr_t>(args[0].As<Number>()->Value());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no inherent guarantee that a value that can be represented as an intptr_t or HANDLE can also be represented losslessly as a JS number – if there is some Windows-specific additional guarantee I'm not aware of, it would be very helpful to add a comment about that here, and otherwise, it would probably be a good idea to just use JS bigint instead

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using bigint now, thank you

Signed-off-by: PickBas <sayed.kirill@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. fs Issues and PRs related to the fs subsystem / file system. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows anonymous pipes do not work with createReadStream

3 participants