cpd_client
Version:
/!\ Pour utiliser ce module il faut aussi utiliser le [CPD_SERVER](https://www.npmjs.com/package/cpd_server)
21 lines (20 loc) • 706 B
JavaScript
const Downloader = require('nodejs-file-downloader');
const t = module.exports
const events = require('events');
const eventEmitter = new events.EventEmitter();
t.events = eventEmitter
t.download = async function download(url, dir) {
const downloader = new Downloader({
url: url,
directory: dir,
onProgress: function(percentage) {
t.events.emit("download", { type: "progress", state: `${percentage}%`, msg: `[CPD] Downloading ${url}`, dir: dir })
}
})
try {
await downloader.download();
} catch (error) {
t.events.emit("download", { type: "error", error: `[CPD] Downloading Error : ${error}` })
console.log(error)
}
}