files.d.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. declare namespace files {
  2. type byte = number;
  3. function isFile(path: string): boolean;
  4. function isDir(path: string): boolean;
  5. function isEmptyDir(path: string): boolean;
  6. function join(parent: string, ...child: string[]): string;
  7. function create(path: string): boolean;
  8. function createWithDirs(path: string): boolean;
  9. function exists(path: string): boolean;
  10. function ensureDir(path: string): void;
  11. function read(path: string, encoding?: string): string;
  12. function readBytes(path: string): byte[];
  13. function write(path: string, text, encoding?: string): void;
  14. function writeBytes(path: string, bytes: byte[]): void;
  15. function append(path: string, text: string, encoding?: string): void;
  16. function appendBytes(path: string, text: byte[], encoding?: string): void;
  17. function copy(frompath: string, topath: string): boolean;
  18. function move(frompath: string, topath: string): boolean;
  19. function rename(path: string, newName): boolean;
  20. function renameWithoutExtension(path: string, newName: string): boolean;
  21. function getName(path: string): string;
  22. function getNameWithoutExtension(path: string): string;
  23. function getExtension(path: string): string;
  24. function remove(path: string): boolean;
  25. function removeDir(path: string): boolean;
  26. function getSdcardPath(): string;
  27. function cwd(): string;
  28. function path(relativePath: string): string;
  29. function listDir(path: string, filter: (filename: string) => boolean): string[];
  30. }
  31. interface ReadableTextFile {
  32. read(): string;
  33. read(maxCount: number): string;
  34. readline(): string;
  35. readlines(): string[];
  36. close(): void;
  37. }
  38. interface WritableTextFile {
  39. write(text: string): void;
  40. writeline(line: string): void;
  41. writelines(lines: string[]): void;
  42. flush(): void;
  43. close(): void;
  44. }
  45. declare function open(path: string, mode?: 'r', encoding?: string, bufferSize?: number): ReadableTextFile;
  46. declare function open(path: string, mode?: 'w' | 'a', encoding?: string, bufferSize?: number): WritableTextFile;