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GAEzC,EAAQ,KAAK,GAAY,SAAS,EAAK,EAAK,GACxC,GAAK,GAAyB,KAAlB,EAAI,WAKZ,EAAK,QAAS,CAAE,WAAY,EAAI,WAAY,IAAK,QALlB,CAE7B,EAAQ,GAAY,KAAK,GAC3B,EAAK,aAAc,CAAE,UAAW,EAAW,WAAY,EAAY,UAAW,EAAI,QAAQ,mBACjG,CAGD,GAED,EAEA,IAAI,EAAO,SAAc,EAAO,GAC/B,QAAwB,IAApB,EAAS,GACZ,MAAM,IAAI,MAAM,kBAMjB,GAAsB,IAFF,EAAS,GAAO,OAGnC,OAAO,EAGR,IAAI,IAAI,EAAE,EAAG,EAAE,EAAS,GAAO,SAAU,EACxC,EAAS,GAAO,GAAG,GAGpB,OAAO,CACR,EAEA,KAAK,GAAK,SAAY,EAAO,GAC5B,QAAwB,IAApB,EAAS,GACZ,MAAM,IAAI,MAAM,kBAGjB,QAAqB,IAAjB,GAAsD,mBAAjB,EACxC,MAAM,IAAI,MAAM,2CAGjB,IAA4B,IAAxB,EAAM,QAAQ,KAAa,CAC9B,IAAI,EAAS,EAAM,MAAM,KACzB,IAAK,IAAI,KAAK,EACb,EAAS,GAAG,KAAK,EAEnB,MACC,EAAS,GAAO,KAAK,GAGtB,OAAO,IACR,EAEA,KAAK,aAAe,SAAsB,GAIzC,YAH0B,IAAtB,EAAS,WACL,EAAS,GAEV,IACR,EAEA,KAAK,cAAgB,WACpB,IAAM,IAAI,KAAW,EACpB,EAAS,GAAW,GAErB,OAAO,IACR,CACD,EAEA,OAAO,QAAU,IAAK","file":"/npm/nodejs-download@1.0.5/download.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/nodejs-download@1.0.5/download.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","var download = function download() {\n\n\tvar fs       = require('fs');\n\tvar url      = require('url');\n\tvar http     = require('http');\n\tvar https    = require('https');\n\tvar request  = require('request');\n\tvar triggers = {\n\t\tdownloaded: [],\n\t\tdata: [],\n\t\terror: []\n\t};\n\n\tthis.downloadFile = function downloadFile(remoteFile, localFile, encoding) {\n\t\tvar totalDownload = 0;\n\t\tvar file          = fs.createWriteStream(localFile);\n\t\t\n\t\tvar downloadProtocol = http;\n\t\tif (remoteFile.substr(0, 5) === 'https') {\n\t\t\tdownloadProtocol = https;\n\t\t}\n\n\t\tdownloadProtocol.get(remoteFile, function (response) {\n\t        if (encoding) {\n\t            response.setEncoding(encoding);\n\t        }\n\n\t\t\tvar totalLength    = parseInt(response.headers['content-length'], 10);\n\t\t\tvar downloaded     = 0;\n\t\t\tvar lastPercentage = 0;\n\n\t\t\ttotalDownload  = totalLength / 1048576; //1048576 - bytes in  1Megabyte\n\n\t\t\tresponse.pipe(file);\n\t\t    response.on('data', function(chunk) {\n\n\t\t        if (response.statusCode !== 200) {\n\t\t        \temit('error', { statusCode: response.statusCode, response: chunk.toString() });\n\t\t        \treturn;\n\t\t        }\n\n\t            downloaded += chunk.length;\n\t\t        file.write(chunk);\n\n\t\t        var percentage = (100.0 * downloaded / totalLength).toFixed(2);\n\n\t\t        if (lastPercentage !== percentage) {\n\t\t        \tvar downlaoded = (downloaded / 1048576).toFixed(2);\n\n\t\t        \temit('data', { percentage: percentage, downlaoded: downlaoded, totalSize: totalDownload });\n\n\t\t\t    \tlastPercentage = percentage;\n\t\t\t    }\n\t\t    });\n\n\t\t    response.on('end', function() {\n\t\t        file.end();\n\n\t\t        if (response.statusCode === 200) {\n\t\t        \temit('downloaded', { localFile: localFile, remoteFile: remoteFile, totalSize: totalDownload });\n\t\t        } else {\n\t\t        \tfs.unlink(localFile);\n\t\t        }\n\t\t    });\n\n\t\t\tresponse.on('error', function(e) {\n\t\t        emit('error', { statusCode: response.statusCode, response: e.message });\n\t\t\t});\n\t\t});\n\t};\n\n\tthis.downloadPicture = function downloadFile(remoteFile, localFile, encoding) {\n\t\tvar file          = fs.createWriteStream(localFile);\n\n\t\trequest.head(remoteFile, function(err, res, body) {\n    \t\tif (!err && res.statusCode == 200) {\n\n\t\t\t\tvar r = request(remoteFile).pipe(file);\n\t\t        emit('downloaded', { localFile: localFile, remoteFile: remoteFile, totalSize: res.headers['content-length'] });\n\t\t\t} else {\n\t\t        emit('error', { statusCode: res.statusCode, res: err });\n\t\t\t}\n\t\t});\n\n\t};\n\n\tvar emit = function emit(event, params) {\n\t\tif (triggers[event] === undefined ) {\n\t\t\tthrow new Error('No valid event');\n\t\t\treturn false;\n\t\t}\n\n\t\tvar totalTriggers = triggers[event].length;\n\n\t\tif (totalTriggers === 0) {\n\t\t\treturn false;\n\t\t}\n\n\t\tfor(var i=0; i<triggers[event].length; ++i) {\n\t\t\ttriggers[event][i](params);\n\t\t}\n\n\t\treturn true;\n\t};\n\n\tthis.on = function on(event, userFunction) {\n\t\tif (triggers[event] === undefined ) {\n\t\t\tthrow new Error('No valid event');\n\t\t}\n\n\t\tif (userFunction === undefined || typeof userFunction !== 'function' ) {\n\t\t\tthrow new Error('Callback function has to be an function');\n\t\t}\n\n\t\tif (event.indexOf(' ') !== -1) {\n\t\t\tvar events = event.split(' ');\n\t\t\tfor (var e in events) {\n\t\t\t\ttriggers[e].push(userFunction);\n\t\t\t}\n\t\t} else {\n\t\t\ttriggers[event].push(userFunction);\n\t\t}\n\n\t\treturn this;\n\t};\n\n\tthis.clearTrigger = function clearTrigger(trigger) {\n\t\tif (triggers[trigger] !== undefined) {\n\t\t\tdelete triggers[trigger];\n\t\t}\n\t\treturn this;\n\t}\n\n\tthis.clearTriggers = function clearTriggers() {\n\t\tfor ( var trigger in triggers) {\n\t\t\ttriggers[trigger] = [];\n\t\t}\n\t\treturn this;\n\t}\n};\n\nmodule.exports = (new download());"]}