You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
711 B

4 years ago
  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. }