Skip to content

Instantly share code, notes, and snippets.

@cristiano-belloni
Last active August 29, 2015 14:11
Show Gist options
  • Save cristiano-belloni/22afe04aba3dde02814d to your computer and use it in GitHub Desktop.
Save cristiano-belloni/22afe04aba3dde02814d to your computer and use it in GitHub Desktop.
var request = require('superagent');
var INTERVAL = 4000;
function rangeRequest (start, end) {
request
.get('// todo your server here')
.set('Range:', 'bytes=' + start + '-' + end)
.set('Accept', '*/*')
.set ('Cache-Control:','no-cache')
.end(function(error, res){
console.log (res);
});
}
var when = 5000;
setInterval (function () {
setTimeout (function () {
var start = 100;
var end = 300000;
console.log ("request sent");
rangeRequest (start, end);
}, when);
}, INTERVAL);
@stephenplusplus
Copy link

My version:

var request = require('superagent');
var rangeStream = require('range-stream');
var gcloud = require('gcloud')({
  projectId: 'nth-circlet-705',
  keyFilename: '/Users/stephen/dev/keyfile.json'
});
var file = gcloud.storage().bucket('stephen-has-a-new-bucket-yay').file('blah.jpg');

var INTERVAL = 4000;

function gcloudRangeRequest (start, end) {
  file
    .createReadStream()
    .pipe(rangeStream(start, end))
    .on('data', function() {})
    .on('end', function () {
      console.log('done')
    });
}

function rangeRequest (start, end) {
  request
    .get('http://yahoo.com')
    .set('Range:', 'bytes=' + start + '-' + end)
    .set('Accept', '*/*')
    .set ('Cache-Control:','no-cache')
    .end(function(error, res){
      console.log (res);
    });
}

var when = 5000;

setInterval (function () {
  setTimeout (function () {
    var start = 100;
    var end = 300000;

    console.log ("request sent");

    // rangeRequest (start, end);
    gcloudRangeRequest (start, end);
  }, when);
}, INTERVAL);

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