# read-multiple-files

> Read multiple files asynchronously

Latest version **3.0.0** (published 2018-12-18) · ISC license · 0 weekly downloads

## Install

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

## 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 | 3.0.0 |
| Published | 2018-12-18 |
| First published | 2014-11-19 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 5.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 12 |
| Author | Shinnosuke Watanabe |
| Maintainers | shinnn |
| Keywords | fs, read, reader, multiple, parallel, parallelly, file, files, read, observable, contents, buffer, async, asynchronous, asynchronously |

## Links

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

## Dependencies (2)

- [zen-observable](https://npm.io/package/zen-observable.md) ^0.8.11
- [inspect-with-kind](https://npm.io/package/inspect-with-kind.md) ^1.0.5

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

- 3.0.0 (latest) — 2018-12-18
- 3.0.0-0 (next) — 2018-12-16
- 2.0.0 — 2017-12-18
- 2.0.0-4 — 2017-10-06
- 2.0.0-3 — 2017-09-21
- 2.0.0-2 — 2017-09-19
- 2.0.0-1 — 2017-09-11
- 2.0.0-0 — 2017-09-06
- 1.1.1 — 2015-07-03
- 1.1.0 — 2014-12-16
- 1.0.1 — 2014-12-13
- 1.0.0 — 2014-11-19

## README

# read-multiple-files

[![npm version](https://img.shields.io/npm/v/read-multiple-files.svg)](https://www.npmjs.com/package/read-multiple-files)
[![Build Status](https://travis-ci.com/shinnn/read-multiple-files.svg?branch=master)](https://travis-ci.com/shinnn/read-multiple-files)
[![Coverage Status](https://img.shields.io/coveralls/shinnn/read-multiple-files.svg)](https://coveralls.io/github/shinnn/read-multiple-files)

Read multiple files [Observable](https://github.com/tc39/proposal-observable) way

```javascript
const readMultipleFiles = require('read-multiple-files');

readMultipleFiles(new Set([
  'one.txt',    // 'a'
  'another.txt' // 'b'
])).subscribe({
  next(result) {
    if (result.path === 'one.txt') {
      result.contents; // Buffer.from('a')
    } else if (result.path === 'another.txt') {
      result.contents; // Buffer.from('b')
    }
  },
  complete() {
    console.log('Successfully read all files.');
  }
});
```

## Installation

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

```
npm install read-multiple-files
```

## API

```javascript
const readMultipleFiles = require('read-multiple-files');
```

### readMultipleFiles(*paths* [, *options*])

*paths*: `<Array|Set<string|Buffer|URL|integer>>` (file paths)  
*options*: `Object` ([`fs.readFile`](https://nodejs.org/api/fs.html#fs_fs_readfile_path_options_callback) options) or `string` (encoding)  
Return: [`Observable`](https://tc39.github.io/proposal-observable/#observable) ([Kevin Smith's implementation](https://github.com/zenparsing/zen-observable))

When the `Observable` is [subscribe](https://tc39.github.io/proposal-observable/#observable-prototype-subscribe)d, it starts to read files in parallel, successively send each result to its [`Observer`](https://github.com/tc39/proposal-observable#observer) as an `Object`: `{path: <string|Buffer|URL|integer>, contents: <string:Buffer>}`

```javascript
readMultipleFiles([
  'foo.txt', // 'Hello'
  'bar.txt'  // 'World'
], 'utf8').subscribe({
  next({path, contents}) {
    if (path === 'one.txt') {
      contents; // 'Hello'
    } else if (path === 'another.txt') {
      contents; // 'World'
    }
  }
});
```

The `Observer` receives an error when it fails to read at least one of the files.

```javascript
const readMultipleFiles = require('read-multiple-files');

readMultipleFiles([
  'foo.txt', // exists
  'bar.txt'  // doesn't exist
]).subscribe({
  error(err) {
    err.code; //=> ENOENT
  },
  complete() {
    // `complete` callback will never be called.
  }
});
```

## Related project

* [read-files-promise](https://github.com/shinnn/read-files-promise) — `Promise` interface version

## License

[ISC License](./LICENSE) © 2017 - 2018 Shinnosuke Watanabe

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