Last active
December 21, 2015 01:08
-
-
Save jackfranklin/6225121 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// I have this code for downloading a URL to a file | |
var stream = request(url).pipe(fs.createWriteStream(fileDestination)) | |
// I can bind to "close" for when the file is completely downloaded, which works fine | |
stream.on("close", function() {...}); | |
// is there an event I can bind to that will be fired whenever data is receieved (so not that the file is 100% done, but that a bit more of the file has been downloaded? | |
stream.on("???", function() {...}); | |
// use case: showing a progress bar of downloading the file | |
// I was lead to believe I wanted the "data" event, but this doesn't work and I never see the message: | |
stream.on("data", function() { process.stdout.write("hey"); }); //no work :( |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@PhUU got i!
the process of piping the stream swallows up all events. So you have to save the stream before piping:
Works like a dream.