# read-files-promise

> Promise to read multiple files

Latest version **1.1.1** (published 2015-07-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install read-files-promise
pnpm add read-files-promise
yarn add read-files-promise
bun add read-files-promise
```

## 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 | 1.1.1 |
| Published | 2015-07-03 |
| First published | 2014-08-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Shinnosuke Watanabe |
| Maintainers | shinnn |
| Keywords | fs, read, file, files, multiple, promise, promises, then, thenable |

## Links

- npm: https://www.npmjs.com/package/read-files-promise
- Repository: https://github.com/shinnn/read-files-promise
- Homepage: https://github.com/shinnn/read-files-promise#readme
- Issues: https://github.com/shinnn/read-files-promise/issues
- npm.io page: https://npm.io/package/read-files-promise

## Dependencies (2)

- [wrap-promise](https://npm.io/package/wrap-promise.md) ^1.0.1
- [read-multiple-files](https://npm.io/package/read-multiple-files.md) ^1.1.1

## 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

- 1.1.1 (latest) — 2015-07-03
- 1.1.0 — 2014-12-13
- 1.0.1 — 2014-09-08
- 1.0.0 — 2014-08-15

## README

# read-files-promise

[![NPM version](https://img.shields.io/npm/v/read-files-promise.svg)](https://www.npmjs.com/package/read-files-promise)
[![Build Status](https://travis-ci.org/shinnn/read-files-promise.svg?branch=master)](https://travis-ci.org/shinnn/read-files-promise)
[![Build status](https://ci.appveyor.com/api/projects/status/2ejpbpkek67wdosf?svg=true)](https://ci.appveyor.com/project/ShinnosukeWatanabe/read-files-promise)
[![Coverage Status](https://img.shields.io/coveralls/shinnn/read-files-promise.svg)](https://coveralls.io/r/shinnn/read-files-promise)
[![Dependency Status](https://img.shields.io/david/shinnn/read-files-promise.svg?label=deps)](https://david-dm.org/shinnn/read-files-promise)
[![devDependency Status](https://img.shields.io/david/dev/shinnn/read-files-promise.svg?label=devDeps)](https://david-dm.org/shinnn/read-files-promise#info=devDependencies)

[Promise][promise] to read multiple files

```javascript
const readFiles = require('read-files-promise');

readFiles([
  'path/to/file0', // 'apple'
  'path/to/file1', // 'orange'
], {encoding: 'utf8'})
.then(buffers => {
  buffers; //=> ['apple', 'orange']
});
```

If you want to read a single file in the way of promise, use [fs-readfile-promise](https://github.com/shinnn/fs-readfile-promise).

## Installation

[Use npm.](https://docs.npmjs.com/cli/install)

```
npm install read-files-promise
```

## API

```javascript
const readFiles = require('read-files-promise');
```

### readFiles(*filenames* [, *options*])

*filenames*: `Array` of `String` (file paths)  
*options*: `Object` or `String` (same as [fs.readFile](https://nodejs.org/api/fs.html#fs_fs_readfile_filename_options_callback)'s second argument)  
Return: `Object` ([Promise][promise])

It reads the files specified in its first argument.

When it finish reading all the files, it will be [*fulfilled*](https://promisesaplus.com/#point-26) with an array of the contents as its first argument. The order of the contents depends on the order of file paths.

When it fails to read at least one of the files, it will be [*rejected*](https://promisesaplus.com/#point-30) with an error as its first argument.

```javascript
const readFiles = require('read-files-promise');

readFiles([
  'path/to/file0' // 'a'
  'path/to/file1' // 'b'
  'path/to/file2' // 'c'
]).then(onFulfilled, onRejected);

function onFulfilled(buffers) {
  buffers; //=> [<Buffer 61>, <Buffer 62>, <Buffer 63>]
};

function onRejected(err) {
  console.log('Cannot read the file.');
};
```

## License

Copyright (c) 2014 - 2015 [Shinnosuke Watanabe](https://github.com/shinnn)

Licensed under [the MIT License](./LICENSE).

[promise]: https://promisesaplus.com/

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