# save-file

> Save file dialog in browser, write file to disk in node

Latest version **2.3.1** (published 2019-02-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install save-file
pnpm add save-file
yarn add save-file
bun add save-file
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.3.1 |
| Published | 2019-02-22 |
| First published | 2015-05-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 6.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Dima Yv |
| Maintainers | dy |
| Keywords | file, download, blob, arraybuffer, convert, array, save |

## Links

- npm: https://www.npmjs.com/package/save-file
- Repository: https://github.com/dy/save-file
- Issues: https://github.com/dy/save-file/issues
- npm.io page: https://npm.io/package/save-file

## Dependencies (6)

- [write](https://npm.io/package/write.md) ^1.0.0
- [is-blob](https://npm.io/package/is-blob.md) ^1.0.0
- [is-buffer](https://npm.io/package/is-buffer.md) ^2.0.0
- [file-saver](https://npm.io/package/file-saver.md) ^2.0.0-rc.4
- [simple-mime](https://npm.io/package/simple-mime.md) ^0.1.0
- [to-array-buffer](https://npm.io/package/to-array-buffer.md) ^3.2.0

## Alternatives

- [unionfs](https://npm.io/package/unionfs.md) — 2.2M weekly downloads
- [path-starts-with](https://npm.io/package/path-starts-with.md) — 35.9K weekly downloads
- [redzip](https://npm.io/package/redzip.md) — 1.2K weekly downloads
- [vscode-anymatch](https://npm.io/package/vscode-anymatch.md) — 848 weekly downloads
- [@ledgerhq/coin-filecoin](https://npm.io/package/@ledgerhq/coin-filecoin.md) — 793 weekly downloads

## Recent versions

- 2.3.1 (latest) — 2019-02-22
- 2.3.0 — 2019-02-18
- 2.2.1 — 2019-01-06
- 2.2.0 — 2018-12-15
- 2.1.1 — 2018-11-14
- 2.1.0 — 2018-11-14
- 2.0.0 — 2018-11-14
- 1.3.0 — 2018-11-14
- 1.2.4 — 2018-11-13
- 1.2.3 — 2018-11-12
- 1.2.2 — 2018-11-12
- 1.2.1 — 2018-09-12
- 1.2.0 — 2017-06-17
- 1.1.3 — 2017-04-19
- 1.1.2 — 2017-04-18
- … 1 more at https://npm.io/package/save-file/versions

## README

# save-file [![unstable](https://img.shields.io/badge/stability-unstable-green.svg)](http://github.com/badges/stability-badges) [![Build Status](https://img.shields.io/travis/dy/save-file.svg)](https://travis-ci.org/dy/save-file) [![Greenkeeper badge](https://badges.greenkeeper.io/dy/save-file.svg)](https://greenkeeper.io/)

Save file in node/browser. In browser it prompts save file dialog, in node it creates a file.

* Provides common interface for both node/browser.
* Fixes dialog race in browser − when multiple save-files are called at the same time.
* Handles any types of input data − _Buffer_, _ArrayBuffer_, _ArrayBufferView_, _File_, _Blob_, data-uri string, _ImageData_ etc.

## Usage

[![npm install save-file](https://nodei.co/npm/save-file.png?mini=true)](https://npmjs.org/package/save-file/)

```js
// const save = require('save-file')
import { save } from 'save-file'

await save(data, 'example.mp3')

const saveSync = require('save-file/sync')
saveSync(otherData, 'example2.mp3')
```

## API

### `await save(data|filename, filename|data)`

Save `data` source to the `filename` destination, return actual saved _ArrayBuffer_. `saveSync` performs synchronous call.

`data` type can be:
* _Buffer_, _ArrayBuffer_
* _File_, _Blob_
* dataURI, base64 string
* _TypedArray_, _Array_
* _ImageData_, _AudioBuffer_
* _Object_
* [ndarray](https://github.com/scijs/ndarray)
* etc.

See [to-array-buffer](https://github.com/dy/to-array-buffer) for the full list. The data is expected to be encoded to target format, for that purpose see [image-encode](https://ghub.io/image-encode), [audio-encode](https://ghub.io/audio-encode) etc.

Mime type is detected from the file extension/data type automatically.


## Credits & related

* [file-saver](https://npmjs.org/package/file-saver) − create download file dialog in browser.
* [write](https://npmjs.org/package/write) − write file in node, create directories if none.
* [to-array-buffer](https://github.com/dy/to-array-buffer) — turn anything into ArrayBuffer.
* [simple-mime](https://npmjs.org/package/simple-mime) — tiny mime types detector.

## Copyright

© Dmitry Yv 2018. MIT Licensed.

---
_Source: https://npm.io/package/save-file · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
