index.js 711 B

12345678910111213141516171819202122232425262728293031323334
  1. 'use strict';
  2. module.exports = readdirSync;
  3. const DirectoryReader = require('../directory-reader');
  4. let syncFacade = {
  5. fs: require('./fs'),
  6. forEach: require('./for-each'),
  7. sync: true
  8. };
  9. /**
  10. * Returns the buffered output from a synchronous {@link DirectoryReader}.
  11. *
  12. * @param {string} dir
  13. * @param {object} [options]
  14. * @param {object} internalOptions
  15. */
  16. function readdirSync (dir, options, internalOptions) {
  17. internalOptions.facade = syncFacade;
  18. let reader = new DirectoryReader(dir, options, internalOptions);
  19. let stream = reader.stream;
  20. let results = [];
  21. let data = stream.read();
  22. while (data !== null) {
  23. results.push(data);
  24. data = stream.read();
  25. }
  26. return results;
  27. }