Socket
Socket
Sign inDemoInstall

download

Package Overview
Dependencies
Maintainers
1
Versions
70
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

download - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

41

download.js
'use strict';
var decompress = require('decompress');
var fs = require('fs');
var mkdir = require('mkdirp');
var path = require('path');
var mkdir = require('mkdirp');
var request = require('request');
var decompress = require('decompress');
var stream = require('through2')();
/**
* Download a file to a given destination
*
* Options:
*
* - `extract` Try extracting the file
*
* @param {String} url
* @param {String} dest
* @param {Object} opts
*/
module.exports = function (url, dest, opts) {

@@ -24,21 +36,26 @@ opts = opts || {};

});
req.on('response', function (res) {
var mime = res.headers['content-type'];
var status = res.statusCode;
var end;
if (status < 200 || status >= 300) {
return;
}
if (opts.extract && decompress.canExtract(url, mime)) {
req.pipe(decompress.extract({ type: mime, path: dest }))
.on('close', function () {
stream.emit('close');
});
end = decompress.extract({ ext: mime, path: dest });
} else {
end = fs.createWriteStream(dest);
if (!fs.existsSync(path.dirname(dest))) {
mkdir.sync(path.dirname(dest));
}
}
req.pipe(fs.createWriteStream(dest))
.on('close', function () {
stream.emit('close');
});
}
req.pipe(end);
end.on('close', function () {
stream.emit('close');
});
});

@@ -45,0 +62,0 @@

{
"name": "download",
"version": "0.1.1",
"version": "0.1.2",
"description": "Download and extract files effortlessly",

@@ -34,3 +34,4 @@ "keywords": [

"devDependencies": {
"mocha": "~1.12.0"
"mocha": "~1.12.0",
"rimraf": "~2.2.2"
},

@@ -37,0 +38,0 @@ "engines": {

@@ -0,0 +0,0 @@ # download [![Build Status](https://secure.travis-ci.org/kevva/download.png?branch=master)](http://travis-ci.org/kevva/download)

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