node.d.ts 4.4 KB

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