Socket
Socket
Sign inDemoInstall

nodejs-file-downloader

Package Overview
Dependencies
Maintainers
1
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nodejs-file-downloader - npm Package Compare versions

Comparing version 4.1.1 to 4.2.0

41

Downloader.js

@@ -5,2 +5,4 @@ const fs = require('fs');

const stream = require('stream');
var HttpsProxyAgent = require('https-proxy-agent');
// const {WritableStream}= fs;

@@ -37,2 +39,6 @@ const { Transform } = require('stream')

mandatory: false
},
proxy: {
type: 'string',
mandatory: false
}

@@ -71,2 +77,3 @@ };

* @param {object} [config.httpsAgent = undefined]
* @param {string} [config.proxy = undefined]
* @param {function} [config.onError = undefined]

@@ -79,2 +86,3 @@ * @param {function} [config.onResponse = undefined]

constructor(config) {
// super();

@@ -93,2 +101,3 @@ if (!config || typeof config !== 'object') {

httpsAgent: undefined,
proxy:undefined,
headers: undefined,

@@ -107,2 +116,4 @@ cloneFiles: true,

if (this.config.filename) {

@@ -180,3 +191,3 @@ this.config.fileName = this.config.filename

const finalName = await this._getFinalFileName(response.headers);
const finalPath = `${this.config.directory}/${finalName}`;

@@ -190,3 +201,3 @@

// await this._saveFromBuffer(buffer, finalPath);
}else{
} else {
await this._saveFromReadableStream(response, tempPath);

@@ -196,4 +207,4 @@ // await this._saveFromReadableStream(response, finalPath);

// debugger;
await this._renameTempFileToFinalName(tempPath,finalPath)
await this._renameTempFileToFinalName(tempPath, finalPath)
} catch (error) {

@@ -241,11 +252,17 @@ // debugger

async _makeRequest() {
const httpsAgent = this.config.httpsAgent;
const {timeout,headers,proxy,url,httpsAgent} = this.config;
const options = {
timeout,
headers
}
if(httpsAgent){
options.httpsAgent = httpsAgent;
}
else if(proxy){
// debugger
options.httpsAgent = new HttpsProxyAgent(proxy)
}
// debugger
const response = await request(this.config.url, {
timeout: this.config.timeout,
headers: this.config.headers,
httpsAgent,
});
// console.log(options)
const response = await request(url, options);
// debugger;

@@ -252,0 +269,0 @@

{
"name": "nodejs-file-downloader",
"version": "4.1.1",
"version": "4.2.0",
"description": "A file downloader for NodeJs",

@@ -24,2 +24,3 @@ "main": "Downloader.js",

"follow-redirects": "^1.13.0",
"https-proxy-agent": "^5.0.0",
"mime-types": "^2.1.27",

@@ -26,0 +27,0 @@ "sanitize-filename": "^1.6.3"

@@ -18,2 +18,3 @@ nodejs-file-downloader is a simple utility for downloading files. It hides the complexity of dealing with streams, redirects, paths and duplicate file names. Can automatically repeat failed downloads.

* [Repeat failed downloads automatically](#repeat-failed-downloads-automatically)
* [Use a Proxy](#use-a-proxy)
- [Error handling](#error-handling)

@@ -162,3 +163,3 @@

try {
await downloader.dowload();
await downloader.download();
} catch (error) {//If all attempts fail, the last error is thrown.

@@ -174,2 +175,20 @@ console.log('Final fail',error)

#### Use a proxy
You can pass a proxy string. Under the hood, this will create a custom httpsAgent. This feature wasn't tested extensively.
```javascript
const downloader = new Downloader({
proxy:"http://username:password@some-proxy.com:22225",
url: 'http://212.183.159.230/200MB.zip',
directory: "./",
})
```
 
## Error handling

@@ -180,2 +199,2 @@

If the auto-repeat feature is enabled(by setting the maxAttempts to higher than 1), then only a failure of the final attempt will throw an error.
If the auto-repeat feature is enabled(by setting the maxAttempts to higher than 1), then only a failure of the final attempt will throw an error.

@@ -28,2 +28,3 @@ // const { read } = require('fs');

// debugger;
// console.log('headersss',headers)
const options = {

@@ -35,2 +36,3 @@ headers,

}
// debugger;

@@ -41,2 +43,3 @@ const protocol = url.trim().startsWith('https') ? https : http;

const request = protocol.request(url, options, (res) => {
// debugger;
readStream = res;

@@ -43,0 +46,0 @@ // debugger;

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