promises.js 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.createPromisesApi = void 0;
  4. const FileHandle_1 = require("./FileHandle");
  5. const util_1 = require("./util");
  6. function createPromisesApi(vol) {
  7. if (typeof Promise === 'undefined')
  8. return null;
  9. return {
  10. FileHandle: FileHandle_1.FileHandle,
  11. access(path, mode) {
  12. return (0, util_1.promisify)(vol, 'access')(path, mode);
  13. },
  14. appendFile(path, data, options) {
  15. return (0, util_1.promisify)(vol, 'appendFile')(path instanceof FileHandle_1.FileHandle ? path.fd : path, data, options);
  16. },
  17. chmod(path, mode) {
  18. return (0, util_1.promisify)(vol, 'chmod')(path, mode);
  19. },
  20. chown(path, uid, gid) {
  21. return (0, util_1.promisify)(vol, 'chown')(path, uid, gid);
  22. },
  23. copyFile(src, dest, flags) {
  24. return (0, util_1.promisify)(vol, 'copyFile')(src, dest, flags);
  25. },
  26. lchmod(path, mode) {
  27. return (0, util_1.promisify)(vol, 'lchmod')(path, mode);
  28. },
  29. lchown(path, uid, gid) {
  30. return (0, util_1.promisify)(vol, 'lchown')(path, uid, gid);
  31. },
  32. link(existingPath, newPath) {
  33. return (0, util_1.promisify)(vol, 'link')(existingPath, newPath);
  34. },
  35. lstat(path, options) {
  36. return (0, util_1.promisify)(vol, 'lstat')(path, options);
  37. },
  38. mkdir(path, options) {
  39. return (0, util_1.promisify)(vol, 'mkdir')(path, options);
  40. },
  41. mkdtemp(prefix, options) {
  42. return (0, util_1.promisify)(vol, 'mkdtemp')(prefix, options);
  43. },
  44. open(path, flags, mode) {
  45. return (0, util_1.promisify)(vol, 'open', fd => new FileHandle_1.FileHandle(vol, fd))(path, flags, mode);
  46. },
  47. readdir(path, options) {
  48. return (0, util_1.promisify)(vol, 'readdir')(path, options);
  49. },
  50. readFile(id, options) {
  51. return (0, util_1.promisify)(vol, 'readFile')(id instanceof FileHandle_1.FileHandle ? id.fd : id, options);
  52. },
  53. readlink(path, options) {
  54. return (0, util_1.promisify)(vol, 'readlink')(path, options);
  55. },
  56. realpath(path, options) {
  57. return (0, util_1.promisify)(vol, 'realpath')(path, options);
  58. },
  59. rename(oldPath, newPath) {
  60. return (0, util_1.promisify)(vol, 'rename')(oldPath, newPath);
  61. },
  62. rmdir(path, options) {
  63. return (0, util_1.promisify)(vol, 'rmdir')(path, options);
  64. },
  65. rm(path, options) {
  66. return (0, util_1.promisify)(vol, 'rm')(path, options);
  67. },
  68. stat(path, options) {
  69. return (0, util_1.promisify)(vol, 'stat')(path, options);
  70. },
  71. symlink(target, path, type) {
  72. return (0, util_1.promisify)(vol, 'symlink')(target, path, type);
  73. },
  74. truncate(path, len) {
  75. return (0, util_1.promisify)(vol, 'truncate')(path, len);
  76. },
  77. unlink(path) {
  78. return (0, util_1.promisify)(vol, 'unlink')(path);
  79. },
  80. utimes(path, atime, mtime) {
  81. return (0, util_1.promisify)(vol, 'utimes')(path, atime, mtime);
  82. },
  83. writeFile(id, data, options) {
  84. return (0, util_1.promisify)(vol, 'writeFile')(id instanceof FileHandle_1.FileHandle ? id.fd : id, data, options);
  85. },
  86. };
  87. }
  88. exports.createPromisesApi = createPromisesApi;