Introducing js-file_downloader--emon: A Powerful JavaScript File Downloader Package
Md Wahiduzzaman Emon
Posted on March 10, 2023
Are you looking for a powerful and reliable file downloader package for your JavaScript project? Look no further than js-file_downloader--emon, the latest package designed to help developers easily download files in their applications.
Developed by Md Wahiduzzaman Emon, js-file_downloader--emon is a lightweight and easy-to-use package that offers a range of features to simplify the file downloading process. With this package, you can easily download files from a server using a URL and even monitor the download progress.
Here's an example of how you can use this package in your code:
jsFileDownloader(url, fileName);
If you want to see the progress of the download, you can pass a function as the third parameter
jsFileDownloader(url, fileName, (progress) => {
console.log(progress);
});
If you want to use it with async/await
With js-file_downloader--emon, you can also use promises and async/await syntax to handle download requests in a more efficient manner.
try {
const response = await jsFileDownloader(url, name, (progress) => {
console.log(progress);
});
console.log(response);
} catch (error) {
console.log(error);
}
If you want to use it with the promise
jsFileDownloader(url, name, (progress) => {
console.log(progress);
})
.then((response) => {
console.log(response);
})
.catch((error) => {
console.log(error);
});
Parameters
url (string): The URL of the file to be downloaded
fileName (string): The name with which the downloaded file will be saved
progress (function): A function that will be called with the download progress
Functionality:
// Tries to download a file from the given URL
// Checks if the url contains “http://” and replaces it with “https://”
// Initializes the necessary variables and arrays
// Reads the response body in chunks
// Calculates the download progress and calls the progress function with the progress value
// Combines the chunks and creates a blob URL
// Creates a link element, assigns the blob URL and file name, and clicks on it to download the file
// Revokes the blob URL
*Returns:
*
// If successful, returns the downloaded file
// If an error occurs, returns the error message.
Additionally, this package is compatible with popular JavaScript frameworks such as React, Vue, Angular, and Solid JS, making it easy to integrate with your existing projects.
To get started with js-file_downloader--emon, simply install it using npm:
npm i js-file_downloader--emon
Overall, js-file_downloader--emon is a powerful and easy-to-use package that offers a range of features to simplify the file-downloading process in JavaScript applications. Whether you're a beginner or an experienced developer, this package is sure to make your life easier. Give it a try today!
Follow me on Github: https://github.com/MdWahiduzzamanEmon
Md Wahediduzzaman Emon
Software Developer
Posted on March 10, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
April 12, 2024
March 10, 2023
October 15, 2022