🚀 Big News:Socket Has Acquired Secure Annex.Learn More →
Socket
Book a DemoSign in
Socket

read-multiple-files

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

read-multiple-files

Read multiple files asynchronously

latest
Source
npmnpm
Version
3.0.0
Version published
Maintainers
1
Created
Source

read-multiple-files

npm version Build Status Coverage Status

Read multiple files Observable way

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

npm install read-multiple-files

API

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

readMultipleFiles(paths [, options])

paths: <Array|Set<string|Buffer|URL|integer>> (file paths)
options: Object (fs.readFile options) or string (encoding)
Return: Observable (Kevin Smith's implementation)

When the Observable is subscribed, it starts to read files in parallel, successively send each result to its Observer as an Object: {path: <string|Buffer|URL|integer>, contents: <string:Buffer>}

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.

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.
  }
});
  • read-files-promise — Promise interface version

License

ISC License © 2017 - 2018 Shinnosuke Watanabe

Keywords

fs

FAQs

Package last updated on 18 Dec 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts