Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

careful-downloader

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

careful-downloader - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0

37

index.js

@@ -12,2 +12,3 @@ import path from "path";

export default async function downloader(downloadUrl, checksumUrl, options) {
// intialize options if none are set
options = options || {};

@@ -40,20 +41,22 @@

// validate the checksum of the download
await checkChecksum(options.tempDir, options.filename, "checksums.txt", options.algorithm, options.encoding);
if (await checkChecksum(options.tempDir, options.filename, "checksums.txt", options.algorithm, options.encoding)) {
// optionally clear the target directory of existing files
if (options.cleanDestDir) {
await fs.remove(options.destDir);
}
// optionally clear the target directory of existing files
if (options.cleanDestDir) {
await fs.remove(options.destDir);
}
// ensure the target directory exists
await fs.mkdirp(options.destDir);
// ensure the target directory exists
await fs.mkdirp(options.destDir);
if (options.extract) {
// decompress download and move resulting files to final destination
await decompress(path.join(options.tempDir, options.filename), options.destDir);
return options.destDir;
if (options.extract) {
// decompress download and move resulting files to final destination
await decompress(path.join(options.tempDir, options.filename), options.destDir);
return options.destDir;
} else {
// move verified download to final destination as-is
await fs.copy(path.join(options.tempDir, options.filename), path.join(options.destDir, options.filename));
return path.join(options.destDir, options.filename);
}
} else {
// move verified download to final destination as-is
await fs.copy(path.join(options.tempDir, options.filename), path.join(options.destDir, options.filename));
return path.join(options.destDir, options.filename);
throw new Error(`Invalid checksum for ${options.filename}.`);
}

@@ -72,3 +75,3 @@ } finally {

return await pipeline(
return pipeline(
got.stream(url, { followRedirect: true }), // GitHub releases redirect to unpredictable URLs

@@ -85,3 +88,3 @@ fs.createWriteStream(dest),

return await checker.validate(baseDir, downloadFile);
return checker.validate(baseDir, downloadFile);
}
{
"name": "careful-downloader",
"version": "1.1.0",
"version": "1.2.0",
"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",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc