downloadjs vs blob-util vs file-saver vs js-file-download
JavaScript File Download Libraries
downloadjsblob-utilfile-saverjs-file-downloadSimilar Packages:

JavaScript File Download Libraries

These libraries facilitate file downloads in web applications by providing various utilities to handle Blob objects, create downloadable links, and manage file saving processes. They simplify the process of generating and downloading files directly from the browser, enhancing user experience by allowing seamless file handling without server-side intervention.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
downloadjs463,0722,329-509 years agoMIT
blob-util0512-38 years agoApache-2.0
file-saver022,018-2145 years agoMIT
js-file-download0921-116 years agoMIT

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

Blob Handling

  • downloadjs:

    downloadjs does not focus on Blob manipulation but allows you to download Blob objects directly with minimal setup. It is straightforward and efficient for triggering downloads without additional Blob processing.

  • blob-util:

    blob-util provides a variety of functions for creating and manipulating Blob objects, including converting data URIs and base64 strings into Blobs. This makes it ideal for applications that need to work extensively with binary data before downloading.

  • file-saver:

    file-saver excels in handling Blob objects and provides a consistent interface for saving files across different browsers. It abstracts away the complexities of Blob creation and download initiation, ensuring compatibility and ease of use.

  • js-file-download:

    js-file-download allows you to download Blob objects easily but does not provide extensive Blob manipulation features. It is best used when you already have a Blob ready for download.

Browser Compatibility

  • downloadjs:

    downloadjs is lightweight and aims for maximum compatibility with modern browsers. It is particularly effective in environments where you want to ensure downloads work seamlessly without additional polyfills.

  • blob-util:

    blob-util is designed to work across all modern browsers, ensuring that Blob manipulations are consistent regardless of the user's environment. However, it may not support older browsers that lack Blob support.

  • file-saver:

    file-saver is known for its strong browser compatibility, including support for Internet Explorer. It handles various edge cases to ensure that file downloads work reliably across different platforms.

  • js-file-download:

    js-file-download offers good compatibility with modern browsers but may not support older versions. It is best suited for applications targeting contemporary web environments.

Ease of Use

  • downloadjs:

    downloadjs is extremely easy to use, with a simple API that allows developers to initiate downloads with just a few lines of code. This makes it ideal for quick implementations.

  • blob-util:

    blob-util has a slightly steeper learning curve due to its comprehensive feature set for Blob manipulation. Developers may need to familiarize themselves with its API to fully leverage its capabilities.

  • file-saver:

    file-saver provides a user-friendly API that abstracts many complexities involved in file saving. It is designed to be straightforward, making it accessible for developers of all skill levels.

  • js-file-download:

    js-file-download is also user-friendly, allowing developers to trigger downloads with minimal configuration. Its simplicity makes it a popular choice for straightforward file download needs.

File Type Support

  • downloadjs:

    downloadjs supports downloading files of any type, as long as you provide the correct Blob or URL. It is flexible and can be used for images, text files, and more.

  • blob-util:

    blob-util supports various data formats through its Blob manipulation functions, making it versatile for applications that handle different types of binary data.

  • file-saver:

    file-saver supports a wide range of file types and is particularly useful for applications that need to save documents, images, and other binary files consistently across browsers.

  • js-file-download:

    js-file-download is designed to handle various file types but is particularly focused on providing a user-friendly experience for dynamically generated files.

Customization

  • downloadjs:

    downloadjs is minimalistic and does not provide extensive customization options, making it suitable for straightforward download scenarios without the need for additional features.

  • blob-util:

    blob-util offers limited customization options as it focuses primarily on Blob manipulation rather than download initiation. It is best for developers who need detailed control over Blob creation.

  • file-saver:

    file-saver allows for some customization, such as specifying file names and types during the download process, enhancing user experience by providing meaningful file names.

  • js-file-download:

    js-file-download offers customization primarily in file naming, allowing developers to specify how files should be named upon download, which is useful for user clarity.

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

  • downloadjs:

    Select downloadjs for a lightweight solution focused solely on downloading files. It is ideal for quick implementations where you want minimal overhead and straightforward functionality for triggering downloads from Blob or URL sources.

  • blob-util:

    Choose blob-util if you need a comprehensive utility for handling Blob objects, including conversion from base64 and data URLs. It is particularly useful when you require advanced Blob manipulations before initiating a download.

  • file-saver:

    Opt for file-saver when you need a robust solution for saving files on the client side. It supports various file types and provides a consistent API across different browsers, making it a reliable choice for applications that require extensive file-saving capabilities.

  • js-file-download:

    Use js-file-download if you want a simple and effective way to trigger downloads with customizable file names. It is particularly useful for applications that generate files dynamically and need to ensure that users can save them with specific names.

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.