1
mirror of https://github.com/jakejarvis/careful-downloader.git synced 2026-06-17 14:05:28 -04:00

BREAKING: allow hashes provided as a URL to a text file or a string

(closes #1)
This commit is contained in:
2021-10-16 06:10:36 -04:00
parent bcd2e89f7d
commit 4d3134afb8
8 changed files with 336 additions and 183 deletions
+20
View File
@@ -0,0 +1,20 @@
import stream from "stream";
import { promisify } from "util";
import fs from "fs-extra";
import got from "got";
import debug from "./debug.js";
// Download any file to any destination. Returns a promise.
export default async (url, dest) => {
debug(`Downloading '${url}' to '${dest}'`);
// get remote file and write locally
const pipeline = promisify(stream.pipeline);
const download = pipeline(
got.stream(url, { followRedirect: true }), // GitHub releases redirect to unpredictable URLs
fs.createWriteStream(dest),
);
return download;
};