FileInfo.js 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.FileInfo = exports.FileType = void 0;
  4. var FileType;
  5. (function (FileType) {
  6. FileType[FileType["Unknown"] = 0] = "Unknown";
  7. FileType[FileType["File"] = 1] = "File";
  8. FileType[FileType["Directory"] = 2] = "Directory";
  9. FileType[FileType["SymbolicLink"] = 3] = "SymbolicLink";
  10. })(FileType || (exports.FileType = FileType = {}));
  11. /**
  12. * Describes a file, directory or symbolic link.
  13. */
  14. class FileInfo {
  15. constructor(name) {
  16. this.name = name;
  17. this.type = FileType.Unknown;
  18. this.size = 0;
  19. /**
  20. * Unparsed, raw modification date as a string.
  21. *
  22. * If `modifiedAt` is undefined, the FTP server you're connected to doesn't support the more modern
  23. * MLSD command for machine-readable directory listings. The older command LIST is then used returning
  24. * results that vary a lot between servers as the format hasn't been standardized. Here, directory listings
  25. * and especially modification dates were meant to be human-readable first.
  26. *
  27. * Be careful when still trying to parse this by yourself. Parsing dates from listings using LIST is
  28. * unreliable. This library decides to offer parsed dates only when they're absolutely reliable and safe to
  29. * use e.g. for comparisons.
  30. */
  31. this.rawModifiedAt = "";
  32. /**
  33. * Parsed modification date.
  34. *
  35. * Available if the FTP server supports the MLSD command. Only MLSD guarantees dates than can be reliably
  36. * parsed with the correct timezone and a resolution down to seconds. See `rawModifiedAt` property for the unparsed
  37. * date that is always available.
  38. */
  39. this.modifiedAt = undefined;
  40. /**
  41. * Unix permissions if present. If the underlying FTP server is not running on Unix this will be undefined.
  42. * If set, you might be able to edit permissions with the FTP command `SITE CHMOD`.
  43. */
  44. this.permissions = undefined;
  45. /**
  46. * Hard link count if available.
  47. */
  48. this.hardLinkCount = undefined;
  49. /**
  50. * Link name for symbolic links if available.
  51. */
  52. this.link = undefined;
  53. /**
  54. * Unix group if available.
  55. */
  56. this.group = undefined;
  57. /**
  58. * Unix user if available.
  59. */
  60. this.user = undefined;
  61. /**
  62. * Unique ID if available.
  63. */
  64. this.uniqueID = undefined;
  65. this.name = name;
  66. }
  67. get isDirectory() {
  68. return this.type === FileType.Directory;
  69. }
  70. get isSymbolicLink() {
  71. return this.type === FileType.SymbolicLink;
  72. }
  73. get isFile() {
  74. return this.type === FileType.File;
  75. }
  76. /**
  77. * Deprecated, legacy API. Use `rawModifiedAt` instead.
  78. * @deprecated
  79. */
  80. get date() {
  81. return this.rawModifiedAt;
  82. }
  83. set date(rawModifiedAt) {
  84. this.rawModifiedAt = rawModifiedAt;
  85. }
  86. }
  87. exports.FileInfo = FileInfo;
  88. FileInfo.UnixPermission = {
  89. Read: 4,
  90. Write: 2,
  91. Execute: 1
  92. };