mirror: A fast utility that makes reading multipart responses simple
0

Configure Feed

Select the types of activity you want to include in your feed.

chore: golf, removes `is_preamble` assignment

Marais Rossouw (May 17, 2023, 9:25 PM +1000) 473c268c d9f83fe1

+8 -10
+4 -5
src/browser.ts
··· 14 14 15 15 let len_boundary = boundary.length; 16 16 let buffer = ''; 17 - let is_preamble = true; 18 17 let payloads = []; 19 - let idx_boundary = 0; 18 + let idx_boundary; 19 + let in_main; 20 20 let tmp; 21 21 22 22 try { ··· 39 39 let current = buffer.slice(0, idx_boundary); 40 40 let next = buffer.slice(idx_boundary + len_boundary); 41 41 42 - if (is_preamble) { 43 - is_preamble = false; 42 + if (!in_main) { 44 43 boundary = '\r\n' + boundary; 45 - len_boundary += 2; 44 + in_main = len_boundary += 2; 46 45 } else { 47 46 let idx_headers = current.indexOf('\r\n\r\n') + 4; // 4 -> '\r\n\r\n'.length 48 47 let last_idx = current.lastIndexOf('\r\n', idx_headers);
+4 -5
src/node.ts
··· 13 13 14 14 let len_boundary = Buffer.byteLength(boundary); 15 15 let buffer = Buffer.alloc(0); 16 - let is_preamble = true; 17 16 let payloads = []; 18 - let idx_boundary = 0; 17 + let idx_boundary; 18 + let in_main; 19 19 let tmp; 20 20 21 21 outer: for await (let chunk of stream) { ··· 34 34 let current = buffer.subarray(0, idx_boundary); 35 35 let next = buffer.subarray(idx_boundary + len_boundary); 36 36 37 - if (is_preamble) { 38 - is_preamble = false; 37 + if (!in_main) { 39 38 boundary = '\r\n' + boundary; 40 - len_boundary += 2; 39 + in_main = len_boundary += 2; 41 40 } else { 42 41 let idx_headers = current.indexOf('\r\n\r\n') + 4; // 4 -> '\r\n\r\n'.length 43 42 let last_idx = current.lastIndexOf('\r\n', idx_headers);