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.

NodeJsInputFileSystem.js 845B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const fs = require("graceful-fs");
  7. class NodeJsInputFileSystem {
  8. readdir(path, callback) {
  9. fs.readdir(path, (err, files) => {
  10. callback(err, files && files.map(file => {
  11. return file.normalize ? file.normalize("NFC") : file;
  12. }));
  13. });
  14. }
  15. readdirSync(path) {
  16. const files = fs.readdirSync(path);
  17. return files && files.map(file => {
  18. return file.normalize ? file.normalize("NFC") : file;
  19. });
  20. }
  21. }
  22. const fsMethods = [
  23. "stat",
  24. "statSync",
  25. "readFile",
  26. "readFileSync",
  27. "readlink",
  28. "readlinkSync"
  29. ];
  30. for(const key of fsMethods) {
  31. Object.defineProperty(NodeJsInputFileSystem.prototype, key, {
  32. configurable: true,
  33. writable: true,
  34. value: fs[key].bind(fs)
  35. });
  36. }
  37. module.exports = NodeJsInputFileSystem;