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.

85 lines
2.5 KiB

4 years ago
  1. 'use strict';
  2. const readdirSync = require('./sync');
  3. const readdirAsync = require('./async');
  4. const readdirStream = require('./stream');
  5. module.exports = exports = readdirAsyncPath;
  6. exports.readdir = exports.readdirAsync = exports.async = readdirAsyncPath;
  7. exports.readdirAsyncStat = exports.async.stat = readdirAsyncStat;
  8. exports.readdirStream = exports.stream = readdirStreamPath;
  9. exports.readdirStreamStat = exports.stream.stat = readdirStreamStat;
  10. exports.readdirSync = exports.sync = readdirSyncPath;
  11. exports.readdirSyncStat = exports.sync.stat = readdirSyncStat;
  12. /**
  13. * Synchronous readdir that returns an array of string paths.
  14. *
  15. * @param {string} dir
  16. * @param {object} [options]
  17. * @returns {string[]}
  18. */
  19. function readdirSyncPath (dir, options) {
  20. return readdirSync(dir, options, {});
  21. }
  22. /**
  23. * Synchronous readdir that returns results as an array of {@link fs.Stats} objects
  24. *
  25. * @param {string} dir
  26. * @param {object} [options]
  27. * @returns {fs.Stats[]}
  28. */
  29. function readdirSyncStat (dir, options) {
  30. return readdirSync(dir, options, { stats: true });
  31. }
  32. /**
  33. * Aynchronous readdir (accepts an error-first callback or returns a {@link Promise}).
  34. * Results are an array of path strings.
  35. *
  36. * @param {string} dir
  37. * @param {object} [options]
  38. * @param {function} [callback]
  39. * @returns {Promise<string[]>}
  40. */
  41. function readdirAsyncPath (dir, options, callback) {
  42. return readdirAsync(dir, options, callback, {});
  43. }
  44. /**
  45. * Aynchronous readdir (accepts an error-first callback or returns a {@link Promise}).
  46. * Results are an array of {@link fs.Stats} objects.
  47. *
  48. * @param {string} dir
  49. * @param {object} [options]
  50. * @param {function} [callback]
  51. * @returns {Promise<fs.Stats[]>}
  52. */
  53. function readdirAsyncStat (dir, options, callback) {
  54. return readdirAsync(dir, options, callback, { stats: true });
  55. }
  56. /**
  57. * Aynchronous readdir that returns a {@link stream.Readable} (which is also an {@link EventEmitter}).
  58. * All stream data events ("data", "file", "directory", "symlink") are passed a path string.
  59. *
  60. * @param {string} dir
  61. * @param {object} [options]
  62. * @returns {stream.Readable}
  63. */
  64. function readdirStreamPath (dir, options) {
  65. return readdirStream(dir, options, {});
  66. }
  67. /**
  68. * Aynchronous readdir that returns a {@link stream.Readable} (which is also an {@link EventEmitter})
  69. * All stream data events ("data", "file", "directory", "symlink") are passed an {@link fs.Stats} object.
  70. *
  71. * @param {string} dir
  72. * @param {object} [options]
  73. * @returns {stream.Readable}
  74. */
  75. function readdirStreamStat (dir, options) {
  76. return readdirStream(dir, options, { stats: true });
  77. }