Skip to content

Commit ee6ef75

Browse files
committed
refactor(jszip-cli): Use for loop
1 parent 986d624 commit ee6ef75

File tree

1 file changed

+25
-24
lines changed

1 file changed

+25
-24
lines changed

packages/jszip-cli/src/ExtractService.ts

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -58,37 +58,38 @@ export class ExtractService {
5858
entries.push([filePath, entry]);
5959
}
6060
});
61+
6162
let lastPercent = 0;
63+
let index = 0;
6264

63-
await Promise.all(
64-
entries.map(async ([filePath, entry], index) => {
65-
const resolvedFilePath = path.join(this.outputDir!, filePath);
66-
if (entry.dir) {
67-
await fs.ensureDir(resolvedFilePath);
68-
} else {
69-
const data = await entry.async('nodebuffer');
70-
await fs.writeFile(resolvedFilePath, data, {
71-
encoding: 'utf-8',
72-
});
65+
for (const [filePath, entry] of entries) {
66+
const resolvedFilePath = path.join(this.outputDir!, filePath);
67+
if (entry.dir) {
68+
await fs.ensureDir(resolvedFilePath);
69+
} else {
70+
const data = await entry.async('nodebuffer');
71+
await fs.writeFile(resolvedFilePath, data, {
72+
encoding: 'utf-8',
73+
});
7374

74-
this.extractedFilesCount++;
75+
this.extractedFilesCount++;
7576

76-
const diff = Math.floor(index / entries.length) - Math.floor(lastPercent);
77-
if (diff && !this.options.quiet) {
78-
this.progressBar.tick(diff);
79-
lastPercent = Math.floor(index / entries.length);
80-
}
77+
const diff = Math.floor(index / entries.length) - Math.floor(lastPercent);
78+
if (diff && !this.options.quiet) {
79+
this.progressBar.tick(diff);
80+
lastPercent = Math.floor(index / entries.length);
8181
}
82+
}
8283

83-
if (isWin32) {
84-
if (entry.dosPermissions) {
85-
await fs.chmod(resolvedFilePath, entry.dosPermissions);
86-
}
87-
} else if (entry.unixPermissions) {
88-
await fs.chmod(resolvedFilePath, entry.unixPermissions);
84+
if (isWin32) {
85+
if (entry.dosPermissions) {
86+
await fs.chmod(resolvedFilePath, entry.dosPermissions);
8987
}
90-
})
91-
);
88+
} else if (entry.unixPermissions) {
89+
await fs.chmod(resolvedFilePath, entry.unixPermissions);
90+
}
91+
index++;
92+
}
9293
}
9394
return this;
9495
}

0 commit comments

Comments
 (0)