Fix response.body.getReader compatibility with node-fetch
Issue
When using this library with node-fetch instead of native fetch, it would fail with an error: response.body.getReader is not a function. This is because node-fetch doesn't implement the Web Streams API in the same way as native fetch.
Solution
This PR adds support for both implementations:
- It checks if
response.body.getReader()is available (native fetch) - If available, it uses the existing implementation with
getReader() - If not available, it falls back to a Node.js stream implementation using event listeners
The implementation maintains identical timeout and error handling behaviors between both approaches.
Changes
- Added a check for
response.body.getReaderavailability - Added a new
processNodeStreamfunction for node-fetch compatible streams - Updated documentation to clarify compatibility with both fetch implementations
- Added a simple compatibility test
This change enables the library to work with both Node.js 18+ (with native fetch) and older Node.js versions using node-fetch as a fallback without any code changes required by the user.
Fixes #6.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.