项目作者: rolandjitsu

项目描述 :
A simple fn to save a file to disk.
高级语言: TypeScript
项目地址: git://github.com/rolandjitsu/save-file.git
创建时间: 2018-09-05T09:03:04Z
项目社区:https://github.com/rolandjitsu/save-file

开源协议:

下载


File Saver

A simple fn to save a file to disk.

npm
GitHub Workflow Status
Coveralls github branch

Table of Contents

Installation


You can install this package from NPM:

  1. npm add save-as-file

Or with Yarn:

  1. yarn add save-as-file

CDN

For CDN, you can use unpkg:

https://unpkg.com/save-as-file/dist/bundles/save-as-file.umd.min.js

The global namespace for save-as-file is saveAsFile:

  1. const json = JSON.stringify({ping: true});
  2. const file = new File([json], {type: 'application/json'});
  3. saveAsFile(file, 'test.json');

Usage


ES6

Save a File to disk:

  1. import saveFile from 'save-as-file';
  2. const json = JSON.stringify({ping: true});
  3. const file = new File([json], {type: 'application/json'});
  4. saveFile(file, 'test.json');

NOTE: We create a temporary data uri for File/Blob objects which we revoke after 1 minute.
If you need to download a large file which may take longer than 1 minute to download,
use the 3rd argument to increase this timeout:

  1. import saveFile from 'save-as-file';
  2. const json = JSON.stringify({ping: true});
  3. const file = new File([json], {type: 'application/json'});
  4. saveFile(file, 'test.json', 1000 * 60 * 10 /* 10 mins */);

CommonJS

Save a File to disk:

  1. const saveFile = require('save-as-file');
  2. const json = JSON.stringify({ping: true});
  3. const file = new File([json], {type: 'application/json'});
  4. saveFile(file, 'test.json');

Browser Support


You can expect this lib to run wherever the href download attribute is supported.

Contribute


If you wish to contribute, please use the following guidelines: