FileHandle.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.FileHandle = void 0;
  4. const util_1 = require("./util");
  5. class FileHandle {
  6. constructor(fs, fd) {
  7. this.fs = fs;
  8. this.fd = fd;
  9. }
  10. appendFile(data, options) {
  11. return (0, util_1.promisify)(this.fs, 'appendFile')(this.fd, data, options);
  12. }
  13. chmod(mode) {
  14. return (0, util_1.promisify)(this.fs, 'fchmod')(this.fd, mode);
  15. }
  16. chown(uid, gid) {
  17. return (0, util_1.promisify)(this.fs, 'fchown')(this.fd, uid, gid);
  18. }
  19. close() {
  20. return (0, util_1.promisify)(this.fs, 'close')(this.fd);
  21. }
  22. datasync() {
  23. return (0, util_1.promisify)(this.fs, 'fdatasync')(this.fd);
  24. }
  25. read(buffer, offset, length, position) {
  26. return (0, util_1.promisify)(this.fs, 'read', bytesRead => ({ bytesRead, buffer }))(this.fd, buffer, offset, length, position);
  27. }
  28. readFile(options) {
  29. return (0, util_1.promisify)(this.fs, 'readFile')(this.fd, options);
  30. }
  31. stat(options) {
  32. return (0, util_1.promisify)(this.fs, 'fstat')(this.fd, options);
  33. }
  34. sync() {
  35. return (0, util_1.promisify)(this.fs, 'fsync')(this.fd);
  36. }
  37. truncate(len) {
  38. return (0, util_1.promisify)(this.fs, 'ftruncate')(this.fd, len);
  39. }
  40. utimes(atime, mtime) {
  41. return (0, util_1.promisify)(this.fs, 'futimes')(this.fd, atime, mtime);
  42. }
  43. write(buffer, offset, length, position) {
  44. return (0, util_1.promisify)(this.fs, 'write', bytesWritten => ({ bytesWritten, buffer }))(this.fd, buffer, offset, length, position);
  45. }
  46. writeFile(data, options) {
  47. return (0, util_1.promisify)(this.fs, 'writeFile')(this.fd, data, options);
  48. }
  49. }
  50. exports.FileHandle = FileHandle;