Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Socket
Sign inDemoInstall

tus-js-client

Package Overview
Dependencies
Maintainers
1
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tus-js-client - npm Package Compare versions

Comparing version 1.5.0 to 1.5.1

bin/browserstack-jasmine.js

11

bin/phantom-jasmine.js
/* global ConsoleReporter */
/* eslint no-console: 0 */
/* eslint-env phantomjs */

@@ -10,6 +11,10 @@ /**

* In order to run this script, invoke it using following command:
* phantomjs --ssl-protocol=any bin/phantom-jasmine.js
* phantomjs --local-to-remote-url-access=yes bin/phantom-jasmine.js
*
* The --ssl-protocol flag is required as else Phantom will complain about
* failing handshakes when loading resources over HTTPS.
* The --local-to-remote-url-access flag is required as else Phantom
* will complain about NETWORK_ERR XMLHttpRequest Exception 101.
* This is caused by us opening test/SpecRunner.html using the file://
* protocol but in test/spec/upload.browser.js we make HTTP requests
* to https://master.tus.io/ which is usually not allowed. Therfore,
* we must explicitly disable to (elsewhere useful) security rule.
*/

@@ -16,0 +21,0 @@ "use strict";

@@ -208,2 +208,3 @@ (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;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){

var isSupported = void 0;

@@ -217,6 +218,6 @@ if (typeof window !== "undefined") {

var isSupported = XMLHttpRequest && Blob && typeof Blob.prototype.slice === "function";
isSupported = XMLHttpRequest && Blob && typeof Blob.prototype.slice === "function";
} else {
// Node.js environment using http module
var isSupported = true;
isSupported = true;
}

@@ -292,3 +293,4 @@

overridePatchMethod: false,
retryDelays: null
retryDelays: null,
removeFingerprintOnSuccess: false
};

@@ -586,2 +588,9 @@

if (_this2._size === 0) {
// Nothing to upload and file was successfully created
_this2._emitSuccess();
_this2._source.close();
return;
}
if (_this2.options.resume) {

@@ -739,2 +748,8 @@ Storage.setItem(_this2._fingerprint, _this2.url);

if (offset == _this4._size) {
if (_this4.options.removeFingerprintOnSuccess && _this4.options.resume) {
// Remove stored fingerprint and corresponding endpoint. This causes
// new upload of the same file must be treated as a different file.
Storage.removeItem(_this4._fingerprint);
}
// Yay, finally done :)

@@ -741,0 +756,0 @@ _this4._emitSuccess();

@@ -1,2 +0,2 @@

(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;o<r.length;o++)s(r[o]);return s}({1:[function(_dereq_,module,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.encode=encode;var _window=window;var btoa=_window.btoa;function encode(data){return btoa(unescape(encodeURIComponent(data)))}var isSupported=exports.isSupported="btoa"in window},{}],2:[function(_dereq_,module,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.newRequest=newRequest;exports.resolveUrl=resolveUrl;var _resolveUrl=_dereq_("resolve-url");var _resolveUrl2=_interopRequireDefault(_resolveUrl);function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{"default":obj}}function newRequest(){return new window.XMLHttpRequest}function resolveUrl(origin,link){return(0,_resolveUrl2.default)(origin,link)}},{"resolve-url":10}],3:[function(_dereq_,module,exports){"use strict";var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor)}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor}}();Object.defineProperty(exports,"__esModule",{value:true});exports.getSource=getSource;function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function")}}var FileSource=function(){function FileSource(file){_classCallCheck(this,FileSource);this._file=file;this.size=file.size}_createClass(FileSource,[{key:"slice",value:function slice(start,end){return this._file.slice(start,end)}},{key:"close",value:function close(){}}]);return FileSource}();function getSource(input){if(typeof input.slice==="function"&&typeof input.size!=="undefined"){return new FileSource(input)}throw new Error("source object may only be an instance of File or Blob in this environment")}},{}],4:[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{hasStorage="localStorage"in window;var key="tusSupport";localStorage.setItem(key,localStorage.getItem(key))}catch(e){if(e.code===e.SECURITY_ERR||e.code===e.QUOTA_EXCEEDED_ERR){hasStorage=false}else{throw e}}var canStoreURLs=exports.canStoreURLs=hasStorage;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)}},{}],5:[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},{}],6:[function(_dereq_,module,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.default=fingerprint;function fingerprint(file){return["tus",file.name,file.type,file.size,file.lastModified].join("-")}},{}],7:[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;if(typeof window!=="undefined"){var _window=window;var XMLHttpRequest=_window.XMLHttpRequest;var Blob=_window.Blob;var isSupported=XMLHttpRequest&&Blob&&typeof Blob.prototype.slice==="function"}else{var isSupported=true}module.exports={Upload:_upload2.default,isSupported:isSupported,canStoreURLs:_storage.canStoreURLs,defaultOptions:defaultOptions}},{"./node/storage":4,"./upload":8}],8:[function(_dereq_,module,exports){"use strict";var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor)}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor}}();Object.defineProperty(exports,"__esModule",{value:true});var _fingerprint=_dereq_("./fingerprint");var _fingerprint2=_interopRequireDefault(_fingerprint);var _error=_dereq_("./error");var _error2=_interopRequireDefault(_error);var _extend=_dereq_("extend");var _extend2=_interopRequireDefault(_extend);var _request=_dereq_("./node/request");var _source=_dereq_("./node/source");var _base=_dereq_("./node/base64");var Base64=_interopRequireWildcard(_base);var _storage=_dereq_("./node/storage");var Storage=_interopRequireWildcard(_storage);function _interopRequireWildcard(obj){if(obj&&obj.__esModule){return obj}else{var newObj={};if(obj!=null){for(var key in obj){if(Object.prototype.hasOwnProperty.call(obj,key))newObj[key]=obj[key]}}newObj.default=obj;return newObj}}function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{"default":obj}}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function")}}var defaultOptions={endpoint:"",fingerprint:_fingerprint2.default,resume:true,onProgress:null,onChunkComplete:null,onSuccess:null,onError:null,headers:{},chunkSize:Infinity,withCredentials:false,uploadUrl:null,uploadSize:null,overridePatchMethod:false,retryDelays:null};var Upload=function(){function Upload(file,options){_classCallCheck(this,Upload);this.options=(0,_extend2.default)(true,{},defaultOptions,options);this.file=file;this.url=null;this._xhr=null;this._fingerprint=null;this._offset=null;this._aborted=false;this._size=null;this._source=null;this._retryAttempt=0;this._retryTimeout=null;this._offsetBeforeRetry=0}_createClass(Upload,[{key:"start",value:function start(){var _this=this;var file=this.file;if(!file){this._emitError(new Error("tus: no file or stream to upload provided"));return}if(!this.options.endpoint){this._emitError(new Error("tus: no endpoint provided"));return}var source=this._source=(0,_source.getSource)(file,this.options.chunkSize);if(this.options.uploadSize!=null){var size=+this.options.uploadSize;if(isNaN(size)){throw new Error("tus: cannot convert `uploadSize` option into a number")}this._size=size}else{var size=source.size;if(size==null){throw new Error("tus: cannot automatically derive upload's size from input and must be specified manually using the `uploadSize` option")}this._size=size}var retryDelays=this.options.retryDelays;if(retryDelays!=null){if(Object.prototype.toString.call(retryDelays)!=="[object Array]"){throw new Error("tus: the `retryDelays` option must either be an array or null")}else{(function(){var errorCallback=_this.options.onError;_this.options.onError=function(err){_this.options.onError=errorCallback;var shouldResetDelays=_this._offset!=null&&_this._offset>_this._offsetBeforeRetry;if(shouldResetDelays){_this._retryAttempt=0}var isOnline=true;if(typeof window!=="undefined"&&"navigator"in window&&window.navigator.onLine===false){isOnline=false}var shouldRetry=_this._retryAttempt<retryDelays.length&&err.originalRequest!=null&&!inStatusCategory(err.originalRequest.status,400)&&isOnline;if(!shouldRetry){_this._emitError(err);return}var delay=retryDelays[_this._retryAttempt++];_this._offsetBeforeRetry=_this._offset;_this.options.uploadUrl=_this.url;_this._retryTimeout=setTimeout(function(){_this.start()},delay)}})()}}this._aborted=false;if(this.url!=null){this._resumeUpload();return}if(this.options.uploadUrl!=null){this.url=this.options.uploadUrl;this._resumeUpload();return}if(this.options.resume){this._fingerprint=this.options.fingerprint(file);var resumedUrl=Storage.getItem(this._fingerprint);if(resumedUrl!=null){this.url=resumedUrl;this._resumeUpload();return}}this._createUpload()}},{key:"abort",value:function abort(){if(this._xhr!==null){this._xhr.abort();this._source.close();this._aborted=true}if(this._retryTimeout!=null){clearTimeout(this._retryTimeout);this._retryTimeout=null}}},{key:"_emitXhrError",value:function _emitXhrError(xhr,err,causingErr){this._emitError(new _error2.default(err,causingErr,xhr))}},{key:"_emitError",value:function _emitError(err){if(typeof this.options.onError==="function"){this.options.onError(err)}else{throw err}}},{key:"_emitSuccess",value:function _emitSuccess(){if(typeof this.options.onSuccess==="function"){this.options.onSuccess()}}},{key:"_emitProgress",value:function _emitProgress(bytesSent,bytesTotal){if(typeof this.options.onProgress==="function"){this.options.onProgress(bytesSent,bytesTotal)}}},{key:"_emitChunkComplete",value:function _emitChunkComplete(chunkSize,bytesAccepted,bytesTotal){if(typeof this.options.onChunkComplete==="function"){this.options.onChunkComplete(chunkSize,bytesAccepted,bytesTotal)}}},{key:"_setupXHR",value:function _setupXHR(xhr){this._xhr=xhr;xhr.setRequestHeader("Tus-Resumable","1.0.0");var headers=this.options.headers;for(var name in headers){xhr.setRequestHeader(name,headers[name])}xhr.withCredentials=this.options.withCredentials}},{key:"_createUpload",value:function _createUpload(){var _this2=this;var xhr=(0,_request.newRequest)();xhr.open("POST",this.options.endpoint,true);xhr.onload=function(){if(!inStatusCategory(xhr.status,200)){_this2._emitXhrError(xhr,new Error("tus: unexpected response while creating upload"));return}var location=xhr.getResponseHeader("Location");if(location==null){_this2._emitXhrError(xhr,new Error("tus: invalid or missing Location header"));return}_this2.url=(0,_request.resolveUrl)(_this2.options.endpoint,location);if(_this2.options.resume){Storage.setItem(_this2._fingerprint,_this2.url)}_this2._offset=0;_this2._startUpload()};xhr.onerror=function(err){_this2._emitXhrError(xhr,new Error("tus: failed to create upload"),err)};this._setupXHR(xhr);xhr.setRequestHeader("Upload-Length",this._size);var metadata=encodeMetadata(this.options.metadata);if(metadata!==""){xhr.setRequestHeader("Upload-Metadata",metadata)}xhr.send(null)}},{key:"_resumeUpload",value:function _resumeUpload(){var _this3=this;var xhr=(0,_request.newRequest)();xhr.open("HEAD",this.url,true);xhr.onload=function(){if(!inStatusCategory(xhr.status,200)){if(_this3.options.resume&&inStatusCategory(xhr.status,400)){Storage.removeItem(_this3._fingerprint)}if(xhr.status===423){_this3._emitXhrError(xhr,new Error("tus: upload is currently locked; retry later"));return}_this3.url=null;_this3._createUpload();return}var offset=parseInt(xhr.getResponseHeader("Upload-Offset"),10);if(isNaN(offset)){_this3._emitXhrError(xhr,new Error("tus: invalid or missing offset value"));return}var length=parseInt(xhr.getResponseHeader("Upload-Length"),10);if(isNaN(length)){_this3._emitXhrError(xhr,new Error("tus: invalid or missing length value"));return}if(offset===length){_this3._emitProgress(length,length);_this3._emitSuccess();return}_this3._offset=offset;_this3._startUpload()};xhr.onerror=function(err){_this3._emitXhrError(xhr,new Error("tus: failed to resume upload"),err)};this._setupXHR(xhr);xhr.send(null)}},{key:"_startUpload",value:function _startUpload(){var _this4=this;if(this._aborted){return}var xhr=(0,_request.newRequest)();if(this.options.overridePatchMethod){xhr.open("POST",this.url,true);xhr.setRequestHeader("X-HTTP-Method-Override","PATCH")}else{xhr.open("PATCH",this.url,true)}xhr.onload=function(){if(!inStatusCategory(xhr.status,200)){_this4._emitXhrError(xhr,new Error("tus: unexpected response while uploading chunk"));return}var offset=parseInt(xhr.getResponseHeader("Upload-Offset"),10);if(isNaN(offset)){_this4._emitXhrError(xhr,new Error("tus: invalid or missing offset value"));return}_this4._emitProgress(offset,_this4._size);_this4._emitChunkComplete(offset-_this4._offset,offset,_this4._size);_this4._offset=offset;if(offset==_this4._size){_this4._emitSuccess();_this4._source.close();return}_this4._startUpload()};xhr.onerror=function(err){if(_this4._aborted){return}_this4._emitXhrError(xhr,new Error("tus: failed to upload chunk at offset "+_this4._offset),err)};if("upload"in xhr){xhr.upload.onprogress=function(e){if(!e.lengthComputable){return}_this4._emitProgress(start+e.loaded,_this4._size)}}this._setupXHR(xhr);xhr.setRequestHeader("Upload-Offset",this._offset);xhr.setRequestHeader("Content-Type","application/offset+octet-stream");var start=this._offset;var end=this._offset+this.options.chunkSize;if(end===Infinity||end>this._size){end=this._size}xhr.send(this._source.slice(start,end));this._emitProgress(this._offset,this._size)}}]);return Upload}();function encodeMetadata(metadata){if(!Base64.isSupported){return""}var encoded=[];for(var key in metadata){encoded.push(key+" "+Base64.encode(metadata[key]))}return encoded.join(",")}function inStatusCategory(status,category){return status>=category&&status<category+100}Upload.defaultOptions=defaultOptions;exports.default=Upload},{"./error":5,"./fingerprint":6,"./node/base64":1,"./node/request":2,"./node/source":3,"./node/storage":4,extend:9}],9:[function(_dereq_,module,exports){"use strict";var hasOwn=Object.prototype.hasOwnProperty;var toStr=Object.prototype.toString;var isArray=function isArray(arr){if(typeof Array.isArray==="function"){return Array.isArray(arr)}return toStr.call(arr)==="[object Array]"};var isPlainObject=function isPlainObject(obj){if(!obj||toStr.call(obj)!=="[object Object]"){return false}var hasOwnConstructor=hasOwn.call(obj,"constructor");var hasIsPrototypeOf=obj.constructor&&obj.constructor.prototype&&hasOwn.call(obj.constructor.prototype,"isPrototypeOf");if(obj.constructor&&!hasOwnConstructor&&!hasIsPrototypeOf){return false}var key;for(key in obj){}return typeof key==="undefined"||hasOwn.call(obj,key)};module.exports=function extend(){var options,name,src,copy,copyIsArray,clone,target=arguments[0],i=1,length=arguments.length,deep=false;if(typeof target==="boolean"){deep=target;target=arguments[1]||{};i=2}else if(typeof target!=="object"&&typeof target!=="function"||target==null){target={}}for(;i<length;++i){options=arguments[i];if(options!=null){for(name in options){src=target[name];copy=options[name];if(target!==copy){if(deep&&copy&&(isPlainObject(copy)||(copyIsArray=isArray(copy)))){if(copyIsArray){copyIsArray=false;clone=src&&isArray(src)?src:[]}else{clone=src&&isPlainObject(src)?src:{}}target[name]=extend(deep,clone,copy)}else if(typeof copy!=="undefined"){target[name]=copy}}}}}return target}},{}],10:[function(_dereq_,module,exports){void function(root,factory){if(typeof define==="function"&&define.amd){define(factory)}else if(typeof exports==="object"){module.exports=factory()}else{root.resolveUrl=factory()}}(this,function(){function resolveUrl(){var numUrls=arguments.length;if(numUrls===0){throw new Error("resolveUrl requires at least one argument; got none.")}var base=document.createElement("base");base.href=arguments[0];if(numUrls===1){return base.href}var head=document.getElementsByTagName("head")[0];head.insertBefore(base,head.firstChild);var a=document.createElement("a");var resolved;for(var index=1;index<numUrls;index++){a.href=arguments[index];resolved=a.href;base.href=resolved}head.removeChild(base);return resolved}return resolveUrl})},{}]},{},[7])(7)});
(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;o<r.length;o++)s(r[o]);return s}({1:[function(_dereq_,module,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.encode=encode;var _window=window;var btoa=_window.btoa;function encode(data){return btoa(unescape(encodeURIComponent(data)))}var isSupported=exports.isSupported="btoa"in window},{}],2:[function(_dereq_,module,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.newRequest=newRequest;exports.resolveUrl=resolveUrl;var _resolveUrl=_dereq_("resolve-url");var _resolveUrl2=_interopRequireDefault(_resolveUrl);function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{"default":obj}}function newRequest(){return new window.XMLHttpRequest}function resolveUrl(origin,link){return(0,_resolveUrl2.default)(origin,link)}},{"resolve-url":10}],3:[function(_dereq_,module,exports){"use strict";var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor)}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor}}();Object.defineProperty(exports,"__esModule",{value:true});exports.getSource=getSource;function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function")}}var FileSource=function(){function FileSource(file){_classCallCheck(this,FileSource);this._file=file;this.size=file.size}_createClass(FileSource,[{key:"slice",value:function slice(start,end){return this._file.slice(start,end)}},{key:"close",value:function close(){}}]);return FileSource}();function getSource(input){if(typeof input.slice==="function"&&typeof input.size!=="undefined"){return new FileSource(input)}throw new Error("source object may only be an instance of File or Blob in this environment")}},{}],4:[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{hasStorage="localStorage"in window;var key="tusSupport";localStorage.setItem(key,localStorage.getItem(key))}catch(e){if(e.code===e.SECURITY_ERR||e.code===e.QUOTA_EXCEEDED_ERR){hasStorage=false}else{throw e}}var canStoreURLs=exports.canStoreURLs=hasStorage;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)}},{}],5:[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},{}],6:[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("-")}},{}],7:[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":4,"./upload":8}],8:[function(_dereq_,module,exports){"use strict";var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor)}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor}}();Object.defineProperty(exports,"__esModule",{value:true});var _fingerprint=_dereq_("./fingerprint");var _fingerprint2=_interopRequireDefault(_fingerprint);var _error=_dereq_("./error");var _error2=_interopRequireDefault(_error);var _extend=_dereq_("extend");var _extend2=_interopRequireDefault(_extend);var _request=_dereq_("./node/request");var _source=_dereq_("./node/source");var _base=_dereq_("./node/base64");var Base64=_interopRequireWildcard(_base);var _storage=_dereq_("./node/storage");var Storage=_interopRequireWildcard(_storage);function _interopRequireWildcard(obj){if(obj&&obj.__esModule){return obj}else{var newObj={};if(obj!=null){for(var key in obj){if(Object.prototype.hasOwnProperty.call(obj,key))newObj[key]=obj[key]}}newObj.default=obj;return newObj}}function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{"default":obj}}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function")}}var defaultOptions={endpoint:null,fingerprint:_fingerprint2.default,resume:true,onProgress:null,onChunkComplete:null,onSuccess:null,onError:null,headers:{},chunkSize:Infinity,withCredentials:false,uploadUrl:null,uploadSize:null,overridePatchMethod:false,retryDelays:null,removeFingerprintOnSuccess:false};var Upload=function(){function Upload(file,options){_classCallCheck(this,Upload);this.options=(0,_extend2.default)(true,{},defaultOptions,options);this.file=file;this.url=null;this._xhr=null;this._fingerprint=null;this._offset=null;this._aborted=false;this._size=null;this._source=null;this._retryAttempt=0;this._retryTimeout=null;this._offsetBeforeRetry=0}_createClass(Upload,[{key:"start",value:function start(){var _this=this;var file=this.file;if(!file){this._emitError(new Error("tus: no file or stream to upload provided"));return}if(!this.options.endpoint&&!this.options.uploadUrl){this._emitError(new Error("tus: neither an endpoint or an upload URL is provided"));return}var source=this._source=(0,_source.getSource)(file,this.options.chunkSize);if(this.options.uploadSize!=null){var size=+this.options.uploadSize;if(isNaN(size)){throw new Error("tus: cannot convert `uploadSize` option into a number")}this._size=size}else{var size=source.size;if(size==null){throw new Error("tus: cannot automatically derive upload's size from input and must be specified manually using the `uploadSize` option")}this._size=size}var retryDelays=this.options.retryDelays;if(retryDelays!=null){if(Object.prototype.toString.call(retryDelays)!=="[object Array]"){throw new Error("tus: the `retryDelays` option must either be an array or null")}else{(function(){var errorCallback=_this.options.onError;_this.options.onError=function(err){_this.options.onError=errorCallback;var shouldResetDelays=_this._offset!=null&&_this._offset>_this._offsetBeforeRetry;if(shouldResetDelays){_this._retryAttempt=0}var isOnline=true;if(typeof window!=="undefined"&&"navigator"in window&&window.navigator.onLine===false){isOnline=false}var shouldRetry=_this._retryAttempt<retryDelays.length&&err.originalRequest!=null&&!inStatusCategory(err.originalRequest.status,400)&&isOnline;if(!shouldRetry){_this._emitError(err);return}var delay=retryDelays[_this._retryAttempt++];_this._offsetBeforeRetry=_this._offset;_this.options.uploadUrl=_this.url;_this._retryTimeout=setTimeout(function(){_this.start()},delay)}})()}}this._aborted=false;if(this.url!=null){this._resumeUpload();return}if(this.options.uploadUrl!=null){this.url=this.options.uploadUrl;this._resumeUpload();return}if(this.options.resume){this._fingerprint=this.options.fingerprint(file,this.options);var resumedUrl=Storage.getItem(this._fingerprint);if(resumedUrl!=null){this.url=resumedUrl;this._resumeUpload();return}}this._createUpload()}},{key:"abort",value:function abort(){if(this._xhr!==null){this._xhr.abort();this._source.close();this._aborted=true}if(this._retryTimeout!=null){clearTimeout(this._retryTimeout);this._retryTimeout=null}}},{key:"_emitXhrError",value:function _emitXhrError(xhr,err,causingErr){this._emitError(new _error2.default(err,causingErr,xhr))}},{key:"_emitError",value:function _emitError(err){if(typeof this.options.onError==="function"){this.options.onError(err)}else{throw err}}},{key:"_emitSuccess",value:function _emitSuccess(){if(typeof this.options.onSuccess==="function"){this.options.onSuccess()}}},{key:"_emitProgress",value:function _emitProgress(bytesSent,bytesTotal){if(typeof this.options.onProgress==="function"){this.options.onProgress(bytesSent,bytesTotal)}}},{key:"_emitChunkComplete",value:function _emitChunkComplete(chunkSize,bytesAccepted,bytesTotal){if(typeof this.options.onChunkComplete==="function"){this.options.onChunkComplete(chunkSize,bytesAccepted,bytesTotal)}}},{key:"_setupXHR",value:function _setupXHR(xhr){this._xhr=xhr;xhr.setRequestHeader("Tus-Resumable","1.0.0");var headers=this.options.headers;for(var name in headers){xhr.setRequestHeader(name,headers[name])}xhr.withCredentials=this.options.withCredentials}},{key:"_createUpload",value:function _createUpload(){var _this2=this;if(!this.options.endpoint){this._emitError(new Error("tus: unable to create upload because no endpoint is provided"));return}var xhr=(0,_request.newRequest)();xhr.open("POST",this.options.endpoint,true);xhr.onload=function(){if(!inStatusCategory(xhr.status,200)){_this2._emitXhrError(xhr,new Error("tus: unexpected response while creating upload"));return}var location=xhr.getResponseHeader("Location");if(location==null){_this2._emitXhrError(xhr,new Error("tus: invalid or missing Location header"));return}_this2.url=(0,_request.resolveUrl)(_this2.options.endpoint,location);if(_this2._size===0){_this2._emitSuccess();_this2._source.close();return}if(_this2.options.resume){Storage.setItem(_this2._fingerprint,_this2.url)}_this2._offset=0;_this2._startUpload()};xhr.onerror=function(err){_this2._emitXhrError(xhr,new Error("tus: failed to create upload"),err)};this._setupXHR(xhr);xhr.setRequestHeader("Upload-Length",this._size);var metadata=encodeMetadata(this.options.metadata);if(metadata!==""){xhr.setRequestHeader("Upload-Metadata",metadata)}xhr.send(null)}},{key:"_resumeUpload",value:function _resumeUpload(){var _this3=this;var xhr=(0,_request.newRequest)();xhr.open("HEAD",this.url,true);xhr.onload=function(){if(!inStatusCategory(xhr.status,200)){if(_this3.options.resume&&inStatusCategory(xhr.status,400)){Storage.removeItem(_this3._fingerprint)}if(xhr.status===423){_this3._emitXhrError(xhr,new Error("tus: upload is currently locked; retry later"));return}if(!_this3.options.endpoint){_this3._emitXhrError(xhr,new Error("tus: unable to resume upload (new upload cannot be created without an endpoint)"));return}_this3.url=null;_this3._createUpload();return}var offset=parseInt(xhr.getResponseHeader("Upload-Offset"),10);if(isNaN(offset)){_this3._emitXhrError(xhr,new Error("tus: invalid or missing offset value"));return}var length=parseInt(xhr.getResponseHeader("Upload-Length"),10);if(isNaN(length)){_this3._emitXhrError(xhr,new Error("tus: invalid or missing length value"));return}if(offset===length){_this3._emitProgress(length,length);_this3._emitSuccess();return}_this3._offset=offset;_this3._startUpload()};xhr.onerror=function(err){_this3._emitXhrError(xhr,new Error("tus: failed to resume upload"),err)};this._setupXHR(xhr);xhr.send(null)}},{key:"_startUpload",value:function _startUpload(){var _this4=this;if(this._aborted){return}var xhr=(0,_request.newRequest)();if(this.options.overridePatchMethod){xhr.open("POST",this.url,true);xhr.setRequestHeader("X-HTTP-Method-Override","PATCH")}else{xhr.open("PATCH",this.url,true)}xhr.onload=function(){if(!inStatusCategory(xhr.status,200)){_this4._emitXhrError(xhr,new Error("tus: unexpected response while uploading chunk"));return}var offset=parseInt(xhr.getResponseHeader("Upload-Offset"),10);if(isNaN(offset)){_this4._emitXhrError(xhr,new Error("tus: invalid or missing offset value"));return}_this4._emitProgress(offset,_this4._size);_this4._emitChunkComplete(offset-_this4._offset,offset,_this4._size);_this4._offset=offset;if(offset==_this4._size){if(_this4.options.removeFingerprintOnSuccess&&_this4.options.resume){Storage.removeItem(_this4._fingerprint)}_this4._emitSuccess();_this4._source.close();return}_this4._startUpload()};xhr.onerror=function(err){if(_this4._aborted){return}_this4._emitXhrError(xhr,new Error("tus: failed to upload chunk at offset "+_this4._offset),err)};if("upload"in xhr){xhr.upload.onprogress=function(e){if(!e.lengthComputable){return}_this4._emitProgress(start+e.loaded,_this4._size)}}this._setupXHR(xhr);xhr.setRequestHeader("Upload-Offset",this._offset);xhr.setRequestHeader("Content-Type","application/offset+octet-stream");var start=this._offset;var end=this._offset+this.options.chunkSize;if(end===Infinity||end>this._size){end=this._size}xhr.send(this._source.slice(start,end));this._emitProgress(this._offset,this._size)}}]);return Upload}();function encodeMetadata(metadata){if(!Base64.isSupported){return""}var encoded=[];for(var key in metadata){encoded.push(key+" "+Base64.encode(metadata[key]))}return encoded.join(",")}function inStatusCategory(status,category){return status>=category&&status<category+100}Upload.defaultOptions=defaultOptions;exports.default=Upload},{"./error":5,"./fingerprint":6,"./node/base64":1,"./node/request":2,"./node/source":3,"./node/storage":4,extend:9}],9:[function(_dereq_,module,exports){"use strict";var hasOwn=Object.prototype.hasOwnProperty;var toStr=Object.prototype.toString;var isArray=function isArray(arr){if(typeof Array.isArray==="function"){return Array.isArray(arr)}return toStr.call(arr)==="[object Array]"};var isPlainObject=function isPlainObject(obj){if(!obj||toStr.call(obj)!=="[object Object]"){return false}var hasOwnConstructor=hasOwn.call(obj,"constructor");var hasIsPrototypeOf=obj.constructor&&obj.constructor.prototype&&hasOwn.call(obj.constructor.prototype,"isPrototypeOf");if(obj.constructor&&!hasOwnConstructor&&!hasIsPrototypeOf){return false}var key;for(key in obj){}return typeof key==="undefined"||hasOwn.call(obj,key)};module.exports=function extend(){var options,name,src,copy,copyIsArray,clone,target=arguments[0],i=1,length=arguments.length,deep=false;if(typeof target==="boolean"){deep=target;target=arguments[1]||{};i=2}else if(typeof target!=="object"&&typeof target!=="function"||target==null){target={}}for(;i<length;++i){options=arguments[i];if(options!=null){for(name in options){src=target[name];copy=options[name];if(target!==copy){if(deep&&copy&&(isPlainObject(copy)||(copyIsArray=isArray(copy)))){if(copyIsArray){copyIsArray=false;clone=src&&isArray(src)?src:[]}else{clone=src&&isPlainObject(src)?src:{}}target[name]=extend(deep,clone,copy)}else if(typeof copy!=="undefined"){target[name]=copy}}}}}return target}},{}],10:[function(_dereq_,module,exports){void function(root,factory){if(typeof define==="function"&&define.amd){define(factory)}else if(typeof exports==="object"){module.exports=factory()}else{root.resolveUrl=factory()}}(this,function(){function resolveUrl(){var numUrls=arguments.length;if(numUrls===0){throw new Error("resolveUrl requires at least one argument; got none.")}var base=document.createElement("base");base.href=arguments[0];if(numUrls===1){return base.href}var head=document.getElementsByTagName("head")[0];head.insertBefore(base,head.firstChild);var a=document.createElement("a");var resolved;for(var index=1;index<numUrls;index++){a.href=arguments[index];resolved=a.href;base.href=resolved}head.removeChild(base);return resolved}return resolveUrl})},{}]},{},[7])(7)});
//# sourceMappingURL=tus.min.js.map

@@ -59,3 +59,4 @@ // Generated by Babel

overridePatchMethod: false,
retryDelays: null
retryDelays: null,
removeFingerprintOnSuccess: false
};

@@ -353,2 +354,9 @@

if (_this2._size === 0) {
// Nothing to upload and file was successfully created
_this2._emitSuccess();
_this2._source.close();
return;
}
if (_this2.options.resume) {

@@ -506,2 +514,8 @@ Storage.setItem(_this2._fingerprint, _this2.url);

if (offset == _this4._size) {
if (_this4.options.removeFingerprintOnSuccess && _this4.options.resume) {
// Remove stored fingerprint and corresponding endpoint. This causes
// new upload of the same file must be treated as a different file.
Storage.removeItem(_this4._fingerprint);
}
// Yay, finally done :)

@@ -508,0 +522,0 @@ _this4._emitSuccess();

@@ -6,2 +6,3 @@ /* global window */

const {defaultOptions} = Upload;
let isSupported;

@@ -12,3 +13,3 @@ if (typeof window !== "undefined") {

var isSupported = (
isSupported = (
XMLHttpRequest &&

@@ -20,3 +21,3 @@ Blob &&

// Node.js environment using http module
var isSupported = true;
isSupported = true;
}

@@ -23,0 +24,0 @@

@@ -27,3 +27,4 @@ /* global window */

overridePatchMethod: false,
retryDelays: null
retryDelays: null,
removeFingerprintOnSuccess: false
};

@@ -300,2 +301,9 @@

if (this._size === 0) {
// Nothing to upload and file was successfully created
this._emitSuccess();
this._source.close();
return;
}
if (this.options.resume) {

@@ -443,2 +451,8 @@ Storage.setItem(this._fingerprint, this.url);

if (offset == this._size) {
if (this.options.removeFingerprintOnSuccess && this.options.resume) {
// Remove stored fingerprint and corresponding endpoint. This causes
// new upload of the same file must be treated as a different file.
Storage.removeItem(this._fingerprint);
}
// Yay, finally done :)

@@ -445,0 +459,0 @@ this._emitSuccess();

{
"name": "tus-js-client",
"version": "1.5.0",
"version": "1.5.1",
"description": "A pure JavaScript client for the tus resumable upload protocol",

@@ -36,16 +36,16 @@ "main": "lib.es5/index.js",

"devDependencies": {
"axios": "^0.18.0",
"babel-cli": "^6.6.5",
"babel-eslint": "^4.1.8",
"babel-preset-es2015": "^6.1.18",
"babelify": "^7.3.0",
"browserify": "^12.0.0",
"colors": "^1.1.2",
"browserstack": "^1.5.0",
"browserstack-runner": "^0.7.0",
"derequire": "^2.0.3",
"eslint": "^1.6.0",
"eslint": "^4.19.1",
"exorcist": "^0.4.0",
"get-saucelabs-browsers": "^1.0.1",
"jasmine": "^2.5.2",
"jasmine-ajax": "^3.2.0",
"jasmine-core": "^2.4.1",
"phantomjs-prebuilt": "^2.1.15",
"phantomjs-prebuilt": "^2.1.16",
"replace": "^0.3.0",

@@ -66,4 +66,4 @@ "temp": "^0.8.3",

"test": "./bin/test",
"phantom-test": "phantomjs --ssl-protocol=any bin/phantom-jasmine.js",
"sauce-test": "node bin/sauce-jasmine.js http://localhost:8081/test/SpecRunner.html",
"phantom-test": "phantomjs --local-to-remote-url-access=yes bin/phantom-jasmine.js",
"browserstack-test": "node bin/browserstack-jasmine.js",
"node-test": "cd test; jasmine",

@@ -70,0 +70,0 @@ "minify": "uglifyjs ./dist/tus.js -o ./dist/tus.min.js --in-source-map ./dist/tus.js.map --source-map ./dist/tus.min.js.map --source-map-url tus.min.js.map",

@@ -60,8 +60,26 @@ # tus-js-client [![Build Status](https://travis-ci.org/tus/tus-js-client.svg?branch=master)](https://travis-ci.org/tus/tus-js-client)

[![Sauce Test Status](https://saucelabs.com/browser-matrix/marius_transloadit.svg)](https://saucelabs.com/u/marius_transloadit)
<a href="https://browserstack.com">
<img alt="BrowserStack logo" src="demo/browserstack.png" align="right" />
</a>
We use localStorage, XMLHttpRequest2, the File API and Blob API. About 85% of
today's users should be able to use this software, calculated using
[iwanttouse.com](http://www.iwanttouse.com/#namevalue-storage,xhr2,fileapi,blobbuilder).
tus-js-client is tested and known to support following browsers:
* Internet Explorer 10+
* Microsoft Edge 12+
* Mozilla Firefox 14+
* Google Chrome 20+
* Safari 6+
* Opera 12.1+
* iOS 6.0+
* Android 5.0+
Support in other browsers is *very likely* but has not been confirimed yet.
Since we only use Web Storage, XMLHttpRequest2, the File API and Blob API,
more than 95% of today's users should be able to use tus-js-client.
Compatability between browsers is continuously ensured by automated tests
in the corresponding browsers on [BrowserStack](https://browserstack.com),
who provide their great service glady for Open Source project for free.
## Node compatibility

@@ -202,2 +220,8 @@

[Automated Retries](#automated-retries) section.
* `removeFingerprintOnSuccess = false`: a boolean indicating if the fingerprint
in the storage will be removed when the upload is successfully completed.
This value is `false` for not breaking the previous API contract, but we strongly
suggest to set it to `true` to avoid cluttering the storage space. The effect is
that if the same file is uploaded again, it will create an entirely new upload.
Furthermore, this option will only change behaviour if `resume` is set to `true`.

@@ -204,0 +228,0 @@ ### new tus.Upload(file, options)

@@ -1,2 +0,2 @@

/* global FakeBlob tus */
/* global Blob tus */

@@ -18,3 +18,3 @@ describe("tus", function () {

var file = new FakeBlob("hello world".split(""));
var file = new Blob("hello world".split(""));
var options = {

@@ -67,4 +67,3 @@ endpoint: "http://tus.io/uploads",

it("should store upload urls", function (done) {
var file = new FakeBlob("hello world".split(""));
describe("storing of upload urls", function () {
var options = {

@@ -74,23 +73,53 @@ endpoint: "http://tus.io/uploads",

};
spyOn(options, "fingerprint").and.returnValue("fingerprinted");
var startUpload = function () {
var file = new Blob("hello world".split(""));
spyOn(options, "fingerprint").and.returnValue("fingerprinted");
var upload = new tus.Upload(file, options);
upload.start();
var upload = new tus.Upload(file, options);
upload.start();
expect(options.fingerprint).toHaveBeenCalledWith(file, upload.options);
expect(options.fingerprint).toHaveBeenCalledWith(file, upload.options);
var req = jasmine.Ajax.requests.mostRecent();
expect(req.url).toBe("http://tus.io/uploads");
expect(req.method).toBe("POST");
var req = jasmine.Ajax.requests.mostRecent();
expect(req.url).toBe("http://tus.io/uploads");
expect(req.method).toBe("POST");
req.respondWith({
status: 201,
responseHeaders: {
Location: "/uploads/blargh"
}
req.respondWith({
status: 201,
responseHeaders: {
Location: "/uploads/blargh"
}
});
expect(upload.url).toBe("http://tus.io/uploads/blargh");
};
var finishUpload = function () {
var req = jasmine.Ajax.requests.mostRecent();
expect(req.url).toBe("http://tus.io/uploads/blargh");
expect(req.method).toBe("PATCH");
req.respondWith({
status: 204,
responseHeaders: {
"Upload-Offset": 11
}
});
};
it("should store and retain with default options", function (done) {
startUpload();
expect(localStorage.getItem("fingerprinted")).toBe("http://tus.io/uploads/blargh");
finishUpload();
expect(localStorage.getItem("fingerprinted")).toBe("http://tus.io/uploads/blargh");
done();
});
expect(upload.url).toBe("http://tus.io/uploads/blargh");
expect(localStorage.getItem("fingerprinted")).toBe("http://tus.io/uploads/blargh");
done();
it("should store and remove with option removeFingerprintOnSuccess set", function (done) {
options.removeFingerprintOnSuccess = true;
startUpload();
expect(localStorage.getItem("fingerprinted")).toBe("http://tus.io/uploads/blargh");
finishUpload();
expect(localStorage.getItem("fingerprinted")).toBe(null);
done();
});
});

@@ -101,3 +130,3 @@

var file = new FakeBlob("hello world".split(""));
var file = new Blob("hello world".split(""));
var options = {

@@ -125,3 +154,3 @@ endpoint: "http://tus.io/uploads",

it("should add the request's body to errors", function () {
var file = new FakeBlob("hello world".split(""));
var file = new Blob("hello world".split(""));
var err;

@@ -128,0 +157,0 @@ var options = {

@@ -1,9 +0,27 @@

/* global FakeBlob tus */
var isBrowser = typeof window !== "undefined";
var isNode = !isBrowser;
if (isNode) {
// In the browser environment, Axios and tus are provided directly from
// SpecRunner.html, but in Node we have to require them.
var axios = require("axios");
var tus = require("../../");
// These tests use browser's Blob constructor. To make these tests also
// work in Node.js, we make it an alias for Buffer, which have the same
// API for our use cases.
var Blob = Buffer;
}
// Set Jasmine's timeout for a single test to 10s
jasmine.DEFAULT_TIMEOUT_INTERVAL = 10 * 1000;
describe("tus", function () {
describe("#isSupported", function () {
it("should be true", function () {
expect(tus.isSupported).toBe(true);
});
});
describe("#Upload", function () {
beforeEach(function () {

@@ -29,3 +47,3 @@ jasmine.Ajax.install();

it("should throw if no endpoint and upload URL is provided", function () {
var file = new FakeBlob("hello world".split(""));
var file = new Blob("hello world".split(""));
var upload = new tus.Upload(file);

@@ -36,3 +54,3 @@ expect(upload.start.bind(upload)).toThrowError("tus: neither an endpoint or an upload URL is provided");

it("should upload a file", function (done) {
var file = new FakeBlob("hello world".split(""));
var file = new Blob("hello world".split(""));
var options = {

@@ -103,3 +121,3 @@ endpoint: "http://tus.io/uploads",

it("should create an upload if resuming fails", function (done) {
var file = new FakeBlob("hello world".split(""));
var file = new Blob("hello world".split(""));
var options = {

@@ -133,3 +151,3 @@ endpoint: "http://tus.io/uploads",

it("should throw an error if resuming fails and no endpoint is provided", function (done) {
var file = new FakeBlob("hello world".split(""));
var file = new Blob("hello world".split(""));
var options = {

@@ -158,3 +176,3 @@ uploadUrl: "http://tus.io/uploads/resuming",

it("should resolve relative URLs", function () {
var file = new FakeBlob("hello world".split(""));
var file = new Blob("hello world".split(""));
var options = {

@@ -193,3 +211,3 @@ endpoint: "http://master.tus.io:1080/files/"

it("should upload a file in chunks", function (done) {
var file = new FakeBlob("hello world".split(""));
var file = new Blob("hello world".split(""));
var options = {

@@ -262,3 +280,3 @@ endpoint: "http://tus.io/uploads",

it("should add the original request to errors", function () {
var file = new FakeBlob("hello world".split(""));
var file = new Blob("hello world".split(""));
var err;

@@ -293,4 +311,32 @@ var options = {

it("should only create an upload for empty files", function (done) {
var file = new Blob([]);
var options = {
endpoint: "http://tus.io/uploads",
onSuccess: function () {}
};
spyOn(options, "onSuccess");
var upload = new tus.Upload(file, options);
upload.start();
var req = jasmine.Ajax.requests.mostRecent();
expect(req.url).toBe("http://tus.io/uploads");
expect(req.method).toBe("POST");
expect(req.requestHeaders["Tus-Resumable"]).toBe("1.0.0");
expect(req.requestHeaders["Upload-Length"]).toBe(0);
req.respondWith({
status: 201,
responseHeaders: {
"Location": "http://tus.io/uploads/empty"
}
});
expect(options.onSuccess).toHaveBeenCalled();
done();
});
it("should not resume a finished upload", function (done) {
var file = new FakeBlob("hello world".split(""));
var file = new Blob("hello world".split(""));
var options = {

@@ -327,3 +373,3 @@ endpoint: "http://tus.io/uploads",

it("should resume an upload from a specified url", function (done) {
var file = new FakeBlob("hello world".split(""));
var file = new Blob("hello world".split(""));
var options = {

@@ -377,3 +423,3 @@ endpoint: "http://tus.io/uploads",

it("should resume a previously started upload", function (done) {
var file = new FakeBlob("hello world".split(""));
var file = new Blob("hello world".split(""));
var options = {

@@ -443,3 +489,3 @@ resume: false,

it("should override the PATCH method", function (done) {
var file = new FakeBlob("hello world".split(""));
var file = new Blob("hello world".split(""));
var options = {

@@ -485,3 +531,3 @@ endpoint: "http://tus.io/uploads",

it("should emit an error if an upload is locked", function (done) {
var file = new FakeBlob("hello world".split(""));
var file = new Blob("hello world".split(""));
var options = {

@@ -511,3 +557,3 @@ endpoint: "http://tus.io/uploads",

it("should emit an error if no Location header is presented", function (done) {
var file = new FakeBlob("hello world".split(""));
var file = new Blob("hello world".split(""));
var options = {

@@ -537,3 +583,3 @@ endpoint: "http://tus.io/uploads",

it("should throw if retryDelays is not an array", function () {
var file = new FakeBlob("hello world".split(""));
var file = new Blob("hello world".split(""));
var upload = new tus.Upload(file, {

@@ -547,3 +593,3 @@ endpoint: "http://endpoint/",

it("should retry the upload", function (done) {
var file = new FakeBlob("hello world".split(""));
var file = new Blob("hello world".split(""));
var options = {

@@ -597,3 +643,3 @@ endpoint: "http://tus.io/files/",

it("should not retry if the error has not been caused by a request", function () {
var file = new FakeBlob("hello world".split(""));
var file = new Blob("hello world".split(""));
var options = {

@@ -623,3 +669,3 @@ endpoint: "http://tus.io/files/",

it("should stop retrying after all delays have been used", function (done) {
var file = new FakeBlob("hello world".split(""));
var file = new Blob("hello world".split(""));
var options = {

@@ -664,3 +710,3 @@ endpoint: "http://tus.io/files/",

it("should stop retrying when the abort function is called", function (done) {
var file = new FakeBlob("hello world".split(""));
var file = new Blob("hello world".split(""));
var options = {

@@ -697,3 +743,3 @@ endpoint: "http://tus.io/files/",

var upload;
var file = new FakeBlob("hello world".split(""));
var file = new Blob("hello world".split(""));
var options = {

@@ -742,3 +788,3 @@ endpoint: "http://tus.io/files/",

it("should stop upload when the abort function is called during the POST request", function (done) {
var file = new FakeBlob("hello world".split(""));
var file = new Blob("hello world".split(""));
var options = {

@@ -775,3 +821,3 @@ endpoint: "http://tus.io/files/",

it("should reset the attempt counter if an upload proceeds", function (done) {
var file = new FakeBlob("hello world".split(""));
var file = new Blob("hello world".split(""));
var options = {

@@ -872,2 +918,71 @@ endpoint: "http://tus.io/files/",

});
it("should upload to a real tus server", function (done) {
var file = isNode
? Buffer.from("hello world")
: new Blob("hello world".split(""));
var options = {
resume: false,
endpoint: "https://master.tus.io/files/",
metadata: {
nonlatin: "słońce",
number: 100,
filename: "hello.txt",
filetype: "text/plain"
},
onSuccess: function () {
expect(upload.url).toMatch(/^https:\/\/master\.tus\.io\/files\//);
console.log("Upload URL:", upload.url); // eslint-disable-line no-console
validateUploadContent(upload, done);
},
onError: function (err) {
done.fail(err);
}
};
var upload = new tus.Upload(file, options);
upload.start();
});
});
function validateUploadContent(upload, done) {
axios.get(upload.url)
.then(function (res) {
expect(res.status).toBe(200);
expect(res.data).toBe("hello world");
validateUploadMetadata(upload, done);
})
.catch(done.fail);
}
function validateUploadMetadata(upload, done) {
axios.head(upload.url, {
headers: {
"Tus-Resumable": "1.0.0"
}
}).then(function (res) {
expect(res.status).toBe(200);
expect(res.data).toBe("");
expect(res.headers["tus-resumable"]).toBe("1.0.0");
expect(res.headers["upload-offset"]).toBe("11");
expect(res.headers["upload-length"]).toBe("11");
// The values in the Upload-Metadata header may not be in^the same
// order as we submitted them (the specification does not require
// that). Therefore, we split the values and verify that each one
// is present.
var metadataStr = res.headers["upload-metadata"];
expect(metadataStr).toBeTruthy();
var metadata = metadataStr.split(",");
expect(metadata).toContain("filename aGVsbG8udHh0");
expect(metadata).toContain("filetype dGV4dC9wbGFpbg==");
expect(metadata).toContain("nonlatin c8WCb8WEY2U=");
expect(metadata).toContain("number MTAw");
expect(metadata.length).toBe(4);
done();
})
.catch(done.fail);
}

@@ -1,13 +0,7 @@

var tus = require("../../");
var stream = require("stream");
var temp = require("temp");
var fs = require("fs");
const tus = require("../../");
const stream = require("stream");
const temp = require("temp");
const fs = require("fs");
describe("tus", function () {
describe("#isSupported", function () {
it("should be true", function () {
expect(tus.isSupported).toBe(true);
});
});
describe("#canStoreURLs", function () {

@@ -162,1 +156,2 @@ it("should be false", function () {

}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc