DEV Community

Md Wahiduzzaman Emon
Md Wahiduzzaman Emon

Posted on

Introducing js-file_downloader--emon: A Powerful JavaScript File Downloader Package

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);
Enter fullscreen mode Exit fullscreen mode

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);
});
Enter fullscreen mode Exit fullscreen mode

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);
}
Enter fullscreen mode Exit fullscreen mode

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);
  });
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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

Top comments (0)