downloadjs vs file-saver vs js-file-download
JavaScript File Download Libraries
downloadjsfile-saverjs-file-downloadSimilar Packages:

JavaScript File Download Libraries

JavaScript file download libraries simplify the process of triggering file downloads in web applications. They provide developers with tools to create and manage file downloads directly from the browser, enhancing user experience by allowing seamless data export and file handling. These libraries support various file types and offer different methods for generating and saving files, making them essential for applications that require user-generated content or data export functionalities.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
downloadjs02,331-509 years agoMIT
file-saver022,035-2145 years agoMIT
js-file-download0923-116 years agoMIT

Feature Comparison: downloadjs vs file-saver vs js-file-download

File Type Support

  • downloadjs:

    Download.js supports a wide range of file types, including text, JSON, and binary files. It allows developers to easily specify the file type and name during the download process, making it versatile for different use cases.

  • file-saver:

    FileSaver.js is designed to handle various file types, including images, text files, and binary data. It provides built-in support for different MIME types, ensuring that files are saved correctly across different browsers.

  • js-file-download:

    js-file-download supports common file types such as text and JSON, and it allows for easy customization of file names and types during the download process, making it suitable for straightforward applications.

Browser Compatibility

  • downloadjs:

    Download.js is built with a focus on modern browsers and has good compatibility with most major browsers. However, it may not support older browsers as effectively, so testing is recommended for legacy systems.

  • file-saver:

    FileSaver.js offers extensive browser compatibility, including support for Internet Explorer and other older browsers. This makes it a reliable choice for applications that need to cater to a wider audience with varying browser versions.

  • js-file-download:

    js-file-download is primarily optimized for modern browsers and may have limited support for older versions. It's best suited for applications targeting users with up-to-date browsers.

Ease of Use

  • downloadjs:

    Download.js features a simple and intuitive API that allows developers to implement file downloads with minimal setup. This makes it an excellent choice for quick projects or prototypes where speed is essential.

  • file-saver:

    FileSaver.js provides a straightforward API but may require more configuration compared to Download.js. It is still user-friendly, especially for developers familiar with handling file downloads in JavaScript.

  • js-file-download:

    js-file-download is designed for simplicity, offering an easy-to-use interface that allows developers to trigger downloads quickly. It is particularly beneficial for those who prioritize ease of integration.

Customization Options

  • downloadjs:

    Download.js allows for some customization regarding file names and types, but it is more focused on providing a quick solution rather than extensive configuration options.

  • file-saver:

    FileSaver.js offers robust customization options, including the ability to specify MIME types and file names, making it suitable for applications that require precise control over the download process.

  • js-file-download:

    js-file-download provides basic customization options, allowing developers to set file names and types easily, but it does not offer as many advanced features as FileSaver.js.

Community and Maintenance

  • downloadjs:

    Download.js has a smaller community compared to the other libraries, which may affect the availability of resources and support. However, it is actively maintained and updated.

  • file-saver:

    FileSaver.js has a larger community and is widely used, which means there are more resources, tutorials, and community support available. It is also actively maintained, ensuring compatibility with new browser versions.

  • js-file-download:

    js-file-download has a smaller user base, which may limit community resources. It is maintained but may not receive updates as frequently as FileSaver.js.

How to Choose: downloadjs vs file-saver vs js-file-download

  • downloadjs:

    Choose Download.js if you need a lightweight solution that supports a variety of file types and offers a simple API for triggering downloads without additional dependencies. It is particularly useful for quick implementations where minimal configuration is desired.

  • file-saver:

    Select FileSaver.js if you require robust support for saving files on the client side with a focus on compatibility across different browsers. It is ideal for applications that need to handle complex file types and provides more control over the download process, including MIME type handling.

  • js-file-download:

    Opt for js-file-download if you want a straightforward and easy-to-use library that focuses on file downloads with a minimal setup. It is particularly useful for projects where simplicity and ease of use are prioritized, allowing for quick integration.

README for downloadjs

download

========

Summary


The download() function is used to trigger a file download from JavaScript.

It specifies the contents and name of a new file placed in the browser's download directory. The input can be a URL, String, Blob, or Typed Array of data, or via a dataURL representing the file's data as base64 or url-encoded string. No matter the input format, download() saves a file using the specified file name and mime information in the same manner as a server using a Content-Disposition HTTP header.

Getting and Using


Via NPM/Bower

npm install downloadjs
bower install downloadjs

require("downloadjs")(data, strFileName, strMimeType);

Simple global download function via <script> include

download(data, strFileName, strMimeType);

Included via AMD

require(['path/to/file'], function(download) {
    download(data, strFileName, strMimeType);
});

Parameters


  • data - The Blob, File, String, or dataURL containing the soon-to-be File's contents.
  • strFileName - The name of the file to be created. Note that older browsers (like FF3.5, Ch5) don't honor the file name you provide, instead they automatically name the downloaded file.
  • strMimeType - The MIME content-type of the file to download. While optional, it helps the browser present friendlier information about the download to the user, encouraging them to accept the download.

Example Usage


Plain Text

text string - live demo

download("hello world", "dlText.txt", "text/plain");

text dataURL - live demo

download("data:text/plain,hello%20world", "dlDataUrlText.txt", "text/plain");

text blob - live demo

download(new Blob(["hello world"]), "dlTextBlob.txt", "text/plain");

text url - live demo

download("/robots.txt");

text UInt8 Array - live demo

var str= "hello world",	arr= new Uint8Array(str.length);
str.split("").forEach(function(a,b){
  arr[b]=a.charCodeAt();
});

download( arr, "textUInt8Array.txt", "text/plain" );

HTML

html string - live demo

download(document.documentElement.outerHTML, "dlHTML.html", "text/html");

html Blob - live demo

download(new Blob(["hello world".bold()]), "dlHtmlBlob.html", "text/html");

ajax callback - live demo

(note that callback mode won't work on vanilla ajax or with binary files)

$.ajax({
		url: "/download.html",
		success: download.bind(true, "text/html", "dlAjaxCallback.html")
});

Binary Files

image from URL - live demo

download("/diff6.png");

Image via ajax for custom filename - live demo

var x=new XMLHttpRequest();
x.open( "GET", "/diff6.png" , true);
x.responseType="blob";
x.onload= function(e){download(e.target.response, "awesomesauce.png", "image/png");};
x.send();

Compatibility


download.js works with a wide range of devices and browsers.

You can expect it to work for the vast majority of your users, with some common-sense limits:

  • Devices without file systems like iPhone, iPad, Wii, et al. have nowhere to save the file to, sorry.
  • Android support starts at 4.2 for the built-in browser, though chrome 36+ and firefox 20+ on android 2.3+ work well.
  • Devices without Blob support won't be able to download Blobs or TypedArrays
  • Legacy devices (no a[download]) support can only download a few hundred kilobytes of data, and can't give the file a custom name.
  • Devices without window.URL support can only download a couple megabytes of data
  • IE versions of 9 and before are NOT supported because the don't support a[download] or dataURL frame locations.

FAQ


  • Can I tell when a download is done/canceled? No.
  • How can I style the temporary download link? Define CSS class styles for .download-js-link.
  • What's up with Safari? I don't know either but pull requests that improve the situation are welcome.
  • Why is my binary file corrupted? Likely: an incorrect MIME or using jQuery ajax, which has no bin support.
  • How big of files work? Depends, try yourself: File Echo Demo... I do a 1GB dl routinely on a thinkpad...

Change Log (v4.1)


  • 2008 :: landed a FF+Chrome compat way of downloading strings to local un-named files, upgraded to use a hidden frame and optional mime
  • 2012 :: added named files via a[download], msSaveBlob() for IE (10+) support, and window.URL support for larger+faster saves than dataURLs
  • 2014 :: added dataURL and Blob Input, bind-toggle arity, and legacy dataURL fallback was improved with force-download mime and base64 support
  • 2015 :: converted to amd/commonJS module with browser-friendly fallback
  • 2015 :: 4.1 added direct URL downloading via a single URL argument.
  • 2016 :: 4.2 added large dataURL support, a more semantic codebase, and hidden temp links
  • 2017 :: added support for empty dataURLs
  • 20XX :: ???? Considering Zip, Tar, and other multi-file outputs, Blob.prototype.download option, and more, stay tuned folks.