file-saver vs downloadjs vs blob-util vs download vs js-file-download
ファイルダウンロードライブラリ
file-saverdownloadjsblob-utildownloadjs-file-download類似パッケージ:

ファイルダウンロードライブラリ

これらのライブラリは、Webアプリケーションでのファイルの生成とダウンロードを簡素化するために設計されています。ユーザーがデータをファイルとして保存できるようにするためのさまざまな機能を提供し、特にブラウザの制約を考慮した実装がなされています。これにより、開発者は複雑な処理を行わずに、ユーザーにファイルを提供することができます。

npmのダウンロードトレンド

3 年

GitHub Starsランキング

統計詳細

パッケージ
ダウンロード数
Stars
サイズ
Issues
公開日時
ライセンス
file-saver5,804,05722,034-2145年前MIT
downloadjs515,5072,330-509年前MIT
blob-util0513-38年前Apache-2.0
download01,305-666年前MIT
js-file-download0923-116年前MIT

機能比較: file-saver vs downloadjs vs blob-util vs download vs js-file-download

ファイル生成

  • file-saver:

    BlobやFileオブジェクトを使用して、ユーザーが生成したデータをファイルとして保存するための強力な機能を提供します。

  • downloadjs:

    データを直接ファイルとしてダウンロードするためのシンプルな方法を提供します。特に、文字列やバイナリデータを簡単にファイルとして保存できます。

  • blob-util:

    Blobオブジェクトを生成するためのユーティリティを提供します。テキストや画像データを簡単にBlobに変換できるため、ファイルの生成が容易です。

  • download:

    URLから直接ファイルをダウンロードする機能を持ちますが、ファイル生成の機能はありません。

  • js-file-download:

    データを生成して、ユーザーにダウンロードさせるためのシンプルなAPIを提供します。特に、動的に生成されたデータをファイルとして保存するのに便利です。

ブラウザサポート

  • file-saver:

    広範なブラウザサポートを持ち、特にIEやEdgeなどの古いブラウザでも動作します。

  • downloadjs:

    主要なブラウザでの互換性があり、特にシンプルなダウンロード機能を必要とする場合に適しています。

  • blob-util:

    ほとんどのモダンブラウザで動作し、特にBlobオブジェクトのサポートが必要な場合に適しています。

  • download:

    一般的なブラウザでのファイルダウンロードをサポートしていますが、特定のブラウザの制約に依存する場合があります。

  • js-file-download:

    主要なブラウザで動作し、特にシンプルなダウンロード機能を必要とする場合に適しています。

APIのシンプルさ

  • file-saver:

    APIは少し複雑ですが、強力な機能を持ち、特にBlobを扱う際に便利です。

  • downloadjs:

    直感的でシンプルなAPIを提供し、すぐに使用できるため、学習コストが低いです。

  • blob-util:

    Blobの生成や変換に特化したシンプルなAPIを提供しており、使いやすさが特徴です。

  • download:

    非常にシンプルなAPIを持ち、URLを指定するだけでファイルをダウンロードできます。

  • js-file-download:

    シンプルで直感的なAPIを提供し、すぐに使用できるため、初心者にも適しています。

データフォーマットのサポート

  • file-saver:

    BlobやFileオブジェクトを扱うため、さまざまなデータフォーマットに対応しています。

  • downloadjs:

    テキストやバイナリデータをサポートし、特にデータをそのままファイルとして保存することができます。

  • blob-util:

    テキスト、画像、バイナリデータなど、さまざまなデータフォーマットをサポートしています。

  • download:

    主にURLからのファイルダウンロードに特化しており、データフォーマットの変換は行いません。

  • js-file-download:

    主にテキストデータを扱いますが、バイナリデータのサポートもあります。

ユースケース

  • file-saver:

    ユーザーが生成したデータをファイルとして保存する必要がある場合に最適です。特に、アプリケーションで生成されたデータを保存する際に便利です。

  • downloadjs:

    クライアントサイドでのデータ生成とダウンロードを簡素化したい場合に選択します。特に、ユーザーが入力したデータをファイルとして保存する場合に便利です。

  • blob-util:

    Blobデータの生成や変換が必要なアプリケーションに最適です。特に、画像やテキストを動的に生成する場合に便利です。

  • download:

    シンプルなファイルダウンロード機能を必要とする場合に適しています。特に、外部リソースからファイルを取得する際に便利です。

  • js-file-download:

    シンプルなAPIでファイルをダウンロードしたい場合に選択します。特に、動的に生成されたデータをファイルとして保存するのに便利です。

選び方: file-saver vs downloadjs vs blob-util vs download vs js-file-download

  • file-saver:

    ユーザーが生成したデータをファイルとして保存する必要がある場合に最適です。特に、BlobやFileオブジェクトを扱う際に便利です。

  • downloadjs:

    クライアントサイドでのファイルダウンロードを簡単に実現したい場合に選択します。特に、データを直接ダウンロードするためのシンプルなインターフェースを提供します。

  • blob-util:

    Blobデータの操作が必要な場合や、特にBlobオブジェクトの生成や変換を行う必要がある場合に適しています。

  • download:

    シンプルなファイルダウンロード機能を必要とする場合に最適です。URLからファイルを取得してダウンロードするシンプルなAPIを提供します。

  • js-file-download:

    シンプルなAPIでファイルをダウンロードしたい場合に選択します。特に、データを動的に生成し、ダウンロードするための便利な方法を提供します。

file-saver のREADME

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