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

wget-improved

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wget-improved - npm Package Compare versions

Comparing version 0.9.3 to 1.0.0

48

lib/wget.js

@@ -7,11 +7,20 @@ 'use strict'

var url = require('url');
var util = require('util');
var zlib = require('zlib');
var fs = require('fs');
var EventEmitter = require('events').EventEmitter;
function download(src, output, options, redirects) {
/**
* Downloads a file using http get and request
* @param {string} src - The http URL to download from
* @param {string} output - The filepath to save to
* @param {object} options - Options object
* @param {object} _parentEvent - Used for when their is a 302 redirect and need to maintain state to a new request
* @param {number} redirects - The number of redirects, used to prevent infinite loops
* @returns {*|EventEmitter}
*/
function download(src, output, options, _parentEvent, redirects) {
if(typeof redirects === "undefined") {
redirects = 0;
}
var downloader = new EventEmitter(),
var downloader = _parentEvent || new EventEmitter(),
srcUrl,

@@ -36,9 +45,11 @@ tunnelAgent,

var fileSize, writeStream, downloadedSize;
var gunzip = zlib.createGunzip();
// Handle 302 redirects
if(res.statusCode === 302) {
redirects++;
if(redirects >= 6) {
return downloader.emit('error', 'Infinite redirect loop detected');
if(redirects >= 10) {
downloader.emit('error', 'Infinite redirect loop detected');
}
return download(res.headers.location, output, options, redirects);
download(res.headers.location, output, options, downloader, redirects);
}

@@ -50,3 +61,3 @@

writeStream = fs.createWriteStream(output, {
flags: 'a',
flags: 'w+',
encoding: 'binary'

@@ -59,10 +70,27 @@ });

});
var encoding = "";
if(typeof res.headers['content-encoding'] === "string") {
encoding = res.headers['content-encoding'];
}
// If the user has specified to unzip, and the file is gzip encoded, pipe to gunzip
if(options.gunzip === true && encoding === "gzip") {
res.pipe(gunzip);
} else {
res.pipe(writeStream);
}
// Data handlers
res.on('data', function(chunk) {
downloadedSize += chunk.length;
downloader.emit('progress', downloadedSize/fileSize);
});
gunzip.on('data', function(chunk) {
writeStream.write(chunk);
});
res.on('end', function() {
writeStream.on('finish', function() {
writeStream.end();
downloader.emit('end', output);
downloader.emit('end', "Finished writing to disk");
req.end('finished');
});

@@ -74,3 +102,3 @@ } else {

req.end();
req.end('done');
req.on('error', function(err) {

@@ -77,0 +105,0 @@ downloader.emit('error', err);

{
"name": "wget-improved",
"version": "0.9.3",
"version": "1.0.0",
"description": "wget in nodejs, forked from wget to add improvements and help maintain the project",

@@ -5,0 +5,0 @@ "keywords": ["download", "http", "https", "ftp", "proxy", "wget"],

@@ -9,2 +9,4 @@ # wget-improved

- Better error reporting
- Does not write using append (now uses w+ identical to wget)
- Handles gzip compression, allow you to automatically gunzip the stream

@@ -73,2 +75,4 @@

options = {}
// Set to true to have any gzip stream automatically decompressed before saving
options.gunzip = false;
options.proxy = {};

@@ -81,1 +85,5 @@ options.proxy.protocol = 'http';

```
#Todo
Enable gzip when using request method
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