Skip to content
Advertisement

Stream response to file using Fetch API and fs.createWriteStream

I’m creating an Electron application and I want to stream an image to a file (so basically download it).

I want to use the native Fetch API because the request module would be a big overhead.

But there is no pipe method on the response, so I can’t do something like

JavaScript

So how can I combine fetch and fs.createWriteStream?

Advertisement

Answer

I got it working. I made a function which transforms the response into a readable stream.

JavaScript

So with it, I can do

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement