JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 9918
  • Score
    100M100P100Q173170F

Read multiple files asynchronously

Package Exports

  • read-multiple-files

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (read-multiple-files) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

read-multiple-files

Build Status Build status Coverage Status Dependency Status devDependency Status

A Node module to read multiple files asynchronously

var readMultipleFiles = require('read-multiple-files');

readMultipleFiles(['one.txt', 'another.txt'], function(err, bufs) {
  if (err) {
    throw err;
  }

  bufs; //=> [<Buffer ... >, <Buffer ... >]
});

Installation

NPM version

Use npm.

npm install read-multiple-files

API

var readMultipleFiles = require('read-multiple-files');

readMultipleFiles(paths [, options], callback)

paths: Array of String
options: Object (fs.readFile options)
callback: Function

It is similar to fs.readFile. The only deference is that it takes an array of multiple file paths as its first argument.

callback(error, contents)

error: Error if it fails to read the file, otherwise null
contents: Array of Buffer or String (according to encoding option)

The second argument will be an array of file contents. Its order follows the order of file paths.

var readMultipleFiles = require('read-multiple-files');

// foo.txt: Hello
// bar.txt: World

readMultipleFiles(['foo.txt', 'bar.txt'], 'utf8', function(err, contents) {
  if (err) {
    throw err;
  }

  contents; //=> ['Hello', 'World']
});

If it fails to read at least one file, it passes an error to the first argument and doesn't pass any values to the second argument.

var readMultipleFiles = require('read-multiple-files');

// foo.txt: exists
// bar.txt: doesn't exist
// baz.txt: exists

readMultipleFiles(['foo.txt', 'bar.txt', 'baz.txt'], function(err, contents) {
  err.code; //=> 'ENOENT'
  contents; //=> undefined
  arguments.length; //=> 1
});

License

Copyright (c) 2014 Shinnosuke Watanabe

Licensed under the MIT License.