aboutsummaryrefslogtreecommitdiff
path: root/node_modules/@mrmlnc/readdir-enhanced/lib/sync/index.js
blob: 60243a1afe02ad1b33a117a7453e26a4595449e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
'use strict';

module.exports = readdirSync;

const DirectoryReader = require('../directory-reader');

let syncFacade = {
  fs: require('./fs'),
  forEach: require('./for-each'),
  sync: true
};

/**
 * Returns the buffered output from a synchronous {@link DirectoryReader}.
 *
 * @param {string} dir
 * @param {object} [options]
 * @param {object} internalOptions
 */
function readdirSync (dir, options, internalOptions) {
  internalOptions.facade = syncFacade;

  let reader = new DirectoryReader(dir, options, internalOptions);
  let stream = reader.stream;

  let results = [];
  let data = stream.read();
  while (data !== null) {
    results.push(data);
    data = stream.read();
  }

  return results;
}