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.2.1 to 0.2.2

84

index.js

@@ -8,2 +8,3 @@ 'use strict';

var path = require('path');
var Ware = require('ware');

@@ -19,2 +20,3 @@ /**

this._url = [];
this.ware = new Ware();
this.opts = opts || {};

@@ -56,2 +58,14 @@ this.opts.encoding = null;

/**
* Add a plugin to the middleware stack
*
* @param {Function} plugin
* @api public
*/
Download.prototype.use = function (plugin) {
this.ware.use(plugin);
return this;
};
/**
* Set proxy

@@ -88,29 +102,22 @@ *

var opts = assign(self.opts, obj.opts);
var ret = [];
request.get(obj.url, opts, function (err, res, data) {
if (err) {
return done(err);
}
request.get(obj.url, opts)
.on('error', done)
if (res.statusCode < 200 || res.statusCode >= 300) {
return done(res.statusCode);
}
.on('data', function (data) {
ret.push(data);
})
if (opts.extract) {
return self._extract(data, obj.dest, opts, function (err) {
if (err) {
return done(err);
}
.on('response', function (res) {
if (res.statusCode < 200 || res.statusCode >= 300) {
return done(res.statusCode);
}
done(err);
});
}
self._run(res);
})
fs.outputFile(path.join(obj.dest, name), data, function (err) {
if (err) {
return done(err);
}
if (opts.mode) {
return fs.chmod(path.join(obj.dest, name), opts.mode, function (err) {
.on('end', function () {
if (opts.extract) {
return self._extract(Buffer.concat(ret), obj.dest, opts, function (err) {
if (err) {

@@ -120,9 +127,24 @@ return done(err);

done();
done(err);
});
}
done();
fs.outputFile(path.join(obj.dest, name), Buffer.concat(ret), function (err) {
if (err) {
return done(err);
}
if (opts.mode) {
return fs.chmod(path.join(obj.dest, name), opts.mode, function (err) {
if (err) {
return done(err);
}
done();
});
}
done();
});
});
});
}, function (err) {

@@ -138,2 +160,14 @@ if (err) {

/**
* Run the response through the middleware
*
* @param {Object} res
* @param {Function} cb
* @api public
*/
Download.prototype._run = function (res) {
this.ware.run(res, this);
};
/**
* Extract archive

@@ -140,0 +174,0 @@ *

{
"name": "download",
"version": "0.2.1",
"version": "0.2.2",
"description": "Download and extract files effortlessly",

@@ -33,3 +33,4 @@ "license": "MIT",

"object-assign": "^0.3.1",
"request": "^2.34.0"
"request": "^2.34.0",
"ware": "^0.3.0"
},

@@ -36,0 +37,0 @@ "devDependencies": {

@@ -22,3 +22,4 @@ # download [![Build Status](https://travis-ci.org/kevva/download.svg?branch=master)](https://travis-ci.org/kevva/download)

.get('http://example.com/bar.jpg', 'destFolder')
.get({ url: 'http://example.com/bar.jpg', name: 'foobar.jpg' }, 'destFolder');
.get({ url: 'http://example.com/bar.jpg', name: 'foobar.jpg' }, 'destFolder')
.use(Download.progress());

@@ -48,2 +49,6 @@ download.run(function (err) {

### .use(plugin)
Adds a plugin to the middleware stack.
### .proxy(proxy)

@@ -50,0 +55,0 @@

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