meros
Advanced tools
Comparing version 1.2.0-next.1 to 1.2.0-next.2
const separator = '\r\n\r\n'; | ||
const decoder = new TextDecoder; | ||
async function* generate(stream, boundary, options) { | ||
boundary = '\r\n' + boundary; | ||
const reader = stream.getReader(), is_eager = !options || !options.multiple; | ||
@@ -31,3 +32,3 @@ let buffer = '', is_preamble = true, payloads = []; | ||
const idx_headers = current.indexOf(separator); | ||
const arr_headers = buffer.slice(0, idx_headers).toString().trim().split(/\r\n/); | ||
const arr_headers = buffer.slice(0, idx_headers).trim().split(/\r\n/); | ||
// parse headers | ||
@@ -39,3 +40,4 @@ let tmp; | ||
} | ||
let body = current.substring(idx_headers + separator.length, current.lastIndexOf('\r\n')); | ||
const last_idx = current.lastIndexOf('\r\n', idx_headers + separator.length); | ||
let body = current.substring(idx_headers + separator.length, last_idx > -1 ? undefined : last_idx); | ||
let is_json = false; | ||
@@ -42,0 +44,0 @@ tmp = headers['content-type']; |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).meros={})}(this,(function(e){const t="\r\n\r\n",n=new TextDecoder;e.meros=async function(e,i){if(!e.ok||!e.body||e.bodyUsed)return e;const o=e.headers.get("content-type");if(!o||!~o.indexOf("multipart/mixed"))return e;const s=o.indexOf("boundary=");return async function*(e,i,o){const s=e.getReader(),r=!o||!o.multiple;let d="",f=!0,l=[];try{let e;e:for(;!(e=await s.read()).done;){const o=n.decode(e.value),s=o.indexOf(i);let c=d.length;for(d+=o,~s?c+=s:c=d.indexOf(i),l=[];~c;){const e=d.substring(0,c),n=d.substring(c+i.length);if(f)f=!1;else{const i={},o=e.indexOf(t),s=d.slice(0,o).toString().trim().split(/\r\n/);let f;for(;f=s.shift();)f=f.split(": "),i[f.shift().toLowerCase()]=f.join(": ");let c=e.substring(o+t.length,e.lastIndexOf("\r\n")),a=!1;if(f=i["content-type"],f&&~f.indexOf("application/json"))try{c=JSON.parse(c),a=!0}catch(e){}if(f={headers:i,body:c,json:a},r?yield f:l.push(f),"--"===n.substring(0,2))break e}d=n,c=d.indexOf(i)}l.length&&(yield l)}}finally{l.length&&(yield l),s.releaseLock()}}(e.body,`--${~s?o.substring(s+9).trim().replace(/['"]/g,""):"-"}`,i)}})); | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).meros={})}(this,(function(e){const n="\r\n\r\n",t=new TextDecoder;e.meros=async function(e,i){if(!e.ok||!e.body||e.bodyUsed)return e;const o=e.headers.get("content-type");if(!o||!~o.indexOf("multipart/mixed"))return e;const s=o.indexOf("boundary=");return async function*(e,i,o){i="\r\n"+i;const s=e.getReader(),r=!o||!o.multiple;let d="",f=!0,l=[];try{let e;e:for(;!(e=await s.read()).done;){const o=t.decode(e.value),s=o.indexOf(i);let c=d.length;for(d+=o,~s?c+=s:c=d.indexOf(i),l=[];~c;){const e=d.substring(0,c),t=d.substring(c+i.length);if(f)f=!1;else{const i={},o=e.indexOf(n),s=d.slice(0,o).trim().split(/\r\n/);let f;for(;f=s.shift();)f=f.split(": "),i[f.shift().toLowerCase()]=f.join(": ");const c=e.lastIndexOf("\r\n",o+n.length);let a=e.substring(o+n.length,c>-1?void 0:c),u=!1;if(f=i["content-type"],f&&~f.indexOf("application/json"))try{a=JSON.parse(a),u=!0}catch(e){}if(f={headers:i,body:a,json:u},r?yield f:l.push(f),"--"===t.substring(0,2))break e}d=t,c=d.indexOf(i)}l.length&&(yield l)}}finally{l.length&&(yield l),s.releaseLock()}}(e.body,`--${~s?o.substring(s+9).trim().replace(/['"]/g,""):"-"}`,i)}})); |
const separator = '\r\n\r\n'; | ||
async function* generate(stream, boundary, options) { | ||
boundary = '\r\n' + boundary; | ||
const len_boundary = Buffer.byteLength(boundary), is_eager = !options || !options.multiple; | ||
@@ -34,3 +35,4 @@ let buffer = Buffer.alloc(0), is_preamble = true, payloads = []; | ||
} | ||
let body = current.slice(idx_headers + separator.length, current.lastIndexOf('\r\n')); | ||
const last_idx = current.lastIndexOf('\r\n', idx_headers + separator.length); | ||
let body = current.slice(idx_headers + separator.length, last_idx > -1 ? undefined : last_idx); | ||
let is_json = false; | ||
@@ -37,0 +39,0 @@ tmp = headers['content-type']; |
{ | ||
"name": "meros", | ||
"version": "1.2.0-next.1", | ||
"description": "A fast 575B utility that makes reading multipart responses simple", | ||
"version": "1.2.0-next.2", | ||
"description": "A fast 610B utility that makes reading multipart responses simple", | ||
"keywords": [ | ||
@@ -6,0 +6,0 @@ "defer", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
29295
512