request.js 734 B

1234567891011121314151617181920
  1. var progress = require('../index');
  2. var req = require('request');
  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. }, function(progress) {
  10. log('Running: '+numeral(progress.runtime).format('00:00:00')+' ('+numeral(progress.transferred).format('0 b')+')\n'+
  11. 'Left: '+numeral(progress.eta).format('00:00:00')+' ('+numeral(progress.remaining).format('0 b')+')\n'+
  12. numeral(progress.speed).format('0.00b')+'/s '+Math.round(progress.percentage)+'%');
  13. });
  14. req('http://cachefly.cachefly.net/10mb.test', {
  15. headers: { 'user-agent': 'test' }
  16. }).pipe(str);
  17. console.log('progress-stream using request module - downloading 10 MB file');