mirror of
https://github.com/jakejarvis/careful-downloader.git
synced 2025-04-26 07:45:23 -04:00
go back to simultaneously downloading the desired file and its checksums
This commit is contained in:
parent
249b0605f0
commit
97315225c1
15
index.js
15
index.js
@ -47,9 +47,6 @@ export default async (downloadUrl, options = {}) => {
|
|||||||
debug(`Temp dir generated: '${tempDir}'`);
|
debug(`Temp dir generated: '${tempDir}'`);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// get the desired file
|
|
||||||
await download(downloadUrl, path.join(tempDir, options.filename));
|
|
||||||
|
|
||||||
// validate the checksum of the download
|
// validate the checksum of the download
|
||||||
let validated = false;
|
let validated = false;
|
||||||
|
|
||||||
@ -57,8 +54,14 @@ export default async (downloadUrl, options = {}) => {
|
|||||||
debug("Using a downloaded checksum file to validate...");
|
debug("Using a downloaded checksum file to validate...");
|
||||||
|
|
||||||
const checksumFilename = new URL(checksumKey).pathname.split("/").pop();
|
const checksumFilename = new URL(checksumKey).pathname.split("/").pop();
|
||||||
await download(checksumKey, path.join(tempDir, checksumFilename));
|
|
||||||
|
|
||||||
|
// simultaneously download the desired file and its checksums
|
||||||
|
await Promise.all([
|
||||||
|
download(downloadUrl, path.join(tempDir, options.filename)),
|
||||||
|
download(checksumKey, path.join(tempDir, checksumFilename)),
|
||||||
|
]);
|
||||||
|
|
||||||
|
// validate the checksum
|
||||||
// eslint-disable-next-line max-len
|
// eslint-disable-next-line max-len
|
||||||
if (await checksumViaFile(path.join(tempDir, options.filename), path.join(tempDir, checksumFilename), options.algorithm, options.encoding)) {
|
if (await checksumViaFile(path.join(tempDir, options.filename), path.join(tempDir, checksumFilename), options.algorithm, options.encoding)) {
|
||||||
validated = true;
|
validated = true;
|
||||||
@ -66,6 +69,10 @@ export default async (downloadUrl, options = {}) => {
|
|||||||
} else if (checksumMethod === "string") {
|
} else if (checksumMethod === "string") {
|
||||||
debug("Using a provided hash to validate...");
|
debug("Using a provided hash to validate...");
|
||||||
|
|
||||||
|
// get the desired file
|
||||||
|
await download(downloadUrl, path.join(tempDir, options.filename));
|
||||||
|
|
||||||
|
// validate the checksum
|
||||||
// eslint-disable-next-line max-len
|
// eslint-disable-next-line max-len
|
||||||
if (await checksumViaString(path.join(tempDir, options.filename), checksumKey, options.algorithm, options.encoding)) {
|
if (await checksumViaString(path.join(tempDir, options.filename), checksumKey, options.algorithm, options.encoding)) {
|
||||||
validated = true;
|
validated = true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user