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

@mux/upchunk

Package Overview
Dependencies
Maintainers
13
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mux/upchunk - npm Package Compare versions

Comparing version 1.0.6 to 1.0.8

2

dist/upchunk.js

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

!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.UpChunk=t():e.UpChunk=t()}(window,function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";var r=this&&this.__assign||function(){return(r=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};t.__esModule=!0;var o=n(1),i=[200,201,202,204,308],s=[408,502,503,504],u=function(){function e(e){var t=this;this.endpoint=e.endpoint,this.file=e.file,this.headers=e.headers||{},this.chunkSize=e.chunkSize||5120,this.attempts=e.attempts||5,this.delayBeforeAttempt=e.delayBeforeAttempt||1,this.chunkCount=0,this.chunkByteSize=1024*this.chunkSize,this.totalChunks=Math.ceil(this.file.size/this.chunkByteSize),this.attemptCount=0,this.offline=!1,this.paused=!1,this.reader=new FileReader,this.eventTarget=new o.EventTarget,this.validateOptions(),this.getEndpoint().then(function(){return t.sendChunks()}),window.addEventListener("online",function(){t.offline&&(t.offline=!1,t.dispatch("online"),t.sendChunks())}),window.addEventListener("offline",function(){t.offline=!0,t.dispatch("offline")})}return e.prototype.on=function(e,t){this.eventTarget.addEventListener(e,t)},e.prototype.pause=function(){this.paused=!0},e.prototype.resume=function(){this.paused&&(this.paused=!1,this.sendChunks())},e.prototype.dispatch=function(e,t){var n=new CustomEvent(e,{detail:t});this.eventTarget.dispatchEvent(n)},e.prototype.validateOptions=function(){if(!this.endpoint||"function"!=typeof this.endpoint&&"string"!=typeof this.endpoint)throw new TypeError("endpoint must be defined as a string or a function that returns a promise");if(!(this.file instanceof File))throw new TypeError("file must be a File object");if(this.headers&&"object"!=typeof this.headers)throw new TypeError("headers must be null or an object");if(this.chunkSize&&("number"!=typeof this.chunkSize||this.chunkSize<=0||this.chunkSize%256!=0))throw new TypeError("chunkSize must be a positive number in multiples of 256");if(this.attempts&&("number"!=typeof this.attempts||this.attempts<=0))throw new TypeError("retries must be a positive number");if(this.delayBeforeAttempt&&("number"!=typeof this.delayBeforeAttempt||this.delayBeforeAttempt<0))throw new TypeError("delayBeforeAttempt must be a positive number")},e.prototype.getEndpoint=function(){var e=this;return"string"==typeof this.endpoint?(this.endpointValue=this.endpoint,Promise.resolve(this.endpoint)):this.endpoint(this.file).then(function(t){return e.endpointValue=t,e.endpointValue})},e.prototype.getChunk=function(){var e=this;return new Promise(function(t){var n=1===e.totalChunks?e.file.size:e.chunkByteSize,r=n*e.chunkCount;e.reader.onload=function(){null!==e.reader.result&&(e.chunk=new Blob([e.reader.result],{type:"application/octet-stream"})),t()},e.reader.readAsArrayBuffer(e.file.slice(r,r+n))})},e.prototype.sendChunk=function(){var e=this.chunkCount*this.chunkByteSize,t=e+this.chunk.size-1,n=r({},this.headers,{"Content-Type":this.file.type,"Content-Length":this.chunk.size,"Content-Range":"bytes "+e+"-"+t+"/"+this.file.size});return this.dispatch("attempt",{chunkNumber:this.chunkCount,chunkSize:this.chunk.size}),fetch(this.endpointValue,{headers:n,method:"PUT",body:this.chunk})},e.prototype.manageRetries=function(){var e=this;if(this.attemptCount<this.attempts)return this.attemptCount=this.attemptCount+1,setTimeout(function(){return e.sendChunks()},1e3*this.delayBeforeAttempt),void this.dispatch("attemptFailure",{message:"An error occured uploading chunk "+this.chunkCount+". "+(this.attempts-this.attemptCount)+" retries left.",chunkNumber:this.chunkCount,attemptsLeft:this.attempts-this.attemptCount});this.dispatch("error",{message:"An error occured uploading chunk "+this.chunkCount+". No more retries, stopping upload",chunk:this.chunkCount,attempts:this.attemptCount})},e.prototype.sendChunks=function(){var e=this;this.paused||this.offline||this.getChunk().then(function(){return e.sendChunk()}).then(function(t){if(i.includes(t.status)){e.chunkCount=e.chunkCount+1,e.chunkCount<e.totalChunks?e.sendChunks():e.dispatch("success");var n=Math.round(100/e.totalChunks*e.chunkCount);e.dispatch("progress",n)}else if(s.includes(t.status)){if(e.paused||e.offline)return;e.manageRetries()}else{if(e.paused||e.offline)return;e.dispatch("error",{message:"Server responded with "+t.status+". Stopping upload.",chunkNumber:e.chunkCount,attempts:e.attemptCount})}}).catch(function(t){e.paused||e.offline||e.manageRetries()})},e}();t.UpChunk=u,t.createUpload=function(e){return new u(e)}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const r=new WeakMap,o=new WeakMap;function i(e){const t=r.get(e);return console.assert(null!=t,"'this' is expected an Event object, but got",e),t}function s(e){null==e.passiveListener?e.event.cancelable&&(e.canceled=!0,"function"==typeof e.event.preventDefault&&e.event.preventDefault()):"undefined"!=typeof console&&"function"==typeof console.error&&console.error("Unable to preventDefault inside passive event listener invocation.",e.passiveListener)}function u(e,t){r.set(this,{eventTarget:e,event:t,eventPhase:2,currentTarget:e,canceled:!1,stopped:!1,immediateStopped:!1,passiveListener:null,timeStamp:t.timeStamp||Date.now()}),Object.defineProperty(this,"isTrusted",{value:!1,enumerable:!0});const n=Object.keys(t);for(let e=0;e<n.length;++e){const t=n[e];t in this||Object.defineProperty(this,t,a(t))}}function a(e){return{get(){return i(this).event[e]},set(t){i(this).event[e]=t},configurable:!0,enumerable:!0}}function l(e){return{value(){const t=i(this).event;return t[e].apply(t,arguments)},configurable:!0,enumerable:!0}}function p(e){if(null==e||e===Object.prototype)return u;let t=o.get(e);return null==t&&(t=function(e,t){const n=Object.keys(t);if(0===n.length)return e;function r(t,n){e.call(this,t,n)}r.prototype=Object.create(e.prototype,{constructor:{value:r,configurable:!0,writable:!0}});for(let o=0;o<n.length;++o){const i=n[o];if(!(i in e.prototype)){const e="function"==typeof Object.getOwnPropertyDescriptor(t,i).value;Object.defineProperty(r.prototype,i,e?l(i):a(i))}}return r}(p(Object.getPrototypeOf(e)),e),o.set(e,t)),t}function c(e){return i(e).immediateStopped}function f(e,t){i(e).passiveListener=t}u.prototype={get type(){return i(this).event.type},get target(){return i(this).eventTarget},get currentTarget(){return i(this).currentTarget},composedPath(){const e=i(this).currentTarget;return null==e?[]:[e]},get NONE(){return 0},get CAPTURING_PHASE(){return 1},get AT_TARGET(){return 2},get BUBBLING_PHASE(){return 3},get eventPhase(){return i(this).eventPhase},stopPropagation(){const e=i(this);e.stopped=!0,"function"==typeof e.event.stopPropagation&&e.event.stopPropagation()},stopImmediatePropagation(){const e=i(this);e.stopped=!0,e.immediateStopped=!0,"function"==typeof e.event.stopImmediatePropagation&&e.event.stopImmediatePropagation()},get bubbles(){return Boolean(i(this).event.bubbles)},get cancelable(){return Boolean(i(this).event.cancelable)},preventDefault(){s(i(this))},get defaultPrevented(){return i(this).canceled},get composed(){return Boolean(i(this).event.composed)},get timeStamp(){return i(this).timeStamp},get srcElement(){return i(this).eventTarget},get cancelBubble(){return i(this).stopped},set cancelBubble(e){if(!e)return;const t=i(this);t.stopped=!0,"boolean"==typeof t.event.cancelBubble&&(t.event.cancelBubble=!0)},get returnValue(){return!i(this).canceled},set returnValue(e){e||s(i(this))},initEvent(){}},Object.defineProperty(u.prototype,"constructor",{value:u,configurable:!0,writable:!0}),"undefined"!=typeof window&&void 0!==window.Event&&(Object.setPrototypeOf(u.prototype,window.Event.prototype),o.set(window.Event.prototype,u));const h=new WeakMap,d=3;function y(e){return null!==e&&"object"==typeof e}function v(e){const t=h.get(e);if(null==t)throw new TypeError("'this' is expected an EventTarget object, but got another value.");return t}function b(e,t){Object.defineProperty(e,`on${t}`,function(e){return{get(){let t=v(this).get(e);for(;null!=t;){if(t.listenerType===d)return t.listener;t=t.next}return null},set(t){"function"==typeof t||y(t)||(t=null);const n=v(this);let r=null,o=n.get(e);for(;null!=o;)o.listenerType===d?null!==r?r.next=o.next:null!==o.next?n.set(e,o.next):n.delete(e):r=o,o=o.next;if(null!==t){const o={listener:t,listenerType:d,passive:!1,once:!1,next:null};null===r?n.set(e,o):r.next=o}},configurable:!0,enumerable:!0}}(t))}function g(e){function t(){m.call(this)}t.prototype=Object.create(m.prototype,{constructor:{value:t,configurable:!0,writable:!0}});for(let n=0;n<e.length;++n)b(t.prototype,e[n]);return t}function m(){if(!(this instanceof m)){if(1===arguments.length&&Array.isArray(arguments[0]))return g(arguments[0]);if(arguments.length>0){const e=new Array(arguments.length);for(let t=0;t<arguments.length;++t)e[t]=arguments[t];return g(e)}throw new TypeError("Cannot call a class as a function")}h.set(this,new Map)}m.prototype={addEventListener(e,t,n){if(null==t)return;if("function"!=typeof t&&!y(t))throw new TypeError("'listener' should be a function or an object.");const r=v(this),o=y(n),i=(o?Boolean(n.capture):Boolean(n))?1:2,s={listener:t,listenerType:i,passive:o&&Boolean(n.passive),once:o&&Boolean(n.once),next:null};let u=r.get(e);if(void 0===u)return void r.set(e,s);let a=null;for(;null!=u;){if(u.listener===t&&u.listenerType===i)return;a=u,u=u.next}a.next=s},removeEventListener(e,t,n){if(null==t)return;const r=v(this),o=(y(n)?Boolean(n.capture):Boolean(n))?1:2;let i=null,s=r.get(e);for(;null!=s;){if(s.listener===t&&s.listenerType===o)return void(null!==i?i.next=s.next:null!==s.next?r.set(e,s.next):r.delete(e));i=s,s=s.next}},dispatchEvent(e){if(null==e||"string"!=typeof e.type)throw new TypeError('"event.type" should be a string.');const t=v(this),n=e.type;let r=t.get(n);if(null==r)return!0;const o=function(e,t){return new(p(Object.getPrototypeOf(t)))(e,t)}(this,e);let s=null;for(;null!=r;){if(r.once?null!==s?s.next=r.next:null!==r.next?t.set(n,r.next):t.delete(n):s=r,f(o,r.passive?r.listener:null),"function"==typeof r.listener)try{r.listener.call(this,o)}catch(e){"undefined"!=typeof console&&"function"==typeof console.error&&console.error(e)}else r.listenerType!==d&&"function"==typeof r.listener.handleEvent&&r.listener.handleEvent(o);if(c(o))break;r=r.next}return f(o,null),function(e,t){i(e).eventPhase=t}(o,0),function(e,t){i(e).currentTarget=t}(o,null),!o.defaultPrevented}},Object.defineProperty(m.prototype,"constructor",{value:m,configurable:!0,writable:!0}),"undefined"!=typeof window&&void 0!==window.EventTarget&&Object.setPrototypeOf(m.prototype,window.EventTarget.prototype),t.defineEventAttribute=b,t.EventTarget=m,t.default=m,e.exports=m,e.exports.EventTarget=e.exports.default=m,e.exports.defineEventAttribute=b}])});
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.UpChunk=t():e.UpChunk=t()}(this,function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";var r=this&&this.__assign||function(){return(r=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};t.__esModule=!0;var o=n(1),i=[200,201,202,204,308],s=[408,502,503,504],u=function(){function e(e){var t=this;this.endpoint=e.endpoint,this.file=e.file,this.headers=e.headers||{},this.chunkSize=e.chunkSize||5120,this.attempts=e.attempts||5,this.delayBeforeAttempt=e.delayBeforeAttempt||1,this.chunkCount=0,this.chunkByteSize=1024*this.chunkSize,this.totalChunks=Math.ceil(this.file.size/this.chunkByteSize),this.attemptCount=0,this.offline=!1,this.paused=!1,this.reader=new FileReader,this.eventTarget=new o.EventTarget,this.validateOptions(),this.getEndpoint().then(function(){return t.sendChunks()}),"undefined"!=typeof window&&(window.addEventListener("online",function(){t.offline&&(t.offline=!1,t.dispatch("online"),t.sendChunks())}),window.addEventListener("offline",function(){t.offline=!0,t.dispatch("offline")}))}return e.prototype.on=function(e,t){this.eventTarget.addEventListener(e,t)},e.prototype.pause=function(){this.paused=!0},e.prototype.resume=function(){this.paused&&(this.paused=!1,this.sendChunks())},e.prototype.dispatch=function(e,t){var n=new CustomEvent(e,{detail:t});this.eventTarget.dispatchEvent(n)},e.prototype.validateOptions=function(){if(!this.endpoint||"function"!=typeof this.endpoint&&"string"!=typeof this.endpoint)throw new TypeError("endpoint must be defined as a string or a function that returns a promise");if(!(this.file instanceof File))throw new TypeError("file must be a File object");if(this.headers&&"object"!=typeof this.headers)throw new TypeError("headers must be null or an object");if(this.chunkSize&&("number"!=typeof this.chunkSize||this.chunkSize<=0||this.chunkSize%256!=0))throw new TypeError("chunkSize must be a positive number in multiples of 256");if(this.attempts&&("number"!=typeof this.attempts||this.attempts<=0))throw new TypeError("retries must be a positive number");if(this.delayBeforeAttempt&&("number"!=typeof this.delayBeforeAttempt||this.delayBeforeAttempt<0))throw new TypeError("delayBeforeAttempt must be a positive number")},e.prototype.getEndpoint=function(){var e=this;return"string"==typeof this.endpoint?(this.endpointValue=this.endpoint,Promise.resolve(this.endpoint)):this.endpoint(this.file).then(function(t){return e.endpointValue=t,e.endpointValue})},e.prototype.getChunk=function(){var e=this;return new Promise(function(t){var n=1===e.totalChunks?e.file.size:e.chunkByteSize,r=n*e.chunkCount;e.reader.onload=function(){null!==e.reader.result&&(e.chunk=new Blob([e.reader.result],{type:"application/octet-stream"})),t()},e.reader.readAsArrayBuffer(e.file.slice(r,r+n))})},e.prototype.sendChunk=function(){var e=this.chunkCount*this.chunkByteSize,t=e+this.chunk.size-1,n=r({},this.headers,{"Content-Type":this.file.type,"Content-Length":this.chunk.size,"Content-Range":"bytes "+e+"-"+t+"/"+this.file.size});return this.dispatch("attempt",{chunkNumber:this.chunkCount,chunkSize:this.chunk.size}),fetch(this.endpointValue,{headers:n,method:"PUT",body:this.chunk})},e.prototype.manageRetries=function(){var e=this;if(this.attemptCount<this.attempts)return this.attemptCount=this.attemptCount+1,setTimeout(function(){return e.sendChunks()},1e3*this.delayBeforeAttempt),void this.dispatch("attemptFailure",{message:"An error occured uploading chunk "+this.chunkCount+". "+(this.attempts-this.attemptCount)+" retries left.",chunkNumber:this.chunkCount,attemptsLeft:this.attempts-this.attemptCount});this.dispatch("error",{message:"An error occured uploading chunk "+this.chunkCount+". No more retries, stopping upload",chunk:this.chunkCount,attempts:this.attemptCount})},e.prototype.sendChunks=function(){var e=this;this.paused||this.offline||this.getChunk().then(function(){return e.sendChunk()}).then(function(t){if(i.includes(t.status)){e.chunkCount=e.chunkCount+1,e.chunkCount<e.totalChunks?e.sendChunks():e.dispatch("success");var n=Math.round(100/e.totalChunks*e.chunkCount);e.dispatch("progress",n)}else if(s.includes(t.status)){if(e.paused||e.offline)return;e.manageRetries()}else{if(e.paused||e.offline)return;e.dispatch("error",{message:"Server responded with "+t.status+". Stopping upload.",chunkNumber:e.chunkCount,attempts:e.attemptCount})}}).catch(function(t){e.paused||e.offline||e.manageRetries()})},e}();t.UpChunk=u,t.createUpload=function(e){return new u(e)}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const r=new WeakMap,o=new WeakMap;function i(e){const t=r.get(e);return console.assert(null!=t,"'this' is expected an Event object, but got",e),t}function s(e){null==e.passiveListener?e.event.cancelable&&(e.canceled=!0,"function"==typeof e.event.preventDefault&&e.event.preventDefault()):"undefined"!=typeof console&&"function"==typeof console.error&&console.error("Unable to preventDefault inside passive event listener invocation.",e.passiveListener)}function u(e,t){r.set(this,{eventTarget:e,event:t,eventPhase:2,currentTarget:e,canceled:!1,stopped:!1,immediateStopped:!1,passiveListener:null,timeStamp:t.timeStamp||Date.now()}),Object.defineProperty(this,"isTrusted",{value:!1,enumerable:!0});const n=Object.keys(t);for(let e=0;e<n.length;++e){const t=n[e];t in this||Object.defineProperty(this,t,a(t))}}function a(e){return{get(){return i(this).event[e]},set(t){i(this).event[e]=t},configurable:!0,enumerable:!0}}function l(e){return{value(){const t=i(this).event;return t[e].apply(t,arguments)},configurable:!0,enumerable:!0}}function p(e){if(null==e||e===Object.prototype)return u;let t=o.get(e);return null==t&&(t=function(e,t){const n=Object.keys(t);if(0===n.length)return e;function r(t,n){e.call(this,t,n)}r.prototype=Object.create(e.prototype,{constructor:{value:r,configurable:!0,writable:!0}});for(let o=0;o<n.length;++o){const i=n[o];if(!(i in e.prototype)){const e="function"==typeof Object.getOwnPropertyDescriptor(t,i).value;Object.defineProperty(r.prototype,i,e?l(i):a(i))}}return r}(p(Object.getPrototypeOf(e)),e),o.set(e,t)),t}function c(e){return i(e).immediateStopped}function f(e,t){i(e).passiveListener=t}u.prototype={get type(){return i(this).event.type},get target(){return i(this).eventTarget},get currentTarget(){return i(this).currentTarget},composedPath(){const e=i(this).currentTarget;return null==e?[]:[e]},get NONE(){return 0},get CAPTURING_PHASE(){return 1},get AT_TARGET(){return 2},get BUBBLING_PHASE(){return 3},get eventPhase(){return i(this).eventPhase},stopPropagation(){const e=i(this);e.stopped=!0,"function"==typeof e.event.stopPropagation&&e.event.stopPropagation()},stopImmediatePropagation(){const e=i(this);e.stopped=!0,e.immediateStopped=!0,"function"==typeof e.event.stopImmediatePropagation&&e.event.stopImmediatePropagation()},get bubbles(){return Boolean(i(this).event.bubbles)},get cancelable(){return Boolean(i(this).event.cancelable)},preventDefault(){s(i(this))},get defaultPrevented(){return i(this).canceled},get composed(){return Boolean(i(this).event.composed)},get timeStamp(){return i(this).timeStamp},get srcElement(){return i(this).eventTarget},get cancelBubble(){return i(this).stopped},set cancelBubble(e){if(!e)return;const t=i(this);t.stopped=!0,"boolean"==typeof t.event.cancelBubble&&(t.event.cancelBubble=!0)},get returnValue(){return!i(this).canceled},set returnValue(e){e||s(i(this))},initEvent(){}},Object.defineProperty(u.prototype,"constructor",{value:u,configurable:!0,writable:!0}),"undefined"!=typeof window&&void 0!==window.Event&&(Object.setPrototypeOf(u.prototype,window.Event.prototype),o.set(window.Event.prototype,u));const h=new WeakMap,d=3;function y(e){return null!==e&&"object"==typeof e}function v(e){const t=h.get(e);if(null==t)throw new TypeError("'this' is expected an EventTarget object, but got another value.");return t}function b(e,t){Object.defineProperty(e,`on${t}`,function(e){return{get(){let t=v(this).get(e);for(;null!=t;){if(t.listenerType===d)return t.listener;t=t.next}return null},set(t){"function"==typeof t||y(t)||(t=null);const n=v(this);let r=null,o=n.get(e);for(;null!=o;)o.listenerType===d?null!==r?r.next=o.next:null!==o.next?n.set(e,o.next):n.delete(e):r=o,o=o.next;if(null!==t){const o={listener:t,listenerType:d,passive:!1,once:!1,next:null};null===r?n.set(e,o):r.next=o}},configurable:!0,enumerable:!0}}(t))}function g(e){function t(){m.call(this)}t.prototype=Object.create(m.prototype,{constructor:{value:t,configurable:!0,writable:!0}});for(let n=0;n<e.length;++n)b(t.prototype,e[n]);return t}function m(){if(!(this instanceof m)){if(1===arguments.length&&Array.isArray(arguments[0]))return g(arguments[0]);if(arguments.length>0){const e=new Array(arguments.length);for(let t=0;t<arguments.length;++t)e[t]=arguments[t];return g(e)}throw new TypeError("Cannot call a class as a function")}h.set(this,new Map)}m.prototype={addEventListener(e,t,n){if(null==t)return;if("function"!=typeof t&&!y(t))throw new TypeError("'listener' should be a function or an object.");const r=v(this),o=y(n),i=(o?Boolean(n.capture):Boolean(n))?1:2,s={listener:t,listenerType:i,passive:o&&Boolean(n.passive),once:o&&Boolean(n.once),next:null};let u=r.get(e);if(void 0===u)return void r.set(e,s);let a=null;for(;null!=u;){if(u.listener===t&&u.listenerType===i)return;a=u,u=u.next}a.next=s},removeEventListener(e,t,n){if(null==t)return;const r=v(this),o=(y(n)?Boolean(n.capture):Boolean(n))?1:2;let i=null,s=r.get(e);for(;null!=s;){if(s.listener===t&&s.listenerType===o)return void(null!==i?i.next=s.next:null!==s.next?r.set(e,s.next):r.delete(e));i=s,s=s.next}},dispatchEvent(e){if(null==e||"string"!=typeof e.type)throw new TypeError('"event.type" should be a string.');const t=v(this),n=e.type;let r=t.get(n);if(null==r)return!0;const o=function(e,t){return new(p(Object.getPrototypeOf(t)))(e,t)}(this,e);let s=null;for(;null!=r;){if(r.once?null!==s?s.next=r.next:null!==r.next?t.set(n,r.next):t.delete(n):s=r,f(o,r.passive?r.listener:null),"function"==typeof r.listener)try{r.listener.call(this,o)}catch(e){"undefined"!=typeof console&&"function"==typeof console.error&&console.error(e)}else r.listenerType!==d&&"function"==typeof r.listener.handleEvent&&r.listener.handleEvent(o);if(c(o))break;r=r.next}return f(o,null),function(e,t){i(e).eventPhase=t}(o,0),function(e,t){i(e).currentTarget=t}(o,null),!o.defaultPrevented}},Object.defineProperty(m.prototype,"constructor",{value:m,configurable:!0,writable:!0}),"undefined"!=typeof window&&void 0!==window.EventTarget&&Object.setPrototypeOf(m.prototype,window.EventTarget.prototype),t.defineEventAttribute=b,t.EventTarget=m,t.default=m,e.exports=m,e.exports.EventTarget=e.exports.default=m,e.exports.defineEventAttribute=b}])});
//# sourceMappingURL=upchunk.js.map
{
"name": "@mux/upchunk",
"version": "1.0.6",
"version": "1.0.8",
"description": "Dead simple chunked file uploads using Fetch",

@@ -5,0 +5,0 @@ "main": "dist/upchunk.js",

@@ -0,1 +1,3 @@

![UpChunk](banner.png)
# UpChunk <img src="https://travis-ci.org/muxinc/upchunk.svg?branch=master" alt="Build Status">

@@ -60,2 +62,4 @@

```javascript
import * as UpChunk from '@mux/upchunk';
// Pretend you have an HTML page with an input like: <input id="picker" type="file" />

@@ -62,0 +66,0 @@ const picker = document.getElementById('picker');

@@ -67,16 +67,18 @@ import { EventTarget } from 'event-target-shim';

// trigger events when offline/back online
window.addEventListener('online', () => {
if (!this.offline) {
return;
}
if (typeof(window) !== 'undefined') {
window.addEventListener('online', () => {
if (!this.offline) {
return;
}
this.offline = false;
this.dispatch('online');
this.sendChunks();
});
this.offline = false;
this.dispatch('online');
this.sendChunks();
});
window.addEventListener('offline', () => {
this.offline = true;
this.dispatch('offline');
});
window.addEventListener('offline', () => {
this.offline = true;
this.dispatch('offline');
});
}
}

@@ -83,0 +85,0 @@

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