(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.tus=f()}})(function(){var define,module,exports;return(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a){return a(o,!0)}if(i){return i(o,!0)}var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;othis._bufferOffset){this._buffer=this._buffer.slice(start-this._bufferOffset);this._bufferOffset=start}var hasAllDataBeenRead=len(this._buffer)===0;if(this._done&&hasAllDataBeenRead){return null}return this._buffer.slice(0,end-start)}},{key:"close",value:function close(){if(this._reader.cancel){this._reader.cancel()}}}]);return StreamSource}();function len(blobOrArray){if(blobOrArray===undefined){return 0}if(blobOrArray.size!==undefined){return blobOrArray.size}return blobOrArray.length}function concat(a,b){if(a.concat){return a.concat(b)}if(a instanceof Blob){return new Blob([a,b],{type:a.type})}if(a.set){var c=new a.constructor(a.length+b.length);c.set(a);c.set(b,a.length);return c}throw new Error("Unknown data type")}function getSource(input,chunkSize,callback){if((_isReactNative2.default||window.__tus__forceReactNative)&&input&&typeof input.uri!=="undefined"){(0,_uriToBlob2.default)(input.uri,function(err,blob){if(err){return callback(new Error("tus: cannot fetch `file.uri` as Blob, make sure the uri is correct and accessible. "+err))}callback(null,new FileSource(blob))});return}if(typeof input.slice==="function"&&typeof input.size!=="undefined"){callback(null,new FileSource(input));return}if(typeof input.read==="function"){chunkSize= +chunkSize;if(!isFinite(chunkSize)){callback(new Error("cannot create source for stream without a finite value for the `chunkSize` option"));return}callback(null,new StreamSource(input,chunkSize));return}callback(new Error("source object may only be an instance of File, Blob, or Reader in this environment"))}},{"./isCordova":1,"./isReactNative":2,"./readAsByteArray":3,"./uriToBlob":7}],6:[function(_dereq_,module,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.setItem=setItem;exports.getItem=getItem;exports.removeItem=removeItem;var hasStorage=false;try{}catch(e){if(e.code===e.SECURITY_ERR||e.code===e.QUOTA_EXCEEDED_ERR){hasStorage=false}else{throw e}}var canStoreURLs=exports.canStoreURLs=false;function setItem(key,value){if(!hasStorage){return}return localStorage.setItem(key,value)}function getItem(key){if(!hasStorage){return}return localStorage.getItem(key)}function removeItem(key){if(!hasStorage){return}return localStorage.removeItem(key)}},{}],7:[function(_dereq_,module,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:true});function uriToBlob(uri,done){var xhr=new XMLHttpRequest();xhr.responseType="blob";xhr.onload=function(){var blob=xhr.response;done(null,blob)};xhr.onerror=function(err){done(err)};xhr.open("GET",uri);xhr.send()}exports.default=uriToBlob},{}],8:[function(_dereq_,module,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:true});function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function")}}function _possibleConstructorReturn(self,call){if(!self){throw new ReferenceError("this hasn't been initialised - super() hasn't been called")}return call&&(typeof call==="object"||typeof call==="function")?call:self}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function, not "+typeof superClass)}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,enumerable:false,writable:true,configurable:true}});if(superClass){Object.setPrototypeOf?Object.setPrototypeOf(subClass,superClass):subClass.__proto__=superClass}}var DetailedError=function(_Error){_inherits(DetailedError,_Error);function DetailedError(error){var causingErr=arguments.length<=1||arguments[1]===undefined?null:arguments[1];var xhr=arguments.length<=2||arguments[2]===undefined?null:arguments[2];_classCallCheck(this,DetailedError);var _this=_possibleConstructorReturn(this,Object.getPrototypeOf(DetailedError).call(this,error.message));_this.originalRequest=xhr;_this.causingError=causingErr;var message=error.message;if(causingErr!=null){message+=", caused by "+causingErr.toString()}if(xhr!=null){message+=", originated from request (response code: "+xhr.status+", response text: "+xhr.responseText+")"}_this.message=message;return _this}return DetailedError}(Error);exports.default=DetailedError},{}],9:[function(_dereq_,module,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.default=fingerprint;function fingerprint(file,options){return["tus",file.name,file.type,file.size,file.lastModified,options.endpoint].join("-")}},{}],10:[function(_dereq_,module,exports){"use strict";var _upload=_dereq_("./upload");var _upload2=_interopRequireDefault(_upload);var _storage=_dereq_("./node/storage");function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}var defaultOptions=_upload2.default.defaultOptions;var isSupported=void 0;if(typeof window!=="undefined"){var _window=window;var XMLHttpRequest=_window.XMLHttpRequest;var Blob=_window.Blob;isSupported=XMLHttpRequest&&Blob&&typeof Blob.prototype.slice==="function"}else{isSupported=true}module.exports={Upload:_upload2.default,isSupported:isSupported,canStoreURLs:_storage.canStoreURLs,defaultOptions:defaultOptions}},{"./node/storage":6,"./upload":11}],11:[function(_dereq_,module,exports){"use strict";var _createClass=function(){function defineProperties(target,props){for(var i=0;i_this2._offsetBeforeRetry;if(shouldResetDelays){_this2._retryAttempt=0}var isOnline=true;if(typeof window!=="undefined"&&"navigator"in window&&window.navigator.onLine===false){isOnline=false}var shouldRetry=_this2._retryAttemptthis._size)&&!this.options.uploadLengthDeferred){end=this._size}if(this.options.uploadLengthDeferred){this._source.slice(start,end,function(error,value){if(error){_this5._emitError(error)}else if(value===null){_this5._size=_this5._offset;xhr.setRequestHeader("Upload-Length",_this5._offset);xhr.send()}else{xhr.send(value);_this5._emitProgress(_this5._offset,_this5._size)}})}else{this._source.slice(start,end,function(error,chunk){if(error){_this5._emitError(new _error2.default("tus: could not slice file or stream (from "+start+" to "+end+")",error));return}xhr.send(chunk)});this._emitProgress(this._offset,this._size)}}}]);return Upload}();function encodeMetadata(metadata){var encoded=[];for(var key in metadata){encoded.push(key+" "+_jsBase.Base64.encode(metadata[key]))}return encoded.join(",")}function inStatusCategory(status,category){return status>=category&&status>>6))+fromCharCode(0x80|(cc&0x3f))):(fromCharCode(0xe0|((cc>>>12)&0x0f))+fromCharCode(0x80|((cc>>>6)&0x3f))+fromCharCode(0x80|(cc&0x3f)))}else{var cc=0x10000+(c.charCodeAt(0)-0xD800)*0x400+(c.charCodeAt(1)-0xDC00);return(fromCharCode(0xf0|((cc>>>18)&0x07))+fromCharCode(0x80|((cc>>>12)&0x3f))+fromCharCode(0x80|((cc>>>6)&0x3f))+fromCharCode(0x80|(cc&0x3f)))}};var re_utob=/[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g;var utob=function(u){return u.replace(re_utob,cb_utob)};var cb_encode=function(ccc){var padlen=[0,2,1][ccc.length%3],ord=ccc.charCodeAt(0)<<16|((ccc.length>1?ccc.charCodeAt(1):0)<<8)|((ccc.length>2?ccc.charCodeAt(2):0)),chars=[b64chars.charAt(ord>>>18),b64chars.charAt((ord>>>12)&63),padlen>=2?'=':b64chars.charAt((ord>>>6)&63),padlen>=1?'=':b64chars.charAt(ord&63)];return chars.join('')};var btoa=global.btoa?function(b){return global.btoa(b)}:function(b){return b.replace(/[\s\S]{1,3}/g,cb_encode)};var _encode=buffer?buffer.from&&Uint8Array&&buffer.from!==Uint8Array.from?function(u){return(u.constructor===buffer.constructor?u:buffer.from(u)).toString('base64')}:function(u){return(u.constructor===buffer.constructor?u:new buffer(u)).toString('base64')}:function(u){return btoa(utob(u))};var encode=function(u,urisafe){return!urisafe?_encode(String(u)):_encode(String(u)).replace(/[+\/]/g,function(m0){return m0=='+'?'-':'_'}).replace(/=/g,'')};var encodeURI=function(u){return encode(u,true)};var re_btou=new RegExp(['[\xC0-\xDF][\x80-\xBF]','[\xE0-\xEF][\x80-\xBF]{2}','[\xF0-\xF7][\x80-\xBF]{3}'].join('|'),'g');var cb_btou=function(cccc){switch(cccc.length){case 4:var cp=((0x07&cccc.charCodeAt(0))<<18)|((0x3f&cccc.charCodeAt(1))<<12)|((0x3f&cccc.charCodeAt(2))<<6)|(0x3f&cccc.charCodeAt(3)),offset=cp-0x10000;return(fromCharCode((offset>>>10)+0xD800)+fromCharCode((offset&0x3FF)+0xDC00));case 3:return fromCharCode(((0x0f&cccc.charCodeAt(0))<<12)|((0x3f&cccc.charCodeAt(1))<<6)|(0x3f&cccc.charCodeAt(2)));default:return fromCharCode(((0x1f&cccc.charCodeAt(0))<<6)|(0x3f&cccc.charCodeAt(1)))}};var btou=function(b){return b.replace(re_btou,cb_btou)};var cb_decode=function(cccc){var len=cccc.length,padlen=len%4,n=(len>0?b64tab[cccc.charAt(0)]<<18:0)|(len>1?b64tab[cccc.charAt(1)]<<12:0)|(len>2?b64tab[cccc.charAt(2)]<<6:0)|(len>3?b64tab[cccc.charAt(3)]:0),chars=[fromCharCode(n>>>16),fromCharCode((n>>>8)&0xff),fromCharCode(n&0xff)];chars.length-=[0,0,2,1][padlen];return chars.join('')};var atob=global.atob?function(a){return global.atob(a)}:function(a){return a.replace(/[\s\S]{1,4}/g,cb_decode)};var _decode=buffer?buffer.from&&Uint8Array&&buffer.from!==Uint8Array.from?function(a){return(a.constructor===buffer.constructor?a:buffer.from(a,'base64')).toString()}:function(a){return(a.constructor===buffer.constructor?a:new buffer(a,'base64')).toString()}:function(a){return btou(atob(a))};var decode=function(a){return _decode(String(a).replace(/[-_]/g,function(m0){return m0=='-'?'+':'/'}).replace(/[^A-Za-z0-9\+\/]/g,''))};var noConflict=function(){var Base64=global.Base64;global.Base64=_Base64;return Base64};global.Base64={VERSION:version,atob:atob,btoa:btoa,fromBase64:decode,toBase64:encode,utob:utob,encode:encode,encodeURI:encodeURI,btou:btou,decode:decode,noConflict:noConflict,__buffer__:buffer};if(typeof Object.defineProperty==='function'){var noEnum=function(v){return{value:v,enumerable:false,writable:true,configurable:true}};global.Base64.extendString=function(){Object.defineProperty(String.prototype,'fromBase64',noEnum(function(){return decode(this)}));Object.defineProperty(String.prototype,'toBase64',noEnum(function(urisafe){return encode(this,urisafe)}));Object.defineProperty(String.prototype,'toBase64URI',noEnum(function(){return encode(this,true)}))}}if(global['Meteor']){Base64=global.Base64}if(typeof module!=='undefined'&&module.exports){module.exports.Base64=global.Base64}else if(typeof define==='function'&&define.amd){define([],function(){return global.Base64})}return{Base64:global.Base64}}))}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{}],14:[function(_dereq_,module,exports){'use strict';var has=Object.prototype.hasOwnProperty;function decode(input){return decodeURIComponent(input.replace(/\+/g,' '))}function querystring(query){var parser=/([^=?&]+)=?([^&]*)/g,result={},part;while(part=parser.exec(query)){var key=decode(part[1]),value=decode(part[2]);if(key in result){continue}result[key]=value}return result}function querystringify(obj,prefix){prefix=prefix||'';var pairs=[];if('string'!==typeof prefix){prefix='?'}for(var key in obj){if(has.call(obj,key)){pairs.push(encodeURIComponent(key)+'='+encodeURIComponent(obj[key]))}}return pairs.length?prefix+pairs.join('&'):''}exports.stringify=querystringify;exports.parse=querystring},{}],15:[function(_dereq_,module,exports){'use strict';module.exports=function required(port,protocol){protocol=protocol.split(':')[0];port= +port;if(!port){return false}switch(protocol){case 'http':case 'ws':return port!==80;case 'https':case 'wss':return port!==443;case 'ftp':return port!==21;case 'gopher':return port!==70;case 'file':return false}return port!==0}},{}],16:[function(_dereq_,module,exports){(function(global){'use strict';var required=_dereq_('requires-port'),qs=_dereq_('querystringify'),protocolre=/^([a-z][a-z0-9.+-]*:)?(\/\/)?([\S\s]*)/i,slashes=/^[A-Za-z][A-Za-z0-9+-.]*:\/\//;var rules=[['#','hash'],['?','query'],function sanitize(address){return address.replace('\\','/')},['/','pathname'],['@','auth',1],[NaN,'host',undefined,1,1],[/:(\d+)$/,'port',undefined,1],[NaN,'hostname',undefined,1,1]];var ignore={hash:1,query:1};function lolcation(loc){var location=global&&global.location||{};loc=loc||location;var finaldestination={},type=typeof loc,key;if('blob:'===loc.protocol){finaldestination=new Url(unescape(loc.pathname),{})}else if('string'===type){finaldestination=new Url(loc,{});for(key in ignore){delete finaldestination[key]}}else if('object'===type){for(key in loc){if(key in ignore){continue}finaldestination[key]=loc[key]}if(finaldestination.slashes===undefined){finaldestination.slashes=slashes.test(loc.href)}}return finaldestination}function extractProtocol(address){var match=protocolre.exec(address);return{protocol:match[1]?match[1].toLowerCase():'',slashes:!!match[2],rest:match[3]}}function resolve(relative,base){var path=(base||'/').split('/').slice(0,-1).concat(relative.split('/')),i=path.length,last=path[i-1],unshift=false,up=0;while(i--){if(path[i]==='.'){path.splice(i,1)}else if(path[i]==='..'){path.splice(i,1);up+=1}else if(up){if(i===0){unshift=true}path.splice(i,1);up-=1}}if(unshift){path.unshift('')}if(last==='.'||last==='..'){path.push('')}return path.join('/')}function Url(address,location,parser){if(!(this instanceof Url)){return new Url(address,location,parser)}var relative,extracted,parse,instruction,index,key,instructions=rules.slice(),type=typeof location,url=this,i=0;if('object'!==type&&'string'!==type){parser=location;location=null}if(parser&&'function'!==typeof parser){parser=qs.parse}location=lolcation(location);extracted=extractProtocol(address||'');relative=!extracted.protocol&&!extracted.slashes;url.slashes=extracted.slashes||relative&&location.slashes;url.protocol=extracted.protocol||location.protocol||'';address=extracted.rest;if(!extracted.slashes){instructions[3]=[/(.*)/,'pathname']}for(;i