Skip to content

Commit 641ef80

Browse files
committed
Simplify boundary extraction
Handle error condition first
1 parent fc08e79 commit 641ef80

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

modules/io.mjs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3295,19 +3295,20 @@ class TFile {
32953295

32963296
// multipart messages requires special handling
32973297

3298-
const indx = hdr.indexOf('boundary='), view = new DataView(res);
3299-
let boundary = '';
3300-
if (indx > 0) {
3301-
boundary = hdr.slice(indx + 9);
3302-
if ((boundary[0] === '"') && (boundary.at(-1) === '"'))
3303-
boundary = boundary.slice(1, boundary.length - 1);
3304-
boundary = '--' + boundary;
3305-
} else {
3298+
const indx = hdr.indexOf('boundary=');
3299+
if (indx <= 0) {
33063300
console.error('Did not found boundary id in the response header - fallback to single range request');
33073301
return send_new_request('noranges');
33083302
}
33093303

3310-
for(let n = first, o = 0; n < last; n += 2) {
3304+
let boundary = hdr.slice(indx + 9);
3305+
if ((boundary[0] === '"') && (boundary.at(-1) === '"'))
3306+
boundary = boundary.slice(1, boundary.length - 1);
3307+
boundary = '--' + boundary;
3308+
3309+
const view = new DataView(res);
3310+
3311+
for (let n = first, o = 0; n < last; n += 2) {
33113312
let code1, code2 = view.getUint8(o), nline = 0, line = '',
33123313
finish_header = false, segm_start = 0, segm_last = -1;
33133314

0 commit comments

Comments
 (0)