Skip to content

shinnn/realpaths-callback

Repository files navigation

realpaths-callback

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

Callback-style version of realpaths:

Like fs.realpath, but resolves multiple paths at once

const realpathsCallback = require('realpaths-callback');

// symlink1 <<===>> /path/to/foo.txt
// symlink2 <<===>> /path/to/bar.txt

realpaths(['symlink1', 'symlink2'], (err, paths) => {
  if (err) {
    throw err;
  }

  paths; //=> ['/path/to/foo.txt', '/path/to/bar.txt']
});

Installation

Use npm.

npm install realpaths-callback

API

const realpathsCallback = require('realpaths-callback');

realpathsCallback(paths [, cache], callback)

paths: Array of strings (file paths)
cache: Object (used as fs.realpath cache)
callback: Function (called after the paths are resolved)

It's API is very similar to fs.realpath. The only difference is realpaths-callback takes an array as its first argument and resolves multiple paths at once.

'use strict';

const path = require('path');
const realpaths = require('realpaths-callback');

realpaths(['symlink1', 'symlink2'], {
  cache: {
    [path.resolve('symlink1')]: '/path/to/foo.txt',
    [path.resolve('symlink2')]: '/path/to/bar.txt'
  }
}, (err, paths) => {
  if (err) {
    throw err;
  }
  paths; //=> ['/path/to/foo.txt', '/path/to/bar.txt']
});

If at least one of the paths cannot be resolved, it immediately passes an error to its callback function without considering the rest of paths.

Related project

License

Copyright (c) 2015 - 2016 Shinnosuke Watanabe

Licensed under the MIT License.

About

Callback-style version of realpaths

Resources

License

Stars

Watchers

Forks

Packages

No packages published