diff options
Diffstat (limited to 'downloaders.js')
-rw-r--r-- | downloaders.js | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/downloaders.js b/downloaders.js index b7582a9..f0833e7 100644 --- a/downloaders.js +++ b/downloaders.js @@ -4,7 +4,6 @@ const { spawn } = require('child_process') const { Base64 } = require('js-base64') const mkdirp = promisify(require('mkdirp')) const fs = require('fs') -const fse = require('fs-extra') const fetch = require('node-fetch') const tempy = require('tempy') const path = require('path') @@ -15,7 +14,22 @@ const rename = promisify(fs.rename) const stat = promisify(fs.stat) const readdir = promisify(fs.readdir) const symlink = promisify(fs.symlink) -const copyFile = fse.copy + +const copyFile = (source, target) => { + // Stolen from https://stackoverflow.com/a/30405105/4633828 + const rd = fs.createReadStream(source) + const wr = fs.createWriteStream(target) + return new Promise((resolve, reject) => { + rd.on('error', reject) + wr.on('error', reject) + wr.on('finish', resolve) + rd.pipe(wr) + }).catch(function(error) { + rd.destroy() + wr.end() + throw error + }) +} const cachify = (identifier, baseFunction) => { return async arg => { |