node.d.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /// <reference types="node" />
  2. import { Volume } from './volume';
  3. import { EventEmitter } from 'events';
  4. import Stats from './Stats';
  5. export declare const SEP = "/";
  6. /**
  7. * Node in a file system (like i-node, v-node).
  8. */
  9. export declare class Node extends EventEmitter {
  10. ino: number;
  11. uid: number;
  12. gid: number;
  13. atime: Date;
  14. mtime: Date;
  15. ctime: Date;
  16. buf: Buffer;
  17. perm: number;
  18. mode: number;
  19. nlink: number;
  20. symlink: string[];
  21. constructor(ino: number, perm?: number);
  22. getString(encoding?: string): string;
  23. setString(str: string): void;
  24. getBuffer(): Buffer;
  25. setBuffer(buf: Buffer): void;
  26. getSize(): number;
  27. setModeProperty(property: number): void;
  28. setIsFile(): void;
  29. setIsDirectory(): void;
  30. setIsSymlink(): void;
  31. isFile(): boolean;
  32. isDirectory(): boolean;
  33. isSymlink(): boolean;
  34. makeSymlink(steps: string[]): void;
  35. write(buf: Buffer, off?: number, len?: number, pos?: number): number;
  36. read(buf: Buffer | Uint8Array, off?: number, len?: number, pos?: number): number;
  37. truncate(len?: number): void;
  38. chmod(perm: number): void;
  39. chown(uid: number, gid: number): void;
  40. touch(): void;
  41. canRead(uid?: number, gid?: number): boolean;
  42. canWrite(uid?: number, gid?: number): boolean;
  43. del(): void;
  44. toJSON(): {
  45. ino: number;
  46. uid: number;
  47. gid: number;
  48. atime: number;
  49. mtime: number;
  50. ctime: number;
  51. perm: number;
  52. mode: number;
  53. nlink: number;
  54. symlink: string[];
  55. data: string;
  56. };
  57. }
  58. /**
  59. * Represents a hard link that points to an i-node `node`.
  60. */
  61. export declare class Link extends EventEmitter {
  62. vol: Volume;
  63. parent: Link;
  64. children: {
  65. [child: string]: Link | undefined;
  66. };
  67. private _steps;
  68. node: Node;
  69. ino: number;
  70. length: number;
  71. name: string;
  72. get steps(): string[];
  73. set steps(val: string[]);
  74. constructor(vol: Volume, parent: Link, name: string);
  75. setNode(node: Node): void;
  76. getNode(): Node;
  77. createChild(name: string, node?: Node): Link;
  78. setChild(name: string, link?: Link): Link;
  79. deleteChild(link: Link): void;
  80. getChild(name: string): Link | undefined;
  81. getPath(): string;
  82. getName(): string;
  83. /**
  84. * Walk the tree path and return the `Link` at that location, if any.
  85. * @param steps {string[]} Desired location.
  86. * @param stop {number} Max steps to go into.
  87. * @param i {number} Current step in the `steps` array.
  88. *
  89. * @return {Link|null}
  90. */
  91. walk(steps: string[], stop?: number, i?: number): Link | null;
  92. toJSON(): {
  93. steps: string[];
  94. ino: number;
  95. children: string[];
  96. };
  97. syncSteps(): void;
  98. }
  99. /**
  100. * Represents an open file (file descriptor) that points to a `Link` (Hard-link) and a `Node`.
  101. */
  102. export declare class File {
  103. fd: number;
  104. /**
  105. * Hard link that this file opened.
  106. * @type {any}
  107. */
  108. link: Link;
  109. /**
  110. * Reference to a `Node`.
  111. * @type {Node}
  112. */
  113. node: Node;
  114. /**
  115. * A cursor/offset position in a file, where data will be written on write.
  116. * User can "seek" this position.
  117. */
  118. position: number;
  119. flags: number;
  120. /**
  121. * Open a Link-Node pair. `node` is provided separately as that might be a different node
  122. * rather the one `link` points to, because it might be a symlink.
  123. * @param link
  124. * @param node
  125. * @param flags
  126. * @param fd
  127. */
  128. constructor(link: Link, node: Node, flags: number, fd: number);
  129. getString(encoding?: string): string;
  130. setString(str: string): void;
  131. getBuffer(): Buffer;
  132. setBuffer(buf: Buffer): void;
  133. getSize(): number;
  134. truncate(len?: number): void;
  135. seekTo(position: number): void;
  136. stats(): Stats<number>;
  137. write(buf: Buffer, offset?: number, length?: number, position?: number): number;
  138. read(buf: Buffer | Uint8Array, offset?: number, length?: number, position?: number): number;
  139. chmod(perm: number): void;
  140. chown(uid: number, gid: number): void;
  141. }