mhtml-stream 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- var j=Object.create;var h=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var W=Object.getOwnPropertyNames;var N=Object.getPrototypeOf,J=Object.prototype.hasOwnProperty;var R=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),V=(t,e)=>{for(var r in e)h(t,r,{get:e[r],enumerable:!0})},x=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of W(e))!J.call(t,o)&&o!==r&&h(t,o,{get:()=>e[o],enumerable:!(n=Q(e,o))||n.enumerable});return t};var U=(t,e,r)=>(r=t!=null?j(N(t)):{},x(e||!t||!t.__esModule?h(r,"default",{value:t,enumerable:!0}):r,t)),_=t=>x(h({},"__esModule",{value:!0}),t);var w=R(g=>{"use strict";g.byteLength=G;g.toByteArray=X;g.fromByteArray=ee;var c=[],d=[],z=typeof Uint8Array<"u"?Uint8Array:Array,b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(f=0,F=b.length;f<F;++f)c[f]=b[f],d[b.charCodeAt(f)]=f;var f,F;d["-".charCodeAt(0)]=62;d["_".charCodeAt(0)]=63;function B(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=t.indexOf("=");r===-1&&(r=e);var n=r===e?0:4-r%4;return[r,n]}function G(t){var e=B(t),r=e[0],n=e[1];return(r+n)*3/4-n}function K(t,e,r){return(e+r)*3/4-r}function X(t){var e,r=B(t),n=r[0],o=r[1],a=new z(K(t,n,o)),s=0,i=o>0?n-4:n,l;for(l=0;l<i;l+=4)e=d[t.charCodeAt(l)]<<18|d[t.charCodeAt(l+1)]<<12|d[t.charCodeAt(l+2)]<<6|d[t.charCodeAt(l+3)],a[s++]=e>>16&255,a[s++]=e>>8&255,a[s++]=e&255;return o===2&&(e=d[t.charCodeAt(l)]<<2|d[t.charCodeAt(l+1)]>>4,a[s++]=e&255),o===1&&(e=d[t.charCodeAt(l)]<<10|d[t.charCodeAt(l+1)]<<4|d[t.charCodeAt(l+2)]>>2,a[s++]=e>>8&255,a[s++]=e&255),a}function Y(t){return c[t>>18&63]+c[t>>12&63]+c[t>>6&63]+c[t&63]}function Z(t,e,r){for(var n,o=[],a=e;a<r;a+=3)n=(t[a]<<16&16711680)+(t[a+1]<<8&65280)+(t[a+2]&255),o.push(Y(n));return o.join("")}function ee(t){for(var e,r=t.length,n=r%3,o=[],a=16383,s=0,i=r-n;s<i;s+=a)o.push(Z(t,s,s+a>i?i:s+a));return n===1?(e=t[r-1],o.push(c[e>>2]+c[e<<4&63]+"==")):n===2&&(e=(t[r-2]<<8)+t[r-1],o.push(c[e>>10]+c[e>>4&63]+c[e<<2&63]+"=")),o.join("")}});var fe={};V(fe,{parseMhtml:()=>ce});module.exports=_(fe);var q=U(w());var p=class{#e=new Map;[Symbol.iterator](){return this.entries()}append(e,r){let n=this.#e.get(e);n===void 0?this.#e.set(e,[r]):n.push(r)}*entries(e=", "){for(let[r,n]of this.#e.entries())yield[r,n.join(e)]}*entriesAll(){for(let[e,r]of this.#e.entries())for(let n of r)yield[e,n]}get(e,r=", "){let n=this.#e.get(e);return n===void 0?null:n.join(r)}getAll(e){return this.#e.get(e)??[]}has(e){return this.#e.has(e)}keys(){return this.#e.keys()}*values(e=", "){for(let r of this.#e.values())yield r.join(e)}*valuesAll(){for(let e of this.#e.values())yield*e}};var C=U(w());function te(t){return ArrayBuffer.isView(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):new Uint8Array(t)}function v(t,e){if(t.length!==e.length)return!1;if(t.byteOffset%4===e.byteOffset%4){let r=(4-t.byteOffset%4)%4,n=Math.floor((t.byteLength-r)/4),o=r+n*4,a=new Uint32Array(t.buffer,t.byteOffset+r,n),s=new Uint32Array(e.buffer,e.byteOffset+r,n);for(let i=0;i<r;++i)if(t[i]!==e[i])return!1;for(let i=0;i<n;++i)if(a[i]!==s[i])return!1;for(let i=o;i<t.length;++i)if(t[i]!==e[i])return!1;return!0}else{for(let r of t.keys())if(t[r]!==e[r])return!1;return!0}}function re(t,e){return t.findIndex((r,n)=>{if(r!==e[0]||n+e.length>t.length)return!1;for(let o=1;o<e.length;++o)if(t[n+o]!==e[o])return!1;return!0})}async function*k(t,e){let r=new Uint8Array(0);for await(let n of t){let o=te(n);r=r.length?E([r,o]):o;let a;for(;(a=re(r,e))!==-1;)yield r.subarray(0,a),r=r.subarray(a+e.length)}yield r}function E(t){let e=t.reduce((o,a)=>o+a.length,0),r=new Uint8Array(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return r}async function M(t){let e=[];for await(let r of t)e.push(r);return E(e)}var ne=new Uint8Array([10]);async function*L(t,e=ne){for await(let r of t){let n=new Uint8Array(r.length+e.length),o=!1,a=0;for(let s=0;s<r.length;++s){let i=r[s];if(i>=128)throw new Error(`got non-ascii character when decoding quoted printable: ${r}`);if(i!==61)n[a++]=i;else{let l=r[++s];if(l===void 0)o=!0;else{let u=r[++s];if(u===void 0)throw new Error("quoted printable escape (=) was not followed by two bytes");let y=parseInt(String.fromCharCode(l),16);y*=16,y+=parseInt(String.fromCharCode(u),16),n[a++]=y}}}o||(n.set(e,a),a+=e.length),yield n.subarray(0,a)}}var oe=new TextDecoder;async function*O(t){for await(let e of t)yield(0,C.toByteArray)(oe.decode(e))}async function*m(t){for await(let e of t)yield e}function H(){throw new Error("binary transfer-encoding is explicitly not supported and trying to add an implementation will likely result in unexpected results, but if you want to ignore anyway, set binary to `decode8bit`")}var $=new TextEncoder,D=new TextDecoder;function ae(t){let e=new Uint8Array(t.length),r=0;for(let n=0;n<t.length;++n){let o=t.charCodeAt(n),a;if(o>=128)throw new Error(`got non-ascii character when decoding q-quoted word: "${t}"`);o===95?a=32:o===61?(a=parseInt(t[++n],16),a*=16,a+=parseInt(t[++n],16)):a=o,e[r++]=a}return e.subarray(0,r)}var se=/^=\?([^?\s]+)\?([BQ])\?([^?\s]+)\?=$/;function T(t){let e=se.exec(t);if(e){let[,r,n,o]=e,a;if(n==="Q")a=ae(o);else if(n==="B")a=(0,q.toByteArray)(o);else throw new Error(`unknown encoding for header value encoding: ${n}`);return new TextDecoder(r).decode(a)}else return t}async function ie(t){let e=new p,r="",n="";for(;;){let{done:o,value:a}=await t.next();if(o)throw new Error("didn't find an empty line to signify the end of header parsing");let s=D.decode(a);if(/^\s/.test(s))n+=T(s.substr(1));else if(r&&e.append(r,n),s){let i=s.indexOf(": ");if(i===-1)throw new Error(`header line didn't have key-value delimiter: "${s}"`);r=s.slice(0,i),n=T(s.slice(i+2))}else return e}}var le=new Map([["7bit",m],["base64",O],["quoted-printable",L],["8bit",m],["binary",H]]);function de(t){let e=t.get("Content-Type");if(e===null)throw new Error(`first headers didn't contain a content type: ${JSON.stringify(Object.fromEntries(t))}`);let r,n=!1;for(let s of e.split(/;\s*/))s.startsWith("multipart/")?n=!0:s.startsWith("boundary=")&&(r=s.slice(9),r.startsWith('"')&&r.endsWith('"')&&(r=r.slice(1,-1)));if(!n||r===void 0)throw new Error("first content type header didn't contain 'multipart/...' and a boundary string");let o=$.encode(`--${r}`),a=$.encode(`--${r}--`);return[o,a]}async function*ce(t,{decoderOverrides:e=new Map}={}){let r=new Map([...le.entries(),...e.entries()]),n=new Uint8Array([13,10]),o=k(t,n),a=null,s=!0;for(;s;){let i=await ie(o),[l,u]=a??(a=de(i)),y=i.get("Content-Transfer-Encoding")??"7bit",I=r.get(y);if(I===void 0)throw new Error(`unhandled encoding type: ${y}`);let P=await M(I({[Symbol.asyncIterator](){return{async next(){let{done:S,value:A}=await o.next();if(S)throw new Error(`stream didn't end with the appropriate termination boundary: ${D.decode(u)}`);return v(A,l)?{done:!0,value:void 0}:v(A,u)?(s=!1,{done:!0,value:void 0}):{value:A}}}}}));yield{headers:i,content:P}}}0&&(module.exports={parseMhtml});
1
+ var j=Object.create;var h=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var W=Object.getOwnPropertyNames;var N=Object.getPrototypeOf,J=Object.prototype.hasOwnProperty;var R=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),V=(t,e)=>{for(var r in e)h(t,r,{get:e[r],enumerable:!0})},x=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of W(e))!J.call(t,o)&&o!==r&&h(t,o,{get:()=>e[o],enumerable:!(n=Q(e,o))||n.enumerable});return t};var U=(t,e,r)=>(r=t!=null?j(N(t)):{},x(e||!t||!t.__esModule?h(r,"default",{value:t,enumerable:!0}):r,t)),_=t=>x(h({},"__esModule",{value:!0}),t);var w=R(g=>{"use strict";g.byteLength=G;g.toByteArray=X;g.fromByteArray=ee;var c=[],d=[],z=typeof Uint8Array<"u"?Uint8Array:Array,b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(f=0,F=b.length;f<F;++f)c[f]=b[f],d[b.charCodeAt(f)]=f;var f,F;d["-".charCodeAt(0)]=62;d["_".charCodeAt(0)]=63;function B(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=t.indexOf("=");r===-1&&(r=e);var n=r===e?0:4-r%4;return[r,n]}function G(t){var e=B(t),r=e[0],n=e[1];return(r+n)*3/4-n}function K(t,e,r){return(e+r)*3/4-r}function X(t){var e,r=B(t),n=r[0],o=r[1],a=new z(K(t,n,o)),s=0,i=o>0?n-4:n,l;for(l=0;l<i;l+=4)e=d[t.charCodeAt(l)]<<18|d[t.charCodeAt(l+1)]<<12|d[t.charCodeAt(l+2)]<<6|d[t.charCodeAt(l+3)],a[s++]=e>>16&255,a[s++]=e>>8&255,a[s++]=e&255;return o===2&&(e=d[t.charCodeAt(l)]<<2|d[t.charCodeAt(l+1)]>>4,a[s++]=e&255),o===1&&(e=d[t.charCodeAt(l)]<<10|d[t.charCodeAt(l+1)]<<4|d[t.charCodeAt(l+2)]>>2,a[s++]=e>>8&255,a[s++]=e&255),a}function Y(t){return c[t>>18&63]+c[t>>12&63]+c[t>>6&63]+c[t&63]}function Z(t,e,r){for(var n,o=[],a=e;a<r;a+=3)n=(t[a]<<16&16711680)+(t[a+1]<<8&65280)+(t[a+2]&255),o.push(Y(n));return o.join("")}function ee(t){for(var e,r=t.length,n=r%3,o=[],a=16383,s=0,i=r-n;s<i;s+=a)o.push(Z(t,s,s+a>i?i:s+a));return n===1?(e=t[r-1],o.push(c[e>>2]+c[e<<4&63]+"==")):n===2&&(e=(t[r-2]<<8)+t[r-1],o.push(c[e>>10]+c[e>>4&63]+c[e<<2&63]+"=")),o.join("")}});var fe={};V(fe,{parseMhtml:()=>ce});module.exports=_(fe);var q=U(w());var p=class{#e=new Map;[Symbol.iterator](){return this.entries()}append(e,r){let n=this.#e.get(e);n===void 0?this.#e.set(e,[r]):n.push(r)}*entries(e=", "){for(let[r,n]of this.#e.entries())yield[r,n.join(e)]}*entriesAll(){for(let[e,r]of this.#e.entries())for(let n of r)yield[e,n]}get(e,r=", "){let n=this.#e.get(e);return n===void 0?null:n.join(r)}getAll(e){return this.#e.get(e)??[]}has(e){return this.#e.has(e)}keys(){return this.#e.keys()}*values(e=", "){for(let r of this.#e.values())yield r.join(e)}*valuesAll(){for(let e of this.#e.values())yield*e}};var C=U(w());function te(t){return ArrayBuffer.isView(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):new Uint8Array(t)}function v(t,e){if(t.length!==e.length)return!1;if(t.byteOffset%4===e.byteOffset%4){let r=(4-t.byteOffset%4)%4,n=Math.floor((t.byteLength-r)/4),o=r+n*4,a=new Uint32Array(t.buffer,t.byteOffset+r,n),s=new Uint32Array(e.buffer,e.byteOffset+r,n);for(let i=0;i<r;++i)if(t[i]!==e[i])return!1;for(let i=0;i<n;++i)if(a[i]!==s[i])return!1;for(let i=o;i<t.length;++i)if(t[i]!==e[i])return!1;return!0}else{for(let r of t.keys())if(t[r]!==e[r])return!1;return!0}}function re(t,e){return t.findIndex((r,n)=>{if(r!==e[0]||n+e.length>t.length)return!1;for(let o=1;o<e.length;++o)if(t[n+o]!==e[o])return!1;return!0})}async function*k(t,e){let r=new Uint8Array(0);for await(let n of t){let o=te(n);r=r.length?E([r,o]):o;let a;for(;(a=re(r,e))!==-1;)yield r.subarray(0,a),r=r.subarray(a+e.length)}yield r}function E(t){let e=t.reduce((o,a)=>o+a.length,0),r=new Uint8Array(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return r}async function M(t){let e=[];for await(let r of t)e.push(r);return E(e)}var ne=new Uint8Array([10]);async function*L(t,e=ne){for await(let r of t){let n=new Uint8Array(r.length+e.length),o=!1,a=0;for(let s=0;s<r.length;++s){let i=r[s];if(i>=128)throw new Error(`got non-ascii character when decoding quoted printable: ${i}`);if(i!==61)n[a++]=i;else{let l=r[++s];if(l===void 0)o=!0;else{let u=r[++s];if(u===void 0)throw new Error("quoted printable escape (=) was not followed by two bytes");let y=parseInt(String.fromCharCode(l),16);y*=16,y+=parseInt(String.fromCharCode(u),16),n[a++]=y}}}o||(n.set(e,a),a+=e.length),yield n.subarray(0,a)}}var oe=new TextDecoder;async function*O(t){for await(let e of t)yield(0,C.toByteArray)(oe.decode(e))}async function*m(t){for await(let e of t)yield e}function H(){throw new Error("binary transfer-encoding is explicitly not supported and trying to add an implementation will likely result in unexpected results, but if you want to ignore anyway, set binary to `decode8bit`")}var $=new TextEncoder,D=new TextDecoder;function ae(t){let e=new Uint8Array(t.length),r=0;for(let n=0;n<t.length;++n){let o=t.charCodeAt(n),a;if(o>=128)throw new Error(`got non-ascii character when decoding q-quoted word: "${t}"`);o===95?a=32:o===61?(a=parseInt(t[++n],16),a*=16,a+=parseInt(t[++n],16)):a=o,e[r++]=a}return e.subarray(0,r)}var se=/^=\?([^?\s]+)\?([BQ])\?([^?\s]+)\?=$/;function T(t){let e=se.exec(t);if(e){let[,r,n,o]=e,a;if(n==="Q")a=ae(o);else if(n==="B")a=(0,q.toByteArray)(o);else throw new Error(`unknown encoding for header value encoding: ${n}`);return new TextDecoder(r).decode(a)}else return t}async function ie(t){let e=new p,r="",n="";for(;;){let{done:o,value:a}=await t.next();if(o)throw new Error("didn't find an empty line to signify the end of header parsing");let s=D.decode(a);if(/^\s/.test(s))n+=T(s.substr(1));else if(r&&e.append(r,n),s){let i=s.indexOf(": ");if(i===-1)throw new Error(`header line didn't have key-value delimiter: "${s}"`);r=s.slice(0,i),n=T(s.slice(i+2))}else return e}}var le=new Map([["7bit",m],["base64",O],["quoted-printable",L],["8bit",m],["binary",H]]);function de(t){let e=t.get("Content-Type");if(e===null)throw new Error(`first headers didn't contain a content type: ${JSON.stringify(Object.fromEntries(t))}`);let r,n=!1;for(let s of e.split(/;\s*/))s.startsWith("multipart/")?n=!0:s.startsWith("boundary=")&&(r=s.slice(9),r.startsWith('"')&&r.endsWith('"')&&(r=r.slice(1,-1)));if(!n||r===void 0)throw new Error("first content type header didn't contain 'multipart/...' and a boundary string");let o=$.encode(`--${r}`),a=$.encode(`--${r}--`);return[o,a]}async function*ce(t,{decoderOverrides:e=new Map}={}){let r=new Map([...le.entries(),...e.entries()]),n=new Uint8Array([13,10]),o=k(t,n),a=null,s=!0;for(;s;){let i=await ie(o),[l,u]=a??(a=de(i)),y=i.get("Content-Transfer-Encoding")??"7bit",I=r.get(y);if(I===void 0)throw new Error(`unhandled encoding type: ${y}`);let P=await M(I({[Symbol.asyncIterator](){return{async next(){let{done:S,value:A}=await o.next();if(S)throw new Error(`stream didn't end with the appropriate termination boundary: ${D.decode(u)}`);return v(A,l)?{done:!0,value:void 0}:v(A,u)?(s=!1,{done:!0,value:void 0}):{value:A}}}}}));yield{headers:i,content:P}}}0&&(module.exports={parseMhtml});
@@ -1 +1 @@
1
- var S=Object.create;var I=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var Q=Object.getOwnPropertyNames;var W=Object.getPrototypeOf,N=Object.prototype.hasOwnProperty;var J=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var R=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Q(e))!N.call(t,o)&&o!==r&&I(t,o,{get:()=>e[o],enumerable:!(n=j(e,o))||n.enumerable});return t};var x=(t,e,r)=>(r=t!=null?S(W(t)):{},R(e||!t||!t.__esModule?I(r,"default",{value:t,enumerable:!0}):r,t));var b=J(h=>{"use strict";h.byteLength=_;h.toByteArray=G;h.fromByteArray=Y;var c=[],d=[],V=typeof Uint8Array<"u"?Uint8Array:Array,A="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(f=0,U=A.length;f<U;++f)c[f]=A[f],d[A.charCodeAt(f)]=f;var f,U;d["-".charCodeAt(0)]=62;d["_".charCodeAt(0)]=63;function F(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=t.indexOf("=");r===-1&&(r=e);var n=r===e?0:4-r%4;return[r,n]}function _(t){var e=F(t),r=e[0],n=e[1];return(r+n)*3/4-n}function z(t,e,r){return(e+r)*3/4-r}function G(t){var e,r=F(t),n=r[0],o=r[1],a=new V(z(t,n,o)),s=0,i=o>0?n-4:n,l;for(l=0;l<i;l+=4)e=d[t.charCodeAt(l)]<<18|d[t.charCodeAt(l+1)]<<12|d[t.charCodeAt(l+2)]<<6|d[t.charCodeAt(l+3)],a[s++]=e>>16&255,a[s++]=e>>8&255,a[s++]=e&255;return o===2&&(e=d[t.charCodeAt(l)]<<2|d[t.charCodeAt(l+1)]>>4,a[s++]=e&255),o===1&&(e=d[t.charCodeAt(l)]<<10|d[t.charCodeAt(l+1)]<<4|d[t.charCodeAt(l+2)]>>2,a[s++]=e>>8&255,a[s++]=e&255),a}function K(t){return c[t>>18&63]+c[t>>12&63]+c[t>>6&63]+c[t&63]}function X(t,e,r){for(var n,o=[],a=e;a<r;a+=3)n=(t[a]<<16&16711680)+(t[a+1]<<8&65280)+(t[a+2]&255),o.push(K(n));return o.join("")}function Y(t){for(var e,r=t.length,n=r%3,o=[],a=16383,s=0,i=r-n;s<i;s+=a)o.push(X(t,s,s+a>i?i:s+a));return n===1?(e=t[r-1],o.push(c[e>>2]+c[e<<4&63]+"==")):n===2&&(e=(t[r-2]<<8)+t[r-1],o.push(c[e>>10]+c[e>>4&63]+c[e<<2&63]+"=")),o.join("")}});var T=x(b());var g=class{#e=new Map;[Symbol.iterator](){return this.entries()}append(e,r){let n=this.#e.get(e);n===void 0?this.#e.set(e,[r]):n.push(r)}*entries(e=", "){for(let[r,n]of this.#e.entries())yield[r,n.join(e)]}*entriesAll(){for(let[e,r]of this.#e.entries())for(let n of r)yield[e,n]}get(e,r=", "){let n=this.#e.get(e);return n===void 0?null:n.join(r)}getAll(e){return this.#e.get(e)??[]}has(e){return this.#e.has(e)}keys(){return this.#e.keys()}*values(e=", "){for(let r of this.#e.values())yield r.join(e)}*valuesAll(){for(let e of this.#e.values())yield*e}};var B=x(b());function Z(t){return ArrayBuffer.isView(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):new Uint8Array(t)}function w(t,e){if(t.length!==e.length)return!1;if(t.byteOffset%4===e.byteOffset%4){let r=(4-t.byteOffset%4)%4,n=Math.floor((t.byteLength-r)/4),o=r+n*4,a=new Uint32Array(t.buffer,t.byteOffset+r,n),s=new Uint32Array(e.buffer,e.byteOffset+r,n);for(let i=0;i<r;++i)if(t[i]!==e[i])return!1;for(let i=0;i<n;++i)if(a[i]!==s[i])return!1;for(let i=o;i<t.length;++i)if(t[i]!==e[i])return!1;return!0}else{for(let r of t.keys())if(t[r]!==e[r])return!1;return!0}}function ee(t,e){return t.findIndex((r,n)=>{if(r!==e[0]||n+e.length>t.length)return!1;for(let o=1;o<e.length;++o)if(t[n+o]!==e[o])return!1;return!0})}async function*C(t,e){let r=new Uint8Array(0);for await(let n of t){let o=Z(n);r=r.length?k([r,o]):o;let a;for(;(a=ee(r,e))!==-1;)yield r.subarray(0,a),r=r.subarray(a+e.length)}yield r}function k(t){let e=t.reduce((o,a)=>o+a.length,0),r=new Uint8Array(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return r}async function E(t){let e=[];for await(let r of t)e.push(r);return k(e)}var te=new Uint8Array([10]);async function*M(t,e=te){for await(let r of t){let n=new Uint8Array(r.length+e.length),o=!1,a=0;for(let s=0;s<r.length;++s){let i=r[s];if(i>=128)throw new Error(`got non-ascii character when decoding quoted printable: ${r}`);if(i!==61)n[a++]=i;else{let l=r[++s];if(l===void 0)o=!0;else{let u=r[++s];if(u===void 0)throw new Error("quoted printable escape (=) was not followed by two bytes");let y=parseInt(String.fromCharCode(l),16);y*=16,y+=parseInt(String.fromCharCode(u),16),n[a++]=y}}}o||(n.set(e,a),a+=e.length),yield n.subarray(0,a)}}var re=new TextDecoder;async function*L(t){for await(let e of t)yield(0,B.toByteArray)(re.decode(e))}async function*v(t){for await(let e of t)yield e}function O(){throw new Error("binary transfer-encoding is explicitly not supported and trying to add an implementation will likely result in unexpected results, but if you want to ignore anyway, set binary to `decode8bit`")}var H=new TextEncoder,q=new TextDecoder;function ne(t){let e=new Uint8Array(t.length),r=0;for(let n=0;n<t.length;++n){let o=t.charCodeAt(n),a;if(o>=128)throw new Error(`got non-ascii character when decoding q-quoted word: "${t}"`);o===95?a=32:o===61?(a=parseInt(t[++n],16),a*=16,a+=parseInt(t[++n],16)):a=o,e[r++]=a}return e.subarray(0,r)}var oe=/^=\?([^?\s]+)\?([BQ])\?([^?\s]+)\?=$/;function $(t){let e=oe.exec(t);if(e){let[,r,n,o]=e,a;if(n==="Q")a=ne(o);else if(n==="B")a=(0,T.toByteArray)(o);else throw new Error(`unknown encoding for header value encoding: ${n}`);return new TextDecoder(r).decode(a)}else return t}async function ae(t){let e=new g,r="",n="";for(;;){let{done:o,value:a}=await t.next();if(o)throw new Error("didn't find an empty line to signify the end of header parsing");let s=q.decode(a);if(/^\s/.test(s))n+=$(s.substr(1));else if(r&&e.append(r,n),s){let i=s.indexOf(": ");if(i===-1)throw new Error(`header line didn't have key-value delimiter: "${s}"`);r=s.slice(0,i),n=$(s.slice(i+2))}else return e}}var se=new Map([["7bit",v],["base64",L],["quoted-printable",M],["8bit",v],["binary",O]]);function ie(t){let e=t.get("Content-Type");if(e===null)throw new Error(`first headers didn't contain a content type: ${JSON.stringify(Object.fromEntries(t))}`);let r,n=!1;for(let s of e.split(/;\s*/))s.startsWith("multipart/")?n=!0:s.startsWith("boundary=")&&(r=s.slice(9),r.startsWith('"')&&r.endsWith('"')&&(r=r.slice(1,-1)));if(!n||r===void 0)throw new Error("first content type header didn't contain 'multipart/...' and a boundary string");let o=H.encode(`--${r}`),a=H.encode(`--${r}--`);return[o,a]}async function*ge(t,{decoderOverrides:e=new Map}={}){let r=new Map([...se.entries(),...e.entries()]),n=new Uint8Array([13,10]),o=C(t,n),a=null,s=!0;for(;s;){let i=await ae(o),[l,u]=a??(a=ie(i)),y=i.get("Content-Transfer-Encoding")??"7bit",m=r.get(y);if(m===void 0)throw new Error(`unhandled encoding type: ${y}`);let D=await E(m({[Symbol.asyncIterator](){return{async next(){let{done:P,value:p}=await o.next();if(P)throw new Error(`stream didn't end with the appropriate termination boundary: ${q.decode(u)}`);return w(p,l)?{done:!0,value:void 0}:w(p,u)?(s=!1,{done:!0,value:void 0}):{value:p}}}}}));yield{headers:i,content:D}}}export{ge as parseMhtml};
1
+ var S=Object.create;var I=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var Q=Object.getOwnPropertyNames;var W=Object.getPrototypeOf,N=Object.prototype.hasOwnProperty;var J=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var R=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Q(e))!N.call(t,o)&&o!==r&&I(t,o,{get:()=>e[o],enumerable:!(n=j(e,o))||n.enumerable});return t};var x=(t,e,r)=>(r=t!=null?S(W(t)):{},R(e||!t||!t.__esModule?I(r,"default",{value:t,enumerable:!0}):r,t));var b=J(h=>{"use strict";h.byteLength=_;h.toByteArray=G;h.fromByteArray=Y;var c=[],d=[],V=typeof Uint8Array<"u"?Uint8Array:Array,A="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(f=0,U=A.length;f<U;++f)c[f]=A[f],d[A.charCodeAt(f)]=f;var f,U;d["-".charCodeAt(0)]=62;d["_".charCodeAt(0)]=63;function F(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=t.indexOf("=");r===-1&&(r=e);var n=r===e?0:4-r%4;return[r,n]}function _(t){var e=F(t),r=e[0],n=e[1];return(r+n)*3/4-n}function z(t,e,r){return(e+r)*3/4-r}function G(t){var e,r=F(t),n=r[0],o=r[1],a=new V(z(t,n,o)),s=0,i=o>0?n-4:n,l;for(l=0;l<i;l+=4)e=d[t.charCodeAt(l)]<<18|d[t.charCodeAt(l+1)]<<12|d[t.charCodeAt(l+2)]<<6|d[t.charCodeAt(l+3)],a[s++]=e>>16&255,a[s++]=e>>8&255,a[s++]=e&255;return o===2&&(e=d[t.charCodeAt(l)]<<2|d[t.charCodeAt(l+1)]>>4,a[s++]=e&255),o===1&&(e=d[t.charCodeAt(l)]<<10|d[t.charCodeAt(l+1)]<<4|d[t.charCodeAt(l+2)]>>2,a[s++]=e>>8&255,a[s++]=e&255),a}function K(t){return c[t>>18&63]+c[t>>12&63]+c[t>>6&63]+c[t&63]}function X(t,e,r){for(var n,o=[],a=e;a<r;a+=3)n=(t[a]<<16&16711680)+(t[a+1]<<8&65280)+(t[a+2]&255),o.push(K(n));return o.join("")}function Y(t){for(var e,r=t.length,n=r%3,o=[],a=16383,s=0,i=r-n;s<i;s+=a)o.push(X(t,s,s+a>i?i:s+a));return n===1?(e=t[r-1],o.push(c[e>>2]+c[e<<4&63]+"==")):n===2&&(e=(t[r-2]<<8)+t[r-1],o.push(c[e>>10]+c[e>>4&63]+c[e<<2&63]+"=")),o.join("")}});var T=x(b());var g=class{#e=new Map;[Symbol.iterator](){return this.entries()}append(e,r){let n=this.#e.get(e);n===void 0?this.#e.set(e,[r]):n.push(r)}*entries(e=", "){for(let[r,n]of this.#e.entries())yield[r,n.join(e)]}*entriesAll(){for(let[e,r]of this.#e.entries())for(let n of r)yield[e,n]}get(e,r=", "){let n=this.#e.get(e);return n===void 0?null:n.join(r)}getAll(e){return this.#e.get(e)??[]}has(e){return this.#e.has(e)}keys(){return this.#e.keys()}*values(e=", "){for(let r of this.#e.values())yield r.join(e)}*valuesAll(){for(let e of this.#e.values())yield*e}};var B=x(b());function Z(t){return ArrayBuffer.isView(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):new Uint8Array(t)}function w(t,e){if(t.length!==e.length)return!1;if(t.byteOffset%4===e.byteOffset%4){let r=(4-t.byteOffset%4)%4,n=Math.floor((t.byteLength-r)/4),o=r+n*4,a=new Uint32Array(t.buffer,t.byteOffset+r,n),s=new Uint32Array(e.buffer,e.byteOffset+r,n);for(let i=0;i<r;++i)if(t[i]!==e[i])return!1;for(let i=0;i<n;++i)if(a[i]!==s[i])return!1;for(let i=o;i<t.length;++i)if(t[i]!==e[i])return!1;return!0}else{for(let r of t.keys())if(t[r]!==e[r])return!1;return!0}}function ee(t,e){return t.findIndex((r,n)=>{if(r!==e[0]||n+e.length>t.length)return!1;for(let o=1;o<e.length;++o)if(t[n+o]!==e[o])return!1;return!0})}async function*C(t,e){let r=new Uint8Array(0);for await(let n of t){let o=Z(n);r=r.length?k([r,o]):o;let a;for(;(a=ee(r,e))!==-1;)yield r.subarray(0,a),r=r.subarray(a+e.length)}yield r}function k(t){let e=t.reduce((o,a)=>o+a.length,0),r=new Uint8Array(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return r}async function E(t){let e=[];for await(let r of t)e.push(r);return k(e)}var te=new Uint8Array([10]);async function*M(t,e=te){for await(let r of t){let n=new Uint8Array(r.length+e.length),o=!1,a=0;for(let s=0;s<r.length;++s){let i=r[s];if(i>=128)throw new Error(`got non-ascii character when decoding quoted printable: ${i}`);if(i!==61)n[a++]=i;else{let l=r[++s];if(l===void 0)o=!0;else{let u=r[++s];if(u===void 0)throw new Error("quoted printable escape (=) was not followed by two bytes");let y=parseInt(String.fromCharCode(l),16);y*=16,y+=parseInt(String.fromCharCode(u),16),n[a++]=y}}}o||(n.set(e,a),a+=e.length),yield n.subarray(0,a)}}var re=new TextDecoder;async function*L(t){for await(let e of t)yield(0,B.toByteArray)(re.decode(e))}async function*v(t){for await(let e of t)yield e}function O(){throw new Error("binary transfer-encoding is explicitly not supported and trying to add an implementation will likely result in unexpected results, but if you want to ignore anyway, set binary to `decode8bit`")}var H=new TextEncoder,q=new TextDecoder;function ne(t){let e=new Uint8Array(t.length),r=0;for(let n=0;n<t.length;++n){let o=t.charCodeAt(n),a;if(o>=128)throw new Error(`got non-ascii character when decoding q-quoted word: "${t}"`);o===95?a=32:o===61?(a=parseInt(t[++n],16),a*=16,a+=parseInt(t[++n],16)):a=o,e[r++]=a}return e.subarray(0,r)}var oe=/^=\?([^?\s]+)\?([BQ])\?([^?\s]+)\?=$/;function $(t){let e=oe.exec(t);if(e){let[,r,n,o]=e,a;if(n==="Q")a=ne(o);else if(n==="B")a=(0,T.toByteArray)(o);else throw new Error(`unknown encoding for header value encoding: ${n}`);return new TextDecoder(r).decode(a)}else return t}async function ae(t){let e=new g,r="",n="";for(;;){let{done:o,value:a}=await t.next();if(o)throw new Error("didn't find an empty line to signify the end of header parsing");let s=q.decode(a);if(/^\s/.test(s))n+=$(s.substr(1));else if(r&&e.append(r,n),s){let i=s.indexOf(": ");if(i===-1)throw new Error(`header line didn't have key-value delimiter: "${s}"`);r=s.slice(0,i),n=$(s.slice(i+2))}else return e}}var se=new Map([["7bit",v],["base64",L],["quoted-printable",M],["8bit",v],["binary",O]]);function ie(t){let e=t.get("Content-Type");if(e===null)throw new Error(`first headers didn't contain a content type: ${JSON.stringify(Object.fromEntries(t))}`);let r,n=!1;for(let s of e.split(/;\s*/))s.startsWith("multipart/")?n=!0:s.startsWith("boundary=")&&(r=s.slice(9),r.startsWith('"')&&r.endsWith('"')&&(r=r.slice(1,-1)));if(!n||r===void 0)throw new Error("first content type header didn't contain 'multipart/...' and a boundary string");let o=H.encode(`--${r}`),a=H.encode(`--${r}--`);return[o,a]}async function*ge(t,{decoderOverrides:e=new Map}={}){let r=new Map([...se.entries(),...e.entries()]),n=new Uint8Array([13,10]),o=C(t,n),a=null,s=!0;for(;s;){let i=await ae(o),[l,u]=a??(a=ie(i)),y=i.get("Content-Transfer-Encoding")??"7bit",m=r.get(y);if(m===void 0)throw new Error(`unhandled encoding type: ${y}`);let D=await E(m({[Symbol.asyncIterator](){return{async next(){let{done:P,value:p}=await o.next();if(P)throw new Error(`stream didn't end with the appropriate termination boundary: ${q.decode(u)}`);return w(p,l)?{done:!0,value:void 0}:w(p,u)?(s=!1,{done:!0,value:void 0}):{value:p}}}}}));yield{headers:i,content:D}}}export{ge as parseMhtml};
@@ -1 +1 @@
1
- var mhtml=(()=>{var j=Object.create;var h=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var W=Object.getOwnPropertyNames;var N=Object.getPrototypeOf,J=Object.prototype.hasOwnProperty;var R=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),V=(t,e)=>{for(var r in e)h(t,r,{get:e[r],enumerable:!0})},x=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of W(e))!J.call(t,o)&&o!==r&&h(t,o,{get:()=>e[o],enumerable:!(n=Q(e,o))||n.enumerable});return t};var U=(t,e,r)=>(r=t!=null?j(N(t)):{},x(e||!t||!t.__esModule?h(r,"default",{value:t,enumerable:!0}):r,t)),_=t=>x(h({},"__esModule",{value:!0}),t);var w=R(g=>{"use strict";g.byteLength=G;g.toByteArray=X;g.fromByteArray=ee;var c=[],d=[],z=typeof Uint8Array<"u"?Uint8Array:Array,b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(f=0,F=b.length;f<F;++f)c[f]=b[f],d[b.charCodeAt(f)]=f;var f,F;d["-".charCodeAt(0)]=62;d["_".charCodeAt(0)]=63;function B(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=t.indexOf("=");r===-1&&(r=e);var n=r===e?0:4-r%4;return[r,n]}function G(t){var e=B(t),r=e[0],n=e[1];return(r+n)*3/4-n}function K(t,e,r){return(e+r)*3/4-r}function X(t){var e,r=B(t),n=r[0],o=r[1],a=new z(K(t,n,o)),s=0,i=o>0?n-4:n,l;for(l=0;l<i;l+=4)e=d[t.charCodeAt(l)]<<18|d[t.charCodeAt(l+1)]<<12|d[t.charCodeAt(l+2)]<<6|d[t.charCodeAt(l+3)],a[s++]=e>>16&255,a[s++]=e>>8&255,a[s++]=e&255;return o===2&&(e=d[t.charCodeAt(l)]<<2|d[t.charCodeAt(l+1)]>>4,a[s++]=e&255),o===1&&(e=d[t.charCodeAt(l)]<<10|d[t.charCodeAt(l+1)]<<4|d[t.charCodeAt(l+2)]>>2,a[s++]=e>>8&255,a[s++]=e&255),a}function Y(t){return c[t>>18&63]+c[t>>12&63]+c[t>>6&63]+c[t&63]}function Z(t,e,r){for(var n,o=[],a=e;a<r;a+=3)n=(t[a]<<16&16711680)+(t[a+1]<<8&65280)+(t[a+2]&255),o.push(Y(n));return o.join("")}function ee(t){for(var e,r=t.length,n=r%3,o=[],a=16383,s=0,i=r-n;s<i;s+=a)o.push(Z(t,s,s+a>i?i:s+a));return n===1?(e=t[r-1],o.push(c[e>>2]+c[e<<4&63]+"==")):n===2&&(e=(t[r-2]<<8)+t[r-1],o.push(c[e>>10]+c[e>>4&63]+c[e<<2&63]+"=")),o.join("")}});var fe={};V(fe,{parseMhtml:()=>ce});var q=U(w());var p=class{#e=new Map;[Symbol.iterator](){return this.entries()}append(e,r){let n=this.#e.get(e);n===void 0?this.#e.set(e,[r]):n.push(r)}*entries(e=", "){for(let[r,n]of this.#e.entries())yield[r,n.join(e)]}*entriesAll(){for(let[e,r]of this.#e.entries())for(let n of r)yield[e,n]}get(e,r=", "){let n=this.#e.get(e);return n===void 0?null:n.join(r)}getAll(e){return this.#e.get(e)??[]}has(e){return this.#e.has(e)}keys(){return this.#e.keys()}*values(e=", "){for(let r of this.#e.values())yield r.join(e)}*valuesAll(){for(let e of this.#e.values())yield*e}};var C=U(w());function te(t){return ArrayBuffer.isView(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):new Uint8Array(t)}function v(t,e){if(t.length!==e.length)return!1;if(t.byteOffset%4===e.byteOffset%4){let r=(4-t.byteOffset%4)%4,n=Math.floor((t.byteLength-r)/4),o=r+n*4,a=new Uint32Array(t.buffer,t.byteOffset+r,n),s=new Uint32Array(e.buffer,e.byteOffset+r,n);for(let i=0;i<r;++i)if(t[i]!==e[i])return!1;for(let i=0;i<n;++i)if(a[i]!==s[i])return!1;for(let i=o;i<t.length;++i)if(t[i]!==e[i])return!1;return!0}else{for(let r of t.keys())if(t[r]!==e[r])return!1;return!0}}function re(t,e){return t.findIndex((r,n)=>{if(r!==e[0]||n+e.length>t.length)return!1;for(let o=1;o<e.length;++o)if(t[n+o]!==e[o])return!1;return!0})}async function*k(t,e){let r=new Uint8Array(0);for await(let n of t){let o=te(n);r=r.length?E([r,o]):o;let a;for(;(a=re(r,e))!==-1;)yield r.subarray(0,a),r=r.subarray(a+e.length)}yield r}function E(t){let e=t.reduce((o,a)=>o+a.length,0),r=new Uint8Array(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return r}async function M(t){let e=[];for await(let r of t)e.push(r);return E(e)}var ne=new Uint8Array([10]);async function*L(t,e=ne){for await(let r of t){let n=new Uint8Array(r.length+e.length),o=!1,a=0;for(let s=0;s<r.length;++s){let i=r[s];if(i>=128)throw new Error(`got non-ascii character when decoding quoted printable: ${r}`);if(i!==61)n[a++]=i;else{let l=r[++s];if(l===void 0)o=!0;else{let u=r[++s];if(u===void 0)throw new Error("quoted printable escape (=) was not followed by two bytes");let y=parseInt(String.fromCharCode(l),16);y*=16,y+=parseInt(String.fromCharCode(u),16),n[a++]=y}}}o||(n.set(e,a),a+=e.length),yield n.subarray(0,a)}}var oe=new TextDecoder;async function*O(t){for await(let e of t)yield(0,C.toByteArray)(oe.decode(e))}async function*m(t){for await(let e of t)yield e}function H(){throw new Error("binary transfer-encoding is explicitly not supported and trying to add an implementation will likely result in unexpected results, but if you want to ignore anyway, set binary to `decode8bit`")}var $=new TextEncoder,D=new TextDecoder;function ae(t){let e=new Uint8Array(t.length),r=0;for(let n=0;n<t.length;++n){let o=t.charCodeAt(n),a;if(o>=128)throw new Error(`got non-ascii character when decoding q-quoted word: "${t}"`);o===95?a=32:o===61?(a=parseInt(t[++n],16),a*=16,a+=parseInt(t[++n],16)):a=o,e[r++]=a}return e.subarray(0,r)}var se=/^=\?([^?\s]+)\?([BQ])\?([^?\s]+)\?=$/;function T(t){let e=se.exec(t);if(e){let[,r,n,o]=e,a;if(n==="Q")a=ae(o);else if(n==="B")a=(0,q.toByteArray)(o);else throw new Error(`unknown encoding for header value encoding: ${n}`);return new TextDecoder(r).decode(a)}else return t}async function ie(t){let e=new p,r="",n="";for(;;){let{done:o,value:a}=await t.next();if(o)throw new Error("didn't find an empty line to signify the end of header parsing");let s=D.decode(a);if(/^\s/.test(s))n+=T(s.substr(1));else if(r&&e.append(r,n),s){let i=s.indexOf(": ");if(i===-1)throw new Error(`header line didn't have key-value delimiter: "${s}"`);r=s.slice(0,i),n=T(s.slice(i+2))}else return e}}var le=new Map([["7bit",m],["base64",O],["quoted-printable",L],["8bit",m],["binary",H]]);function de(t){let e=t.get("Content-Type");if(e===null)throw new Error(`first headers didn't contain a content type: ${JSON.stringify(Object.fromEntries(t))}`);let r,n=!1;for(let s of e.split(/;\s*/))s.startsWith("multipart/")?n=!0:s.startsWith("boundary=")&&(r=s.slice(9),r.startsWith('"')&&r.endsWith('"')&&(r=r.slice(1,-1)));if(!n||r===void 0)throw new Error("first content type header didn't contain 'multipart/...' and a boundary string");let o=$.encode(`--${r}`),a=$.encode(`--${r}--`);return[o,a]}async function*ce(t,{decoderOverrides:e=new Map}={}){let r=new Map([...le.entries(),...e.entries()]),n=new Uint8Array([13,10]),o=k(t,n),a=null,s=!0;for(;s;){let i=await ie(o),[l,u]=a??(a=de(i)),y=i.get("Content-Transfer-Encoding")??"7bit",I=r.get(y);if(I===void 0)throw new Error(`unhandled encoding type: ${y}`);let P=await M(I({[Symbol.asyncIterator](){return{async next(){let{done:S,value:A}=await o.next();if(S)throw new Error(`stream didn't end with the appropriate termination boundary: ${D.decode(u)}`);return v(A,l)?{done:!0,value:void 0}:v(A,u)?(s=!1,{done:!0,value:void 0}):{value:A}}}}}));yield{headers:i,content:P}}}return _(fe);})();
1
+ var mhtml=(()=>{var j=Object.create;var h=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var W=Object.getOwnPropertyNames;var N=Object.getPrototypeOf,J=Object.prototype.hasOwnProperty;var R=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),V=(t,e)=>{for(var r in e)h(t,r,{get:e[r],enumerable:!0})},x=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of W(e))!J.call(t,o)&&o!==r&&h(t,o,{get:()=>e[o],enumerable:!(n=Q(e,o))||n.enumerable});return t};var U=(t,e,r)=>(r=t!=null?j(N(t)):{},x(e||!t||!t.__esModule?h(r,"default",{value:t,enumerable:!0}):r,t)),_=t=>x(h({},"__esModule",{value:!0}),t);var w=R(g=>{"use strict";g.byteLength=G;g.toByteArray=X;g.fromByteArray=ee;var c=[],d=[],z=typeof Uint8Array<"u"?Uint8Array:Array,b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(f=0,F=b.length;f<F;++f)c[f]=b[f],d[b.charCodeAt(f)]=f;var f,F;d["-".charCodeAt(0)]=62;d["_".charCodeAt(0)]=63;function B(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=t.indexOf("=");r===-1&&(r=e);var n=r===e?0:4-r%4;return[r,n]}function G(t){var e=B(t),r=e[0],n=e[1];return(r+n)*3/4-n}function K(t,e,r){return(e+r)*3/4-r}function X(t){var e,r=B(t),n=r[0],o=r[1],a=new z(K(t,n,o)),s=0,i=o>0?n-4:n,l;for(l=0;l<i;l+=4)e=d[t.charCodeAt(l)]<<18|d[t.charCodeAt(l+1)]<<12|d[t.charCodeAt(l+2)]<<6|d[t.charCodeAt(l+3)],a[s++]=e>>16&255,a[s++]=e>>8&255,a[s++]=e&255;return o===2&&(e=d[t.charCodeAt(l)]<<2|d[t.charCodeAt(l+1)]>>4,a[s++]=e&255),o===1&&(e=d[t.charCodeAt(l)]<<10|d[t.charCodeAt(l+1)]<<4|d[t.charCodeAt(l+2)]>>2,a[s++]=e>>8&255,a[s++]=e&255),a}function Y(t){return c[t>>18&63]+c[t>>12&63]+c[t>>6&63]+c[t&63]}function Z(t,e,r){for(var n,o=[],a=e;a<r;a+=3)n=(t[a]<<16&16711680)+(t[a+1]<<8&65280)+(t[a+2]&255),o.push(Y(n));return o.join("")}function ee(t){for(var e,r=t.length,n=r%3,o=[],a=16383,s=0,i=r-n;s<i;s+=a)o.push(Z(t,s,s+a>i?i:s+a));return n===1?(e=t[r-1],o.push(c[e>>2]+c[e<<4&63]+"==")):n===2&&(e=(t[r-2]<<8)+t[r-1],o.push(c[e>>10]+c[e>>4&63]+c[e<<2&63]+"=")),o.join("")}});var fe={};V(fe,{parseMhtml:()=>ce});var q=U(w());var p=class{#e=new Map;[Symbol.iterator](){return this.entries()}append(e,r){let n=this.#e.get(e);n===void 0?this.#e.set(e,[r]):n.push(r)}*entries(e=", "){for(let[r,n]of this.#e.entries())yield[r,n.join(e)]}*entriesAll(){for(let[e,r]of this.#e.entries())for(let n of r)yield[e,n]}get(e,r=", "){let n=this.#e.get(e);return n===void 0?null:n.join(r)}getAll(e){return this.#e.get(e)??[]}has(e){return this.#e.has(e)}keys(){return this.#e.keys()}*values(e=", "){for(let r of this.#e.values())yield r.join(e)}*valuesAll(){for(let e of this.#e.values())yield*e}};var C=U(w());function te(t){return ArrayBuffer.isView(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):new Uint8Array(t)}function v(t,e){if(t.length!==e.length)return!1;if(t.byteOffset%4===e.byteOffset%4){let r=(4-t.byteOffset%4)%4,n=Math.floor((t.byteLength-r)/4),o=r+n*4,a=new Uint32Array(t.buffer,t.byteOffset+r,n),s=new Uint32Array(e.buffer,e.byteOffset+r,n);for(let i=0;i<r;++i)if(t[i]!==e[i])return!1;for(let i=0;i<n;++i)if(a[i]!==s[i])return!1;for(let i=o;i<t.length;++i)if(t[i]!==e[i])return!1;return!0}else{for(let r of t.keys())if(t[r]!==e[r])return!1;return!0}}function re(t,e){return t.findIndex((r,n)=>{if(r!==e[0]||n+e.length>t.length)return!1;for(let o=1;o<e.length;++o)if(t[n+o]!==e[o])return!1;return!0})}async function*k(t,e){let r=new Uint8Array(0);for await(let n of t){let o=te(n);r=r.length?E([r,o]):o;let a;for(;(a=re(r,e))!==-1;)yield r.subarray(0,a),r=r.subarray(a+e.length)}yield r}function E(t){let e=t.reduce((o,a)=>o+a.length,0),r=new Uint8Array(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return r}async function M(t){let e=[];for await(let r of t)e.push(r);return E(e)}var ne=new Uint8Array([10]);async function*L(t,e=ne){for await(let r of t){let n=new Uint8Array(r.length+e.length),o=!1,a=0;for(let s=0;s<r.length;++s){let i=r[s];if(i>=128)throw new Error(`got non-ascii character when decoding quoted printable: ${i}`);if(i!==61)n[a++]=i;else{let l=r[++s];if(l===void 0)o=!0;else{let u=r[++s];if(u===void 0)throw new Error("quoted printable escape (=) was not followed by two bytes");let y=parseInt(String.fromCharCode(l),16);y*=16,y+=parseInt(String.fromCharCode(u),16),n[a++]=y}}}o||(n.set(e,a),a+=e.length),yield n.subarray(0,a)}}var oe=new TextDecoder;async function*O(t){for await(let e of t)yield(0,C.toByteArray)(oe.decode(e))}async function*m(t){for await(let e of t)yield e}function H(){throw new Error("binary transfer-encoding is explicitly not supported and trying to add an implementation will likely result in unexpected results, but if you want to ignore anyway, set binary to `decode8bit`")}var $=new TextEncoder,D=new TextDecoder;function ae(t){let e=new Uint8Array(t.length),r=0;for(let n=0;n<t.length;++n){let o=t.charCodeAt(n),a;if(o>=128)throw new Error(`got non-ascii character when decoding q-quoted word: "${t}"`);o===95?a=32:o===61?(a=parseInt(t[++n],16),a*=16,a+=parseInt(t[++n],16)):a=o,e[r++]=a}return e.subarray(0,r)}var se=/^=\?([^?\s]+)\?([BQ])\?([^?\s]+)\?=$/;function T(t){let e=se.exec(t);if(e){let[,r,n,o]=e,a;if(n==="Q")a=ae(o);else if(n==="B")a=(0,q.toByteArray)(o);else throw new Error(`unknown encoding for header value encoding: ${n}`);return new TextDecoder(r).decode(a)}else return t}async function ie(t){let e=new p,r="",n="";for(;;){let{done:o,value:a}=await t.next();if(o)throw new Error("didn't find an empty line to signify the end of header parsing");let s=D.decode(a);if(/^\s/.test(s))n+=T(s.substr(1));else if(r&&e.append(r,n),s){let i=s.indexOf(": ");if(i===-1)throw new Error(`header line didn't have key-value delimiter: "${s}"`);r=s.slice(0,i),n=T(s.slice(i+2))}else return e}}var le=new Map([["7bit",m],["base64",O],["quoted-printable",L],["8bit",m],["binary",H]]);function de(t){let e=t.get("Content-Type");if(e===null)throw new Error(`first headers didn't contain a content type: ${JSON.stringify(Object.fromEntries(t))}`);let r,n=!1;for(let s of e.split(/;\s*/))s.startsWith("multipart/")?n=!0:s.startsWith("boundary=")&&(r=s.slice(9),r.startsWith('"')&&r.endsWith('"')&&(r=r.slice(1,-1)));if(!n||r===void 0)throw new Error("first content type header didn't contain 'multipart/...' and a boundary string");let o=$.encode(`--${r}`),a=$.encode(`--${r}--`);return[o,a]}async function*ce(t,{decoderOverrides:e=new Map}={}){let r=new Map([...le.entries(),...e.entries()]),n=new Uint8Array([13,10]),o=k(t,n),a=null,s=!0;for(;s;){let i=await ie(o),[l,u]=a??(a=de(i)),y=i.get("Content-Transfer-Encoding")??"7bit",I=r.get(y);if(I===void 0)throw new Error(`unhandled encoding type: ${y}`);let P=await M(I({[Symbol.asyncIterator](){return{async next(){let{done:S,value:A}=await o.next();if(S)throw new Error(`stream didn't end with the appropriate termination boundary: ${D.decode(u)}`);return v(A,l)?{done:!0,value:void 0}:v(A,u)?(s=!1,{done:!0,value:void 0}):{value:A}}}}}));yield{headers:i,content:P}}}return _(fe);})();
package/dist/index.d.ts CHANGED
@@ -9,6 +9,12 @@ export interface MhtmlFile {
9
9
  }
10
10
  /** The decoder of any Content-Transfer-Encoding */
11
11
  export interface Decoder {
12
+ /**
13
+ * decode lines
14
+ *
15
+ * @param lines - each line of raw bytes
16
+ * @returns data - decoded lines
17
+ */
12
18
  (lines: AsyncIterable<Uint8Array>): AsyncIterable<Uint8Array>;
13
19
  }
14
20
  /** options for mhtml parsing */
package/dist/index.js CHANGED
@@ -70,6 +70,7 @@ async function parseHeaders(iter) {
70
70
  let key = "";
71
71
  let val = "";
72
72
  for (;;) {
73
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
73
74
  const { done, value } = await iter.next();
74
75
  if (done) {
75
76
  throw new Error("didn't find an empty line to signify the end of header parsing");
@@ -167,6 +168,7 @@ export async function* parseMhtml(stream, { decoderOverrides = new Map() } = {})
167
168
  [Symbol.asyncIterator]() {
168
169
  return {
169
170
  async next() {
171
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
170
172
  const { done, value } = await lines.next();
171
173
  if (done) {
172
174
  throw new Error(`stream didn't end with the appropriate termination boundary: ${decoder.decode(terminus)}`);
package/dist/utils.js CHANGED
@@ -140,7 +140,7 @@ export async function* decodeQuotedPrintable(lines, newLine = defaultNewLine) {
140
140
  for (let ind = 0; ind < bytes.length; ++ind) {
141
141
  const code = bytes[ind];
142
142
  if (code >= 128) {
143
- throw new Error(`got non-ascii character when decoding quoted printable: ${bytes}`);
143
+ throw new Error(`got non-ascii character when decoding quoted printable: ${code}`);
144
144
  }
145
145
  if (code !== 61) {
146
146
  res[destInd++] = code;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mhtml-stream",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Zero dependency stream MHTML parser",
5
5
  "keywords": [
6
6
  "mhtml",
@@ -24,38 +24,42 @@
24
24
  "type": "module",
25
25
  "scripts": {
26
26
  "fmt": "prettier --cache --write 'src/*.ts' '*.json' bundle.mjs",
27
- "lint": "tsc && eslint --cache 'src/*.ts' && typedoc --emit none",
27
+ "lint:tsc": "pnpify tsc",
28
+ "lint:es": "pnpify eslint --cache 'src/*.ts'",
29
+ "lint:doc": "pnpify typedoc --emit none",
30
+ "lint": "yarn lint:tsc && yarn lint:es && yarn lint:doc",
28
31
  "test": "jest --coverage",
29
- "doc": "typedoc",
30
- "build": "tsc -p tsconfig.build.json && node bundle.mjs",
32
+ "doc": "pnpify typedoc",
33
+ "build": "pnpify tsc -p tsconfig.build.json && node bundle.mjs",
31
34
  "prepack": "yarn lint && yarn test && yarn build"
32
35
  },
33
36
  "dependencies": {
34
37
  "base64-js": "^1.5.1"
35
38
  },
36
39
  "devDependencies": {
37
- "@babel/core": "^7.20.2",
38
- "@babel/preset-env": "^7.20.2",
39
- "@babel/preset-typescript": "^7.18.6",
40
+ "@babel/core": "^7.22.5",
41
+ "@babel/preset-env": "^7.22.5",
42
+ "@babel/preset-typescript": "^7.22.5",
40
43
  "@types/base64-js": "^1.3.0",
41
- "@types/jest": "^29.2.3",
42
- "@types/node": "^18.11.9",
43
- "@typescript-eslint/eslint-plugin": "^5.43.0",
44
- "@typescript-eslint/parser": "^5.43.0",
44
+ "@types/jest": "^29.5.2",
45
+ "@types/node": "^20.3.3",
46
+ "@typescript-eslint/eslint-plugin": "^5.60.1",
47
+ "@typescript-eslint/parser": "^5.60.1",
45
48
  "@yarnpkg/esbuild-plugin-pnp": "^3.0.0-rc.15",
46
- "babel-jest": "^29.3.1",
47
- "chalk": "5.1.2",
48
- "esbuild": "^0.15.14",
49
- "eslint": "^8.27.0",
50
- "eslint-config-prettier": "^8.5.0",
51
- "eslint-plugin-jest": "^27.1.5",
52
- "eslint-plugin-spellcheck": "^0.0.19",
49
+ "@yarnpkg/pnpify": "^4.0.0-rc.47",
50
+ "babel-jest": "^29.5.0",
51
+ "chalk": "5.3.0",
52
+ "esbuild": "^0.18.10",
53
+ "eslint": "^8.44.0",
54
+ "eslint-config-prettier": "^8.8.0",
55
+ "eslint-plugin-jest": "^27.2.2",
56
+ "eslint-plugin-spellcheck": "^0.0.20",
53
57
  "eslint-plugin-tsdoc": "^0.2.17",
54
- "jest": "^29.3.1",
55
- "prettier": "^2.7.1",
56
- "prettier-plugin-organize-imports": "^3.2.0",
57
- "typedoc": "^0.23.21",
58
- "typescript": "4.8.4"
58
+ "jest": "^29.5.0",
59
+ "prettier": "^2.8.8",
60
+ "prettier-plugin-organize-imports": "^3.2.2",
61
+ "typedoc": "^0.24.8",
62
+ "typescript": "5.1.6"
59
63
  },
60
64
  "resolutions": {
61
65
  "minimist": "1.2.6",
@@ -94,9 +98,15 @@
94
98
  "extends": [
95
99
  "eslint:recommended",
96
100
  "plugin:@typescript-eslint/recommended",
101
+ "plugin:@typescript-eslint/recommended-requiring-type-checking",
97
102
  "plugin:jest/recommended",
98
103
  "prettier"
99
104
  ],
105
+ "parserOptions": {
106
+ "project": [
107
+ "./tsconfig.json"
108
+ ]
109
+ },
100
110
  "env": {
101
111
  "node": true
102
112
  },
@@ -149,5 +159,5 @@
149
159
  ]
150
160
  }
151
161
  },
152
- "packageManager": "yarn@3.2.4"
162
+ "packageManager": "yarn@3.6.0"
153
163
  }