file-saver
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
File-saver is a solution dedicated to saving files on the client-side, thus making it an ideal tool for web apps generating files on the client. It is an HTML5 saveAs() FileSaver implementation. If the file originates from the server, using the Content-Disposition attachment response header is suggested as it ensures better cross-browser compatibility. FileSaver.js also caters to large files exceeding the blob's size limitation or when the RAM is insufficient, by leveraging the StreamSaver.js which directly saves data to the hard drive asynchronously, using the new streams API and supports progress, cancellation, and tracking when the writing is finished.
To use the file-saver npm package, first, install it via a package manager such as npm or bower. The installation commands are as follows:
npm install file-saver --save
bower install file-saver
For TypeScript definitions, install them using:
npm install @types/file-saver --save-dev
To use it in your JavaScript code, import saveAs
from file-saver:
import { saveAs } from 'file-saver';
For example, if you need to save a text file, you would use the following:
var blob = new Blob(["Hello, world!"], {type: "text/plain;charset=utf-8"});
FileSaver.saveAs(blob, "hello world.txt");
It also supports saving URLs and canvases, and you can save a File
constructor without specifying a filename.
The documentation for file-saver, including browser support and example code, can be found in the readme on the GitHub repository, located at https://github.com/eligrey/FileSaver.js. Here, you will find information on how to use file-saver, how to detect its support in browser, and correct usage with various file types and contexts.