Skip to content
This repository was archived by the owner on Jan 14, 2022. It is now read-only.

Commit d615ba6

Browse files
author
Lucas Rojas
committed
Clean comments in download.js
1 parent 4a789c4 commit d615ba6

File tree

1 file changed

+0
-7
lines changed

1 file changed

+0
-7
lines changed

lib/download.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ function download (inputUri, outputFilePath, callback) {
1313
var uri = url.parse(inputUri);
1414

1515
if (inputUri.indexOf('http://') !== 0 && inputUri.indexOf('https://') !== 0) {
16-
// this is to detect scenarios like localhost:8080 where localhost is
17-
// treated as protocol even if it's not.
1816
if (inputUri.indexOf(uri.protocol + '//') !== 0) {
1917
inputUri = 'http://' + inputUri;
2018
uri = url.parse(inputUri);
@@ -55,33 +53,28 @@ function download (inputUri, outputFilePath, callback) {
5553
var deferred = Q.defer();
5654
protocol.get(options, function (res) {
5755

58-
// If Moved Permanently or Found, redirect to new URL
5956
if ([301, 302].indexOf(res.statusCode) > -1) {
6057
return download(res.headers.location, outputFilePath)
6158
.then(function (result) { deferred.resolve(result); })
6259
.catch(function (err) { deferred.reject(err); });
6360
}
6461

65-
// If not OK or Not Modified, throw error
6662
if ([200, 304].indexOf(res.statusCode) === -1) {
6763
var err = new Error('Error downloading \'' + inputUri + '\'. Response was \'' + res.statusCode + ' - ' + res.statusMessage + '\'.');
6864
err.statusCode = res.statusCode;
6965
err.statusMessage = res.statusMessage;
7066
return deferred.reject(err);
7167
}
7268

73-
// If Not Modified, ignore
7469
if (res.statusCode === 304) {
7570
return deferred.resolve({ 'path': outputFilePath, 'statusCode': res.statusCode, 'statusMessage': res.statusMessage, 'contentType': res.headers['content-type'] });
7671
}
7772

78-
// Else save
7973
res.pipe(fs.createWriteStream(outputFilePath))
8074
.on('close', function () {
8175
var lastAccessed = new Date();
8276
var lastModified = res.headers['last-modified'] ? new Date(res.headers['last-modified']) : lastAccessed;
8377

84-
// update the last modified time of the file to match the response header
8578
fs.utimes(outputFilePath, lastAccessed, lastModified, function (err) {
8679
if (err) {
8780
return deferred.reject(err);

0 commit comments

Comments
 (0)