/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports"],(function(t){"use strict";const n=5e4;function e(t){const n=i(t);if(!n)return{isMultipart:!1,data:null};return{isMultipart:!0,data:n.boundary?o(t.data,n,0):null}}function r(t){const n=new Uint8Array(t,0,2e3),e=String.fromCharCode.apply(null,n),r=e.indexOf('boundary="'),o=-1!==r?e.slice(r+10,e.indexOf('"',r+10)):"";return{boundary:o,offset:-1!==r?r+12+o.length:0}}function o(t,e,r=0){const o="--"+e.boundary,i=[];for(let n=0;n<o.length;n++)i.push(o.charCodeAt(n));const l=[],s="\n--"+e.boundary+"--";for(let n=0;n<s.length;n++)l.push(s.charCodeAt(n));const c=[10],u=[13,10],f=[],d=i.length,h=new Uint8Array(t,r),g=Math.min(n,h.length-d);let p=0,y=0;for(let n=0;n<g;n++){for(y=0;y<d&&h[n+y]===i[y];y++);y===d&&(p&&f.push(a(h.subarray(p,n),e)),n+=d-1,h[n+1]===c[0]?n+=1:h[n+1]===u[0]&&h[n+2]===u[1]&&(n+=2),p=n+1)}const b=l.length;for(let n=h.length-b-10;n<h.length-b;n++){for(y=0;y<b&&h[n+y]===l[y];y++);if(y===b){f.push(a(h.subarray(p,n),e));break}}return f}function i(t){var n,e;const r=null==(n=t.getHeader("Content-Type"))?void 0:n.split(";");if(!(null!=(e=null==r?void 0:r[0].trim())?e:"").startsWith("multipart/"))return null;const o={boundary:"",start:"",type:""};for(let i=1;i<r.length;i++){const t=r[i].indexOf("=");if(t>0){const n=r[i].slice(0,t).trim(),e=r[i].slice(t+1).trim();o[n]=e.startsWith('"')?e.slice(1,e.length-1):e}}return o}function a(t,n){const e=String.fromCharCode.apply(null,t.subarray(0,Math.min(300,t.length))).split("\n"),r=Math.min(e.length,7),o={contentDisposition:"inline"};let i=0;for(let l=0;l<r;l++){var a;if(e[l].length<4)i=i+e[l].length+1;else if("content"===e[l].slice(0,7).toLowerCase()){if(i=i+e[l].length+1,!e[l].includes(":"))continue;const t=e[l].substring(0,e[l].indexOf(":")).trim(),n=e[l].substring(e[l].indexOf(":")+1).trim();switch(t.toLowerCase()){case"content-type":o.contentType=n;break;case"content-description":o.contentDescription=n;break;case"content-transfer-encoding":o.contentTransferEncoding=n;break;case"content-id":o.contentID=n;break;case"content-disposition":o.contentDisposition=n;break;case"content-location":o.contentLocation=n}}else{if(o.contentDisposition.toLowerCase().includes("inline")&&e[l].length>=4&&(null==(a=o.contentType)?void 0:a.toLowerCase().indexOf("image"))>-1){let n=!0,e=t.subarray(i,t.length);if(o.contentType.toLowerCase().indexOf("tif")>0){if("base64"===o.contentTransferEncoding){let t="";const n=e;for(let e=0;e<n.length;e+=65535){const r=n.subarray(e,e+65535>n.length-1?n.length-1:e+65535);t+=String.fromCharCode.apply(null,r)}const r=atob(t);e=new Uint8Array(r.length);for(let o=0;o<e.length;o++)e[o]=r.charCodeAt(o)}n=73===e[0]&&73===e[1]||77===e[0]&&77===e[1]}if(n){let n=e.buffer;"base64"!==o.contentTransferEncoding&&(n=new ArrayBuffer(t.length-i),e=new Uint8Array(n),e.set(t.subarray(i,t.length))),o.contentData=n}break}if((""===n.start||o.contentID===n.start)&&o.contentType){if(o.contentType.includes("text")||o.contentType.includes("xml")){o.contentData=String.fromCharCode.apply(null,t.subarray(i,t.length));break}o.contentData=t.subarray(i,t.length)}}}return o}t.getBoundary=r,t.parse=e,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
