Comparing version 0.5.0 to 1.0.0
23
index.js
@@ -5,2 +5,4 @@ 'use strict' | ||
, URL = require('url') | ||
, http = require('http') | ||
, https = require('https') | ||
@@ -12,3 +14,8 @@ function download(url, dest, options) { | ||
return new Promise((resolve, reject) => { | ||
return new Promise((res, rej) => { | ||
let pending = true | ||
const resolve = (r) => (pending = false, res(r)) | ||
, reject = (e) => (pending = false, rej(e)) | ||
fs.stat(dest, (err, stat) => { | ||
@@ -20,3 +27,3 @@ if (err && err.code !== 'ENOENT') | ||
const req = require(parsedUrl.protocol.slice(0, -1)).request(Object.assign({ | ||
const req = (parsedUrl.protocol === 'https:' ? https : http).request(Object.assign({ | ||
method: options.method || 'GET', | ||
@@ -28,3 +35,3 @@ headers: Object.assign({ Range: 'bytes=' + start + '-' }, options.headers) | ||
if (res.statusCode === 416 && res.headers['content-range'] && res.headers['content-range'].slice(-2) !== '/0') | ||
return fs.unlink(dest, () => resolve(download(url, dest, options))) | ||
return fs.unlink(dest, () => resolve(pending && download(url, dest, options))) | ||
@@ -35,3 +42,3 @@ if (res.statusCode >= 400) | ||
if (res.headers.location) | ||
return resolve(download(res.headers.location, dest, options)) | ||
return resolve(pending && download(res.headers.location, dest, options)) | ||
@@ -62,7 +69,5 @@ if (!res.headers['content-range']) | ||
res.on('end', () => file.end()) | ||
file.on('finish', () => | ||
res.complete | ||
? resolve() | ||
: download(url, dest, options) | ||
) | ||
file.on('finish', () => { | ||
resolve(!res.complete && pending && download(url, dest, options)) | ||
}) | ||
}) | ||
@@ -69,0 +74,0 @@ |
{ | ||
"name": "downit", | ||
"version": "0.5.0", | ||
"version": "1.0.0", | ||
"description": "Resumeable downloader", | ||
"main": "index.js", | ||
"keywords": ["resumeable", "download", "get", "fetch", "resume", "continue", "wget"], | ||
"keywords": [ | ||
"resumeable", | ||
"download", | ||
"get", | ||
"fetch", | ||
"resume", | ||
"continue", | ||
"wget" | ||
], | ||
"author": "Rasmus Porsager <rasmus@porsager.com>", | ||
"repository": "porsager/downit", | ||
"license": "WTFPL" | ||
"license": "WTFPL", | ||
"bin": { | ||
"downit": "bin/downit" | ||
} | ||
} |
@@ -20,10 +20,25 @@ # Downit - Resume downloads in node | ||
headers: { Authorization: 'Bearer Of Good News' }, | ||
progress: (got, total) => console.log('Got', got, 'B of ', total, 'B'), | ||
progress: (got, total) => console.log('Got ', got, 'B of ', total, 'B'), | ||
onrequest: req => { /* The node request instance */ }, | ||
onresponse: req => { /* The node response instance */ } | ||
onresponse: res => { /* The node response instance */ } | ||
}).then(() => { | ||
console.log('Downed it') | ||
}).catch(e => { | ||
console.error('Dropped it') | ||
console.error('Dropped it, due to ', e) | ||
}) | ||
``` | ||
### CLI | ||
Downit also works on the command line. | ||
#### Installation | ||
``` | ||
npm i downit -g | ||
``` | ||
#### Usage | ||
``` | ||
downit url [dest] | ||
``` |
Network access
Supply chain riskThis module accesses the network.
Found 2 instances in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
4055
4
59
1
44
2
2