Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

[Feature] Progress event #8

Closed
matylla opened this Issue Apr 3, 2012 · 7 comments

Comments

Projects
None yet
2 participants

matylla commented Apr 3, 2012

You can read bytes expected (from content-length header) and bytes received so far. Would be especially useful for downloading huge files.

http.on('progress', function(bytesExpected, bytesTotal) {
  // => logic
});
Owner

SaltwaterC commented Apr 3, 2012

I had a discussion about it, but can't seem to find it. In order to work that way, a response object must be returned by http.get itself, and that object to be an EventEmitter instance. The implementation is not what I call straight forward, but I think it is doable with the current API. If it turns out to be too difficult to implement for the current state of affairs, a passed callback to the options object should do the trick way much easier.

Anyway, most probably it is going to be part of v0.4 which targets node.js v0.6.x and its native zlib support. I am pretty sick of the node.js v0.4 HTTP verbage.

matylla commented Apr 3, 2012

Do you have any roadmap in mind? Would be nice to know when the v0.4 will be live.

Owner

SaltwaterC commented Apr 4, 2012

Unfortunately no. For the moment my schedule is full with priority tasks. I'd hate to give you an estimation and not being able to follow it.

PS: adding a callback to the options object is fairly trivial. I could add it pretty quick if you're OK with it.

matylla commented Apr 4, 2012

Yes please.

@SaltwaterC SaltwaterC closed this in b13ea88 Apr 4, 2012

@SaltwaterC SaltwaterC added a commit that referenced this issue Apr 4, 2012

@SaltwaterC SaltwaterC Added an unit test for #8. 836f1d8
Owner

SaltwaterC commented Apr 4, 2012

I added the functionality in the dev branch. I also plan to quickly fix #7. Shall be released pretty soon for public consumption.

PS: I really need to get to v0.4. v0.3 is turning into an unmaintainable mess.

matylla commented Apr 4, 2012

I really need to get to v0.4. v0.3 is turning into an unmaintainable mess.

I know exactly what you mean :) Thanks for a quick fix.

Owner

SaltwaterC commented Apr 4, 2012

If there's no Content-Lenght, then the total is 0.

var http = require('http-get')

var progress = function (current, total) {
    console.log(current, total)
}

http.get({
    url: process.argv[2],
    progress: progress
}, process.argv[3], function (err, res) {
    if (err) {
        console.error(err)
    } else {
        console.log(res)
    }
})

Simple script showing the new functionality. Example:

node http.js http://wordpress.org/latest.tar.gz wordpress.tar.gz

I picked this specifically since it doesn't have a Content-Lenght header. Also tested it with:

node http.js http://mirrors.xservers.ro/ubuntu/releases//precise/ubuntu-12.04-beta2-desktop-i386.iso ubuntu-12.04-beta2-desktop-i386.iso

This does some real traffic over the network interface :).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment