bigdownloader
Advanced tools
Comparing version 1.0.2 to 1.0.4
@@ -9,6 +9,7 @@ "use strict"; | ||
var jswget = require('jswget'); | ||
//var jswget = require('jswget'); | ||
var request = require('request'); | ||
function BigDownloader( opts ) { | ||
this.opts = util._extend({ | ||
@@ -22,3 +23,3 @@ url : undefined, | ||
}, opts); | ||
this.debug = function(){ | ||
@@ -29,29 +30,48 @@ if( this.opts.debug ) { | ||
}.bind(this); | ||
this.size = undefined; | ||
this.progressInterval = undefined; | ||
this.download = function( retry ){ | ||
jswget({ | ||
url : this.opts.url, | ||
downloadpath : path.dirname(this.opts.path) + '/', | ||
downloadas : path.basename(this.opts.path), | ||
downloadmode : true, | ||
onsend: function(req, options){ | ||
this.download = function( retry ){ | ||
this.debug('this.download', 'retry:', retry === true) | ||
var requestOpts = { | ||
url: this.opts.url, | ||
} | ||
try { | ||
var stats = fs.statSync(this.opts.path); | ||
requestOpts.headers = { | ||
'range': 'bytes=' + stats.size.toString() + '-' | ||
} | ||
} catch(e){} | ||
var writeStream = fs.createWriteStream( this.opts.path, { flags: 'a+' } ); | ||
function errCallback(err){ | ||
this.debug(err); | ||
this.download( true ); | ||
} | ||
request(requestOpts) | ||
.on('error', errCallback.bind(this)) | ||
.on('response', function(response) { | ||
if( retry ) return; | ||
this.emit('start'); | ||
if( this.progressInterval ) clearInterval(this.progressInterval); | ||
if( response.headers['content-length'] ) { | ||
this.size = parseInt(response.headers['content-length']); | ||
this.debug('got size from headers', this.size); | ||
} | ||
if( this.progressInterval ) clearInterval(this.progressInterval); | ||
this.progressInterval = setInterval(function(){ | ||
fs.stat( this.opts.path, function(err, stats){ | ||
if( err ) return this.debug(err); | ||
var total = this.opts.size || this.size; | ||
var done = stats.size; | ||
var percent = done / total; | ||
this.emit('progress', { | ||
@@ -62,22 +82,17 @@ total : total, | ||
}) | ||
}.bind(this)); | ||
}.bind(this), this.opts.progressInterval); | ||
}.bind(this), | ||
onhead: function(fstat, req, res){ | ||
if( retry ) return; | ||
if( res.headers['content-length'] ) { | ||
this.size = parseInt(res.headers['content-length']); | ||
this.debug('got size from headers', this.size); | ||
} | ||
}.bind(this), | ||
onsuccess: function(resp, req, res){ | ||
}.bind(this)) | ||
.pipe( writeStream ) | ||
.on('error', errCallback.bind(this)) | ||
.on('finish', function(){ | ||
this.debug('onFinish'); | ||
if( this.progressInterval ) clearInterval(this.progressInterval); | ||
if( typeof this.opts.size == 'number' ) { | ||
if( typeof this.opts.size == 'number' ) { | ||
var stats = fs.statSync( this.opts.path ); | ||
@@ -93,9 +108,9 @@ if( stats.size < this.opts.size ) { | ||
return this.download( true ); | ||
} | ||
} | ||
} | ||
if( typeof this.opts.hash == 'string' ) { | ||
var hasher = crypto.createHash('sha1'); | ||
hasher.setEncoding('hex'); | ||
var reader = fs.createReadStream( this.opts.path ); | ||
@@ -107,3 +122,3 @@ reader.pipe( hasher ); | ||
this.debug('calculated hash:', hash) | ||
if( hash == this.opts.hash ) { | ||
@@ -119,17 +134,11 @@ this.emit('finish'); | ||
} | ||
}.bind(this), | ||
onerror: function(err, req){ | ||
this.debug(err); | ||
this.download( true ); | ||
}.bind(this) | ||
}); | ||
}.bind(this)) | ||
}.bind(this); | ||
this.start = function(){ | ||
this.download(); | ||
}.bind(this); | ||
} | ||
@@ -136,0 +145,0 @@ |
{ | ||
"name": "bigdownloader", | ||
"version": "1.0.2", | ||
"version": "1.0.4", | ||
"description": "Download big files without worries. Included auto-resume", | ||
@@ -12,4 +12,4 @@ "main": "index.js", | ||
"dependencies": { | ||
"jswget": "git+https://github.com/athombv/jswget.git" | ||
"request": "^2.69.0" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Git dependency
Supply chain riskContains a dependency which resolves to a remote git URL. Dependencies fetched from git URLs are not immutable and can be used to inject untrusted code or reduce the likelihood of a reproducible install.
Found 1 instance in 1 package
5410
6
135
0
+ Addedrequest@^2.69.0
+ Addedajv@6.12.6(transitive)
+ Addedasn1@0.2.6(transitive)
+ Addedassert-plus@1.0.0(transitive)
+ Addedasynckit@0.4.0(transitive)
+ Addedaws-sign2@0.7.0(transitive)
+ Addedaws4@1.13.2(transitive)
+ Addedbcrypt-pbkdf@1.0.2(transitive)
+ Addedcaseless@0.12.0(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addedcore-util-is@1.0.2(transitive)
+ Addeddashdash@1.14.1(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addedecc-jsbn@0.1.2(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedextsprintf@1.3.0(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-json-stable-stringify@2.1.0(transitive)
+ Addedforever-agent@0.6.1(transitive)
+ Addedform-data@2.3.3(transitive)
+ Addedgetpass@0.1.7(transitive)
+ Addedhar-schema@2.0.0(transitive)
+ Addedhar-validator@5.1.5(transitive)
+ Addedhttp-signature@1.2.0(transitive)
+ Addedis-typedarray@1.0.0(transitive)
+ Addedisstream@0.1.2(transitive)
+ Addedjsbn@0.1.1(transitive)
+ Addedjson-schema@0.4.0(transitive)
+ Addedjson-schema-traverse@0.4.1(transitive)
+ Addedjson-stringify-safe@5.0.1(transitive)
+ Addedjsprim@1.4.2(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedoauth-sign@0.9.0(transitive)
+ Addedperformance-now@2.1.0(transitive)
+ Addedpsl@1.15.0(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedqs@6.5.3(transitive)
+ Addedrequest@2.88.2(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsshpk@1.18.0(transitive)
+ Addedtough-cookie@2.5.0(transitive)
+ Addedtunnel-agent@0.6.0(transitive)
+ Addedtweetnacl@0.14.5(transitive)
+ Addeduri-js@4.4.1(transitive)
+ Addeduuid@3.4.0(transitive)
+ Addedverror@1.10.0(transitive)