Skip to content

Commit

Permalink
chore: prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
sgarner committed Mar 18, 2024
1 parent 68d8e1e commit 7d73465
Showing 1 changed file with 32 additions and 17 deletions.
49 changes: 32 additions & 17 deletions scripts/postinstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,22 @@ const request = async (url, options) => {
.end();
});

if (response.statusCode >= 300 && response.statusCode < 400 && response.headers.location) {
if (
response.statusCode >= 300 &&
response.statusCode < 400 &&
response.headers.location
) {
// Handle redirect
return request(response.headers.location, {
...options,
auth: null
auth: null,
});
}

if (response.statusCode !== 200) {
throw new Error(`Request failed to ${url} - ${response.statusCode} ${response.statusMessage}`);
throw new Error(
`Request failed to ${url} - ${response.statusCode} ${response.statusMessage}`
);
}

return response;
Expand Down Expand Up @@ -116,20 +122,29 @@ const main = async () => {

const response = await request(link(editionId));
const entryPromises = [];
await new Promise((resolve, reject) => response
.pipe(zlib.createGunzip())
.pipe(tar.t())
.on('entry', (entry) => {
if (entry.path.endsWith('.mmdb')) {
const dstFilename = path.join(downloadPath, path.basename(entry.path));
console.log(`writing ${dstFilename} ...`);
entryPromises.push(new Promise((resolve, reject) => {
entry.pipe(fs.createWriteStream(dstFilename)).on('finish', resolve).on('error', reject);
}));
}
})
.on('end', resolve)
.on('error', reject)
await new Promise((resolve, reject) =>
response
.pipe(zlib.createGunzip())
.pipe(tar.t())
.on('entry', (entry) => {
if (entry.path.endsWith('.mmdb')) {
const dstFilename = path.join(
downloadPath,
path.basename(entry.path)
);
console.log(`writing ${dstFilename} ...`);
entryPromises.push(
new Promise((resolve, reject) => {
entry
.pipe(fs.createWriteStream(dstFilename))
.on('finish', resolve)
.on('error', reject);
})
);
}
})
.on('end', resolve)
.on('error', reject)
);
await Promise.all(entryPromises);
}
Expand Down

0 comments on commit 7d73465

Please sign in to comment.