careful-downloader
Advanced tools
Comparing version 1.3.1 to 1.3.2
24
index.js
@@ -12,6 +12,3 @@ import path from "path"; | ||
export default async function downloader(downloadUrl, checksumUrl, options) { | ||
// intialize options if none are set | ||
options = options || {}; | ||
export default async function downloader(downloadUrl, checksumUrl, options = {}) { | ||
// normalize options and set defaults | ||
@@ -72,8 +69,10 @@ options = { | ||
async function downloadFile(url, dest) { | ||
// get remote file and write locally | ||
const pipeline = promisify(stream.pipeline); | ||
return pipeline( | ||
const download = await pipeline( | ||
got.stream(url, { followRedirect: true }), // GitHub releases redirect to unpredictable URLs | ||
fs.createWriteStream(dest), | ||
); | ||
return download; | ||
} | ||
@@ -83,2 +82,3 @@ | ||
async function checkChecksum(baseDir, downloadFile, checksumFile, algorithm, encoding) { | ||
// instantiate checksum validator | ||
const checker = new sumchecker.ChecksumValidator(algorithm, path.join(baseDir, checksumFile), { | ||
@@ -88,3 +88,13 @@ defaultTextEncoding: encoding, | ||
return checker.validate(baseDir, downloadFile); | ||
// finally test the file | ||
const valid = await checker.validate(baseDir, downloadFile); | ||
return valid; | ||
} | ||
// eslint-disable-next-line no-unused-vars | ||
async function wait(ms) { | ||
return new Promise((resolve) => { | ||
setTimeout(resolve, ms); | ||
}); | ||
} |
{ | ||
"name": "careful-downloader", | ||
"version": "1.3.1", | ||
"version": "1.3.2", | ||
"description": "🕵️♀️ Downloads a file and its checksums to a temporary directory, validates the hash, and optionally extracts it if safe.", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10937
136