text: 
  // For non-view logic
  var $ = require('jquery');
  
  var fileBlock = function(_offset, length, _file, readChunk) {
    var r = new FileReader();
    var blob = _file.slice(_offset, length + _offset);
    r.onload = readChunk;
    r.readAsArrayBuffer(blob);
  }
  
  // Based on alediaferia's SO response
  // http://stackoverflow.com/questions/14438187/javascript-filereader-parsing-long-file-in-chunks
  exports.onFileProgress = function(options, ondata, onerror, onend) {
    var file       = options.file;
    var fileSize   = file.size;
    var chunkSize  = options.bufferSize || 8192;
    var offset     = 0;
    var readChunk = function(evt) {
      if (offset >= fileSize) {
        console.log("Done reading file");
        onend();
        return;
      }
      if (evt.target.error == null) {
        var buffer = evt.target.result;
        var len = buffer.byteLength;
        offset += len;
        ondata(buffer); // callback for handling read chunk
      } else {
        var errorMessage = evt.target.error;
        console.log("Read error: " + errorMessage);
        onerror(errorMessage);
        return;
      }
      fileBlock(offset, chunkSize, file, readChunk);
    }
    fileBlock(offset, chunkSize, file, readChunk);
  }
  
  exports.createTokenGenerator = function() {
    // Make call to API to try and get token
    var hasBeenRunTimes = 0;
    return {
      getToken: function(callback) {
      ++hasBeenRunTimes;
      if (hasBeenRunTimes > 5) {
        var err = new Error('Cannot reach server');
        callback(null, err);
        return;
      }
      var url = '/token';
      var tokenRequest = new XMLHttpRequest();
      tokenRequest.open("GET", url, true);
      tokenRequest.onload = function(evt) {
        var token = tokenRequest.responseText;
        callback(token);
      };
      tokenRequest.send();
      },
      getCount: function() { return hasBeenRunTimes; }
    }
  };
  
  exports.getToken = (function() {
    // Make call to API to try and get token
    var hasBeenRunTimes = 0;
    return function(callback) {
      hasBeenRunTimes++
      if (hasBeenRunTimes > 5) {
        var err = new Error('Cannot reach server');
        callback(null, err);
        return;
      }
      var url = '/token';
      var tokenRequest = new XMLHttpRequest();
      tokenRequest.open("GET", url, true);
      tokenRequest.onload = function(evt) {
        var token = tokenRequest.responseText;
        callback(token);
      };
      tokenRequest.send();
    }
  })();
  
  exports.initPubSub = function() {
    var o         = $({});
    $.subscribe   = o.on.bind(o);
    $.unsubscribe = o.off.bind(o);
    $.publish     = o.trigger.bind(o);
  }