file-saver vs blob-util vs downloadjs vs js-file-download
JavaScript File Download Libraries
file-saverblob-utildownloadjsjs-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
file-saver7,438,56521,989-2146 years agoMIT
blob-util0508-38 years agoApache-2.0
downloadjs02,329-5010 years agoMIT
js-file-download0919-116 years agoMIT

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

Blob Handling

  • 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.

  • 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.

  • 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.

  • 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

  • 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.

  • 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.

  • 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.

  • 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

  • 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.

  • 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.

  • 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.

  • 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

  • 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.

  • 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.

  • 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.

  • 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

  • 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.

  • 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.

  • downloadjs:

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

  • 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: file-saver vs blob-util vs downloadjs vs js-file-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.

  • 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.

  • 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.

  • 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 file-saver

If you need to save really large files bigger than the blob's size limitation or don't have enough RAM, then have a look at the more advanced StreamSaver.js that can save data directly to the hard drive asynchronously with the power of the new streams API. That will have support for progress, cancelation and knowing when it's done writing

FileSaver.js

FileSaver.js is the solution to saving files on the client-side, and is perfect for web apps that generates files on the client, However if the file is coming from the server we recommend you to first try to use Content-Disposition attachment response header as it has more cross-browser compatiblity.

Looking for canvas.toBlob() for saving canvases? Check out canvas-toBlob.js for a cross-browser implementation.

Supported Browsers

BrowserConstructs asFilenamesMax Blob SizeDependencies
Firefox 20+BlobYes800 MiBNone
Firefox < 20data: URINon/aBlob.js
ChromeBlobYes2GBNone
Chrome for AndroidBlobYesRAM/5None
EdgeBlobYes?None
IE 10+BlobYes600 MiBNone
Opera 15+BlobYes500 MiBNone
Opera < 15data: URINon/aBlob.js
Safari 6.1+*BlobNo?None
Safari < 6data: URINon/aBlob.js
Safari 10.1+  Blob        Yes        n/a          None

Feature detection is possible:

try {
    var isFileSaverSupported = !!new Blob;
} catch (e) {}

IE < 10

It is possible to save text files in IE < 10 without Flash-based polyfills. See ChenWenBrian and koffsyrup's saveTextAs() for more details.

Safari 6.1+

Blobs may be opened instead of saved sometimes—you may have to direct your Safari users to manually press +S to save the file after it is opened. Using the application/octet-stream MIME type to force downloads can cause issues in Safari.

iOS

saveAs must be run within a user interaction event such as onTouchDown or onClick; setTimeout will prevent saveAs from triggering. Due to restrictions in iOS saveAs opens in a new window instead of downloading, if you want this fixed please tell Apple how this WebKit bug is affecting you.

Syntax

Import saveAs() from file-saver

import { saveAs } from 'file-saver';
FileSaver saveAs(Blob/File/Url, optional DOMString filename, optional Object { autoBom })

Pass { autoBom: true } if you want FileSaver.js to automatically provide Unicode text encoding hints (see: byte order mark). Note that this is only done if your blob type has charset=utf-8 set.

Examples

Saving text using require()

var FileSaver = require('file-saver');
var blob = new Blob(["Hello, world!"], {type: "text/plain;charset=utf-8"});
FileSaver.saveAs(blob, "hello world.txt");

Saving text

var blob = new Blob(["Hello, world!"], {type: "text/plain;charset=utf-8"});
FileSaver.saveAs(blob, "hello world.txt");

Saving URLs

FileSaver.saveAs("https://httpbin.org/image", "image.jpg");

Using URLs within the same origin will just use a[download]. Otherwise, it will first check if it supports cors header with a synchronous head request. If it does, it will download the data and save using blob URLs. If not, it will try to download it using a[download].

The standard W3C File API Blob interface is not available in all browsers. Blob.js is a cross-browser Blob implementation that solves this.

Saving a canvas

var canvas = document.getElementById("my-canvas");
canvas.toBlob(function(blob) {
    saveAs(blob, "pretty image.png");
});

Note: The standard HTML5 canvas.toBlob() method is not available in all browsers. canvas-toBlob.js is a cross-browser canvas.toBlob() that polyfills this.

Saving File

You can save a File constructor without specifying a filename. If the file itself already contains a name, there is a hand full of ways to get a file instance (from storage, file input, new constructor, clipboard event). If you still want to change the name, then you can change it in the 2nd argument.

// Note: Ie and Edge don't support the new File constructor,
// so it's better to construct blobs and use saveAs(blob, filename)
var file = new File(["Hello, world!"], "hello world.txt", {type: "text/plain;charset=utf-8"});
FileSaver.saveAs(file);

Tracking image

Installation

# Basic Node.JS installation
npm install file-saver --save
bower install file-saver

Additionally, TypeScript definitions can be installed via:

# Additional typescript definitions
npm install @types/file-saver --save-dev