1.0.3 • Published 7 years ago

activerules-read-files-promise v1.0.3

Weekly downloads
10
License
MIT
Repository
github
Last release
7 years ago

activerules-read-files-promise

NPM version Build Status Code Climate Coverage Status Dependency Status devDependency Status

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

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

Installation

Use npm.

npm install activerules-read-files-promise

API

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

readFiles(filenames , options)

filenames: Array of String (file paths)
options: Object or String (same as fs.readFile's second argument)
Return: Object (Promise)

It reads the files specified in its first argument.

When it finish reading all the files, it will be fulfilled with an array of the contents as its first argument. The order of the contents depends on the order of file paths.

It won't reject unless it fails horribly. Finding zero files can be a success.

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) 2017 Brian Winkers

Licensed under the MIT License.

Error on missing files

If you want a version that throws errors on missing files check out the project we forked.