Created
February 7, 2012 16:48
-
-
Save spolu/1760688 to your computer and use it in GitHub Desktop.
resume calls
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
var http = require('http'); | |
var buf1,buf2; | |
var pos1, pos2; | |
var dc = 0; | |
var done = function() { | |
if(dc === 0) { | |
dc++; | |
return; | |
} | |
console.log('equal: ' + (buf1.length === buf2.length)); | |
console.log('equal: ' + (buf1.toString('base64') === buf2.toString('base64'))); | |
}; | |
var req1 = http.get({ host: 'distilleryimage4.s3.amazonaws.com', | |
port: 80, | |
path: '/7d21593427dd11e180c9123138016265_7.jpg' }, | |
function(res) { | |
console.log('CL: ' + res.headers['content-length']); | |
buf1 = new Buffer(parseInt(res.headers['content-length'], 10)); | |
pos1 = 0; | |
res.on('data', function(buf) { | |
buf.copy(buf1, pos1); | |
pos1 += buf.length; | |
console.log('data: ' + buf.length + ' ' + pos1); | |
}); | |
res.on('end', function() { | |
done(); | |
}); | |
}); | |
var req2 = http.get({ host: 'distilleryimage4.s3.amazonaws.com', | |
port: 80, | |
path: '/7d21593427dd11e180c9123138016265_7.jpg' }, | |
function(res) { | |
console.log('CL: ' + res.headers['content-length']); | |
buf2 = new Buffer(parseInt(res.headers['content-length'], 10)); | |
pos2 = 0; | |
res.resume(); | |
res.on('data', function(buf) { | |
buf.copy(buf2, pos2); | |
pos2 += buf.length; | |
console.log('data: ' + buf.length + ' ' + pos2); | |
res.pause(); | |
setTimeout(function() { res.resume(); }, 100); | |
}); | |
res.on('end', function() { | |
done(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment