Skip to content

Commit 1c0dbf5

Browse files
committed
partially refactor onprogress function nested within listArchive function (index.ts)
1 parent 548b0c8 commit 1c0dbf5

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

src/index.ts

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -284,32 +284,36 @@ export const listArchive =
284284
name: string;
285285
};
286286

287+
// let beginningDone = false;
288+
287289
let entries: Entry[] = [];
288290

289291
if (buffer.length > 0) {
290292
data = buffer + data;
291293
buffer = '';
292294
}
293295

296+
const params = {
297+
path: 'Path = ',
298+
type: 'Type = ',
299+
method: 'Method = ',
300+
physicalSize: 'Physical Size = ',
301+
headersSize: 'Headers Size = ',
302+
};
303+
294304
data.split('\n').forEach(function (line) {
295305
// Populate the tech specs of the archive that are passed to the
296306
// resolve handler.
297-
if (line.substr(0, 7) === 'Path = ') {
298-
spec.path = line.substr(7, line.length);
299-
} else if (line.substr(0, 7) === 'Type = ') {
300-
spec.type = line.substr(7, line.length);
301-
} else if (line.substr(0, 9) === 'Method = ') {
302-
spec.method = line.substr(9, line.length);
303-
} else if (line.substr(0, 16) === 'Physical Size = ') {
304-
spec.physicalSize = parseInt(
305-
line.substr(16, line.length),
306-
10
307-
);
308-
} else if (line.substr(0, 15) === 'Headers Size = ') {
309-
spec.headersSize = parseInt(
310-
line.substr(15, line.length),
311-
10
312-
);
307+
if (line.startsWith(params.path)) {
308+
spec.path = line.slice(params.path.length);
309+
} else if (line.startsWith(params.type)) {
310+
spec.type = line.slice(params.type.length);
311+
} else if (line.startsWith(params.method)) {
312+
spec.method = line.slice(params.method.length);
313+
} else if (line.startsWith(params.physicalSize)) {
314+
spec.physicalSize = parseInt(line.slice(params.physicalSize.length), 10);
315+
} else if (line.startsWith(params.headersSize)) {
316+
spec.headersSize = parseInt(line.slice(params.headersSize.length), 10);
313317
} else {
314318
// Parse the stdout to find entries
315319
let res = regex.exec(line);

0 commit comments

Comments
 (0)