http.js 870 B

12345678910111213141516171819202122232425262728293031
  1. var progress = require('../index');
  2. var http = require('http');
  3. var fs = require('fs');
  4. var log = require('single-line-log').stdout;
  5. var numeral = require('numeral');
  6. var str = progress({
  7. drain: true,
  8. time: 100,
  9. speed: 20
  10. });
  11. str.on('progress', function(progress) {
  12. log('Running: '+numeral(progress.runtime).format('00:00:00')+' ('+numeral(progress.transferred).format('0 b')+')\n'+
  13. 'Left: '+numeral(progress.eta).format('00:00:00')+' ('+numeral(progress.remaining).format('0 b')+')\n'+
  14. numeral(progress.speed).format('0.00b')+'/s '+Math.round(progress.percentage)+'%');
  15. });
  16. var options = {
  17. method: 'GET',
  18. host: 'cachefly.cachefly.net',
  19. path: '/10mb.test',
  20. headers: {
  21. 'user-agent': 'testy test'
  22. }
  23. };
  24. http.request(options, function(response) {
  25. response.pipe(str);
  26. }).end();
  27. console.log('progress-stream using http module - downloading 10 MB file');