@elara-services/downloader
v1.0.6
Published
Downloads media to a certain directory
Downloads
1
Readme
Welcome to the Downloader package
Links:
Docs
Support
Patreon
PayPal
Getting Started
- NOTE: This package will automatically create the directories the file_path has if it doesn't exist!
const { Downloader } = require("@elara-services/downloader");
// Without default directory. ('path' required to be included per-download)
const client = new Downloader();
// With default directory
const client = new Downloader(`${process.cwd()}/downloads`); // Will download all files to the downloads folder.
Set Default Directory/Folder
// SET
// NOTE: This WILL create the directory if it doesn't exist!
client.setDefaultDirectory(`${process.cwd()}/downloads`); // Sets the default directory as `/downloads`
// RESET
client.setDefaultDirectory(null);
Download File:
// Will extract the file name and extension from the link.
const r = await client.file(`LINK_HERE`); // Downloads the file to the default directory.
// With options.
const r = await client.file(`LINK_HERE`, {
name: `boop`, // [OPTIONAL]: Only use a file name not the extension! (extension is automatically set!)
path: `${process.cwd()}/images`, // [OPTIONAL]: OR `${process.cwd()}/images/file_name.png` (an exact path name you want to use)
extractFilename: false, // [OPTIONAL]: If false it won't extract the file name and use the one you provided.
maxRedirects: 2, // [OPTIONAL]: The max redirects to follow before erroring out. (default: 21)
// ...other_https_client_options,
});
// Use 'r'
Download Files:
const r = await client.files([
{ url: `....` },
{ url: `....`, ...other_file_info_above },
]);
// Returns { success: string[], errors: Error[] }