Coder Social home page Coder Social logo

read-files-promise's Introduction

read-files-promise

NPM version Build Status Build status Coverage Status Dependency Status devDependency Status

Promise to read multiple files

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.

Installation

Use npm.

npm install 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.

When it fails to read at least one of the files, it will be rejected with an error as its first argument.

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

Licensed under the MIT License.

read-files-promise's People

Contributors

shinnn avatar

Stargazers

Manohar Vanga avatar Brian Winkers avatar

Watchers

 avatar

Forkers

bwinkers

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.