FsPromises.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.FsPromises = void 0;
  4. const util_1 = require("./util");
  5. const constants_1 = require("../constants");
  6. class FsPromises {
  7. constructor(fs, FileHandle) {
  8. this.fs = fs;
  9. this.FileHandle = FileHandle;
  10. this.constants = constants_1.constants;
  11. this.cp = (0, util_1.promisify)(this.fs, 'cp');
  12. this.opendir = (0, util_1.promisify)(this.fs, 'opendir');
  13. this.statfs = (0, util_1.promisify)(this.fs, 'statfs');
  14. this.lutimes = (0, util_1.promisify)(this.fs, 'lutimes');
  15. this.access = (0, util_1.promisify)(this.fs, 'access');
  16. this.chmod = (0, util_1.promisify)(this.fs, 'chmod');
  17. this.chown = (0, util_1.promisify)(this.fs, 'chown');
  18. this.copyFile = (0, util_1.promisify)(this.fs, 'copyFile');
  19. this.lchmod = (0, util_1.promisify)(this.fs, 'lchmod');
  20. this.lchown = (0, util_1.promisify)(this.fs, 'lchown');
  21. this.link = (0, util_1.promisify)(this.fs, 'link');
  22. this.lstat = (0, util_1.promisify)(this.fs, 'lstat');
  23. this.mkdir = (0, util_1.promisify)(this.fs, 'mkdir');
  24. this.mkdtemp = (0, util_1.promisify)(this.fs, 'mkdtemp');
  25. this.readdir = (0, util_1.promisify)(this.fs, 'readdir');
  26. this.readlink = (0, util_1.promisify)(this.fs, 'readlink');
  27. this.realpath = (0, util_1.promisify)(this.fs, 'realpath');
  28. this.rename = (0, util_1.promisify)(this.fs, 'rename');
  29. this.rmdir = (0, util_1.promisify)(this.fs, 'rmdir');
  30. this.rm = (0, util_1.promisify)(this.fs, 'rm');
  31. this.stat = (0, util_1.promisify)(this.fs, 'stat');
  32. this.symlink = (0, util_1.promisify)(this.fs, 'symlink');
  33. this.truncate = (0, util_1.promisify)(this.fs, 'truncate');
  34. this.unlink = (0, util_1.promisify)(this.fs, 'unlink');
  35. this.utimes = (0, util_1.promisify)(this.fs, 'utimes');
  36. this.readFile = (id, options) => {
  37. return (0, util_1.promisify)(this.fs, 'readFile')(id instanceof this.FileHandle ? id.fd : id, options);
  38. };
  39. this.appendFile = (path, data, options) => {
  40. return (0, util_1.promisify)(this.fs, 'appendFile')(path instanceof this.FileHandle ? path.fd : path, data, options);
  41. };
  42. this.open = (path, flags = 'r', mode) => {
  43. return (0, util_1.promisify)(this.fs, 'open', fd => new this.FileHandle(this.fs, fd))(path, flags, mode);
  44. };
  45. this.writeFile = (id, data, options) => {
  46. const dataPromise = (0, util_1.isReadableStream)(data) ? (0, util_1.streamToBuffer)(data) : Promise.resolve(data);
  47. return dataPromise.then(data => (0, util_1.promisify)(this.fs, 'writeFile')(id instanceof this.FileHandle ? id.fd : id, data, options));
  48. };
  49. this.watch = () => {
  50. throw new Error('Not implemented');
  51. };
  52. }
  53. }
  54. exports.FsPromises = FsPromises;
  55. //# sourceMappingURL=FsPromises.js.map