(()=>{function e(n,t,i){var s={upload:function(e,n){e={method:"POST",data:{filesize:e.size},file:e},e=_.assign({},e,n);return t.upload(e)},download:o,downloadAndSaveAs:function(e,n,t){return o(e,n,t).then(function(e){var n=e.getResponseHeader("Content-Type"),t=e.getResponseHeader("Content-Disposition"),e=new Blob([e.response],{type:n});window.saveAs(e,r(t))})},getFilenameFromContentDisposition:r,arrayBufferToBase64:function(e){for(var n="",t=new Uint8Array(e),o=t.byteLength,r=0;r<o;r++)n+=String.fromCharCode(t[r]);return btoa(n)},size:d};function o(t,e,o){var r=n.defer(),a=new XMLHttpRequest;return a.open("GET",e,!0),a.responseType="arraybuffer",a.onload=function(){200===a.status?r.resolve(a):r.reject(a)},a.onprogress=function(e){var n;_.isUndefined(e.loaded)||(n=_.isNumber(Number(o))&&o||d(t),_.isUndefined(n))||(e=e.loaded/n,r.notify(e))},_.forEach(i.headers(),function(e,n){e&&a.setRequestHeader(n,e)}),s.__test?s.__downloadDeferred=r:a.send(),r.promise}function d(e){var n=_.get(e,"length")||_.get(e,"size"),e=_.get(e,"_attachments"),e=_.get(e,_.first(_.keys(e)));return _.isUndefined(n)?_.get(e,"length"):n}function r(e){var n=/filename\*=UTF-8''([^;]+)(?:; ?|$)/i,t=null;return n.test(e)?t=decodeURIComponent(n.exec(e)[1]):0<=(n=e.toLowerCase().indexOf("filename="))&&(e=e.slice(n),null!=(n=/^filename=(["']?)([^;]*?[^\\])\1(?:; ?|$)/i.exec(e)))&&n[2]&&(t=n[2]),t}return s}e.$inject=["$q","$upload","c8yAuth"],angular.module("c8y.core").constant("utoa",function(e){return window.btoa(unescape(encodeURIComponent(e)))}).constant("atou",function(e){return decodeURIComponent(escape(window.atob(e)))}).constant("atob",function(e){return window.atob(e)}).factory("c8yBinaryCommon",e)})();