read-glob-promise

2.0.0 • Public • Published

read-glob-promise

Build Status Build status Coverage Status Dependency Status devDependency Status

Promise version of read-glob:

Search files with glob pattern and read them asynchronously

var readGlob = require('read-glob-promise');
 
readGlob('*.txt')
.then(function(bufs) {
  bufs; //=> [<Buffer ... >, <Buffer ... >, ...]
})
.catch(function(err) {
  console.log(err.message);
});

Installation

NPM version

Use npm.

npm install read-glob-promise

API

var readGlob = require('read-glob-promise');

readGlob(pattern [, options])

pattern: String (glob pattern)
options: Object or String
Return: Object (Promise)

When it finish reading files, it will be fulfilled with an Array of file contents as its first argument.

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

var readGlob = require('read-glob-promise');
 
// foo.txt: lorem
// bar.txt: ipsum
// baz.txt: dolor
 
readGlob('{foo,ba*}.txt', 'utf8')
.then(function(contents) {
  contents; //=> ['lorem', 'ipsum', 'dolor']
});
 
readGlob('{foo,bar.baz}.txt', {nobrace: true})
.then(function(contents) {
  contents; //=> []
});

options

The option object will be directly passed to glob and fs.readFile, or the encoding string sets the encoding of fs.readFile.

Unlike the original API, glob's nodir option is true by default.

License

Copyright (c) 2014 Shinnosuke Watanabe

Licensed under the MIT License.

Package Sidebar

Install

npm i read-glob-promise

Weekly Downloads

1

Version

2.0.0

License

none

Last publish

Collaborators

  • shinnn