You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
807 B
37 lines
807 B
'use strict'
|
|
|
|
var http = require('http');
|
|
var fs = require('fs');
|
|
|
|
module.exports = {
|
|
/**
|
|
*
|
|
*/
|
|
mkdir: function(path) {
|
|
try {
|
|
fs.mkdirSync(path);
|
|
} catch(e) {
|
|
if (e.code !== 'EEXIST'){
|
|
console.log(e);
|
|
}
|
|
}
|
|
},
|
|
|
|
/**
|
|
*
|
|
*/
|
|
download: function(url, filename) {
|
|
return new Promise(function(resolve, reject) {
|
|
var file = fs.createWriteStream(filename);
|
|
|
|
http.get(url, function(response) {
|
|
var pipe = response.pipe(file);
|
|
|
|
pipe.on('finish', function() {
|
|
console.log('Download ' + filename + ' (' + pipe.bytesWritten + ' bytes)');
|
|
resolve();
|
|
});
|
|
});
|
|
});
|
|
}
|
|
};
|
|
|