mirror of
https://github.com/jakejarvis/careful-downloader.git
synced 2025-04-26 13:28:27 -04:00
don't delete the temp dir if set manually and dir exists (fixes #3)
This commit is contained in:
parent
933899d6de
commit
8567cfc76a
12
index.js
12
index.js
@ -9,6 +9,14 @@ import decompress from "decompress";
|
|||||||
import urlParse from "url-parse";
|
import urlParse from "url-parse";
|
||||||
|
|
||||||
export default async function downloader(downloadUrl, checksumUrl, options) {
|
export default async function downloader(downloadUrl, checksumUrl, options) {
|
||||||
|
options = options || {};
|
||||||
|
|
||||||
|
// don't delete the temp dir if set manually and dir exists
|
||||||
|
let deleteTempDir = true;
|
||||||
|
if (options.tempDir && fs.pathExistsSync(options.tempDir)) {
|
||||||
|
deleteTempDir = false;
|
||||||
|
}
|
||||||
|
|
||||||
// normalize options and set defaults
|
// normalize options and set defaults
|
||||||
options = {
|
options = {
|
||||||
filename: options.filename || urlParse(downloadUrl).pathname.split("/").pop(),
|
filename: options.filename || urlParse(downloadUrl).pathname.split("/").pop(),
|
||||||
@ -48,10 +56,12 @@ export default async function downloader(downloadUrl, checksumUrl, options) {
|
|||||||
return path.join(options.destDir, options.filename);
|
return path.join(options.destDir, options.filename);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
// delete temporary directory
|
// delete temporary directory (except for edge cases above)
|
||||||
|
if (deleteTempDir) {
|
||||||
await fs.remove(options.tempDir);
|
await fs.remove(options.tempDir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Download any file to any destination. Returns a promise.
|
// Download any file to any destination. Returns a promise.
|
||||||
async function downloadFile(url, dest) {
|
async function downloadFile(url, dest) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user