node-httpreq icon indicating copy to clipboard operation
node-httpreq copied to clipboard

Downloaded files can end truncated

Open manast opened this issue 4 years ago • 0 comments

The code here is incorrect since it is listening to the source stream "end" event which may trigger much sooner than the target stream has actually completed the writing to disk:

https://github.com/SamDecrock/node-httpreq/blob/c2dbc959ea8538ffcbb12c5a7e7e1b90abd7d5e0/lib/httpreq.js#L352

Instead you must listen to the "finish" event on the downloadStream, to make sure the file is completely stored and closed in disk. You may have not noticed this problem since as long as the process is still alive the file will eventually complete, but if the process closes before, you end with a truncated file. Use case: "electron-simple-updater" will close after downloading the latest version of an app and most likely end with a truncated file that will end with the end-user having a broken electron app.

manast avatar Nov 01 '21 04:11 manast