mongodb-download
Advanced tools
Comparing version 2.1.6 to 2.2.0
@@ -38,3 +38,7 @@ export interface IMongoDBDownloadOptions { | ||
isExtractPresent(): Promise<boolean>; | ||
getMD5HashFileLocation(): Promise<string>; | ||
cacheMD5Hash(signature: string): Promise<void>; | ||
getMD5Hash(): Promise<string>; | ||
getMD5HashOnline(): Promise<string>; | ||
getMD5HashOffline(): Promise<string>; | ||
httpDownload(httpOptions: any, downloadLocation: string, tempDownloadLocation: string): Promise<string>; | ||
@@ -41,0 +45,0 @@ getCrReturn(): string; |
@@ -103,2 +103,4 @@ "use strict"; | ||
resolve(extractLocation); | ||
}, function (e) { | ||
_this.debug('extract() failed', extractLocation, e); | ||
}); | ||
@@ -187,5 +189,48 @@ }); | ||
}; | ||
MongoDBDownload.prototype.getMD5HashFileLocation = function () { | ||
var _this = this; | ||
return new Promise(function (resolve, reject) { | ||
_this.getDownloadLocation().then(function (downloadLocation) { | ||
var md5HashLocation = downloadLocation + ".md5"; | ||
resolve(md5HashLocation); | ||
}, function (e) { | ||
console.error("error @ getMD5HashFileLocation", e); | ||
reject(e); | ||
}); | ||
}); | ||
}; | ||
MongoDBDownload.prototype.cacheMD5Hash = function (signature) { | ||
var _this = this; | ||
return new Promise(function (resolve, reject) { | ||
_this.getMD5HashFileLocation().then(function (hashFile) { | ||
fs.outputFile(hashFile, signature, function (err) { | ||
if (err) { | ||
_this.debug('@cacheMD5Hash unable to save signature', signature); | ||
reject(); | ||
} | ||
else { | ||
resolve(); | ||
} | ||
}); | ||
}); | ||
}); | ||
}; | ||
MongoDBDownload.prototype.getMD5Hash = function () { | ||
var _this = this; | ||
return new Promise(function (resolve, reject) { | ||
_this.getMD5HashOffline().then(function (signature) { | ||
resolve(signature); | ||
}, function (e) { | ||
_this.getMD5HashOnline().then(function (signature) { | ||
resolve(signature); | ||
}, function (e) { | ||
console.error('unable to get signature content', e); | ||
reject(e); | ||
}); | ||
}); | ||
}); | ||
}; | ||
MongoDBDownload.prototype.getMD5HashOnline = function () { | ||
var _this = this; | ||
return new Promise(function (resolve, reject) { | ||
_this.getDownloadURIMD5().then(function (md5URL) { | ||
@@ -197,2 +242,3 @@ request(md5URL).then(function (signatureContent) { | ||
_this.debug("getDownloadMD5Hash: " + signature); | ||
_this.cacheMD5Hash(signature).then(function () { }, function () { }); | ||
resolve(signature); | ||
@@ -206,2 +252,18 @@ }, function (e) { | ||
}; | ||
MongoDBDownload.prototype.getMD5HashOffline = function () { | ||
var _this = this; | ||
return new Promise(function (resolve, reject) { | ||
_this.getMD5HashFileLocation().then(function (hashFile) { | ||
fs.readFile(hashFile, 'utf8', function (err, signature) { | ||
if (err) { | ||
_this.debug('error @ getMD5HashOffline, unable to read hash content', hashFile); | ||
reject(); | ||
} | ||
else { | ||
resolve(signature); | ||
} | ||
}); | ||
}); | ||
}); | ||
}; | ||
MongoDBDownload.prototype.httpDownload = function (httpOptions, downloadLocation, tempDownloadLocation) { | ||
@@ -244,3 +306,3 @@ var _this = this; | ||
var stats = fs.lstatSync(location); | ||
this.debug("sending file from cache"); | ||
this.debug("sending file from cache", location); | ||
exists = true; | ||
@@ -247,0 +309,0 @@ } |
{ | ||
"name": "mongodb-download", | ||
"version": "2.1.6", | ||
"version": "2.2.0", | ||
"description": "download mongodb prebuilt packages from mongodb", | ||
"main": "built/mongodb-download.js", | ||
"main": "built/mongodb-download.js", | ||
"bin": "built/mongodb-download-cli.js", | ||
"types": "built/mongodb-download.d.ts", | ||
"types": "built/mongodb-download.d.ts", | ||
"scripts": { | ||
@@ -35,7 +35,7 @@ "test": "mocha" | ||
"devDependencies": { | ||
"@types/node": "^6.0.58", | ||
"mocha": "^3.2.0", | ||
"chai": "^3.5.0" | ||
"@types/node": "^6.0.70", | ||
"chai": "^3.5.0", | ||
"mocha": "^3.2.0" | ||
}, | ||
"homepage": "https://github.com/winfinit/mongodb-download#readme" | ||
} | ||
} |
@@ -133,2 +133,4 @@ const os: any = require('os'); | ||
resolve(extractLocation); | ||
}, (e: any) => { | ||
this.debug('extract() failed', extractLocation, e); | ||
}); | ||
@@ -217,5 +219,47 @@ }); | ||
} | ||
getMD5HashFileLocation(): Promise<string> { | ||
return new Promise<string>((resolve, reject) => { | ||
this.getDownloadLocation().then((downloadLocation: string) => { | ||
let md5HashLocation: string = `${downloadLocation}.md5`; | ||
resolve(md5HashLocation); | ||
}, (e) => { | ||
console.error("error @ getMD5HashFileLocation", e); | ||
reject(e); | ||
}); | ||
}); | ||
} | ||
cacheMD5Hash(signature: string): Promise<void> { | ||
return new Promise<void>((resolve, reject) => { | ||
this.getMD5HashFileLocation().then((hashFile: string) => { | ||
fs.outputFile(hashFile, signature, (err: any) => { | ||
if ( err ) { | ||
this.debug('@cacheMD5Hash unable to save signature', signature); | ||
reject(); | ||
} else { | ||
resolve(); | ||
} | ||
}); | ||
}); | ||
}); | ||
} | ||
getMD5Hash(): Promise<string> { | ||
return new Promise<string>((resolve, reject) => { | ||
this.getMD5HashOffline().then((signature: string) => { | ||
resolve(signature); | ||
}, (e: any) => { | ||
this.getMD5HashOnline().then((signature: string) => { | ||
resolve(signature); | ||
}, (e: any) => { | ||
console.error('unable to get signature content', e); | ||
reject(e); | ||
}); | ||
}); | ||
}); | ||
} | ||
getMD5HashOnline(): Promise<string> { | ||
return new Promise<string>((resolve, reject) => { | ||
this.getDownloadURIMD5().then((md5URL) => { | ||
@@ -227,2 +271,3 @@ request(md5URL).then((signatureContent: string) => { | ||
this.debug(`getDownloadMD5Hash: ${signature}`); | ||
this.cacheMD5Hash(signature).then(() => {}, () => {}); | ||
resolve(signature); | ||
@@ -233,2 +278,17 @@ }, (e: any) => { | ||
}); | ||
}) | ||
}); | ||
} | ||
getMD5HashOffline(): Promise<string> { | ||
return new Promise<string>((resolve, reject) => { | ||
this.getMD5HashFileLocation().then((hashFile: string) => { | ||
fs.readFile(hashFile, 'utf8', (err: any, signature: string) => { | ||
if ( err ) { | ||
this.debug('error @ getMD5HashOffline, unable to read hash content', hashFile); | ||
reject(); | ||
} else { | ||
resolve(signature); | ||
} | ||
}); | ||
}); | ||
@@ -280,3 +340,3 @@ }); | ||
let stats: any = fs.lstatSync(location); | ||
this.debug("sending file from cache"); | ||
this.debug("sending file from cache", location); | ||
exists = true; | ||
@@ -283,0 +343,0 @@ } catch (e) { |
@@ -79,3 +79,3 @@ var expect = require('chai').expect; | ||
it('should return a link to md5 content', function(done){ | ||
it('should return a link to md5 URI', function(done){ | ||
let mongoDBDownload = new MongoDBDownload({}); | ||
@@ -87,2 +87,9 @@ mongoDBDownload.getDownloadURIMD5().then((location) => { | ||
}); | ||
it('should return md5 cache file', function(done){ | ||
let mongoDBDownload = new MongoDBDownload({}); | ||
mongoDBDownload.getMD5HashFileLocation().then((md5File) => { | ||
expect(md5File).to.be.an("string"); | ||
done(); | ||
}); | ||
}); | ||
it('should return a link to md5 content', function(done){ | ||
@@ -95,2 +102,16 @@ let mongoDBDownload = new MongoDBDownload({}); | ||
}); | ||
it('should return md5 hash online', function(done){ | ||
let mongoDBDownload = new MongoDBDownload({}); | ||
mongoDBDownload.getMD5HashOnline().then((md5) => { | ||
expect(md5).to.be.an("string"); | ||
done(); | ||
}); | ||
}); | ||
it('should return md5 cached hash', function(done){ | ||
let mongoDBDownload = new MongoDBDownload({}); | ||
mongoDBDownload.getMD5HashOffline().then((md5) => { | ||
expect(md5).to.be.an("string"); | ||
done(); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
73006
1369