fs.d.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /// <reference types="node" />
  2. /// <reference types="node" />
  3. import { Stats } from "fs";
  4. export declare const MAX_FILE_REQUESTS = 8;
  5. export declare const CONCURRENCY: {
  6. concurrency: number;
  7. };
  8. export declare type AfterCopyFileTransformer = (file: string) => Promise<boolean>;
  9. export declare class CopyFileTransformer {
  10. readonly afterCopyTransformer: AfterCopyFileTransformer;
  11. constructor(afterCopyTransformer: AfterCopyFileTransformer);
  12. }
  13. export declare type FileTransformer = (file: string) => Promise<null | string | Buffer | CopyFileTransformer> | null | string | Buffer | CopyFileTransformer;
  14. export declare type Filter = (file: string, stat: Stats) => boolean;
  15. export declare function unlinkIfExists(file: string): Promise<void>;
  16. export declare function statOrNull(file: string): Promise<Stats | null>;
  17. export declare function exists(file: string): Promise<boolean>;
  18. export interface FileConsumer {
  19. consume(file: string, fileStat: Stats, parent: string, siblingNames: Array<string>): any;
  20. /**
  21. * @default false
  22. */
  23. isIncludeDir?: boolean;
  24. }
  25. /**
  26. * Returns list of file paths (system-dependent file separator)
  27. */
  28. export declare function walk(initialDirPath: string, filter?: Filter | null, consumer?: FileConsumer): Promise<Array<string>>;
  29. export declare function copyFile(src: string, dest: string, isEnsureDir?: boolean): Promise<any>;
  30. /**
  31. * Hard links is used if supported and allowed.
  32. * File permission is fixed — allow execute for all if owner can, allow read for all if owner can.
  33. *
  34. * ensureDir is not called, dest parent dir must exists
  35. */
  36. export declare function copyOrLinkFile(src: string, dest: string, stats?: Stats | null, isUseHardLink?: boolean, exDevErrorHandler?: (() => boolean) | null): Promise<any>;
  37. export declare class FileCopier {
  38. private readonly isUseHardLinkFunction?;
  39. private readonly transformer?;
  40. isUseHardLink: boolean;
  41. constructor(isUseHardLinkFunction?: ((file: string) => boolean) | null | undefined, transformer?: FileTransformer | null | undefined);
  42. copy(src: string, dest: string, stat: Stats | undefined): Promise<void>;
  43. }
  44. export interface CopyDirOptions {
  45. filter?: Filter | null;
  46. transformer?: FileTransformer | null;
  47. isUseHardLink?: ((file: string) => boolean) | null;
  48. }
  49. /**
  50. * Empty directories is never created.
  51. * Hard links is used if supported and allowed.
  52. */
  53. export declare function copyDir(src: string, destination: string, options?: CopyDirOptions): Promise<any>;
  54. export declare function dirSize(dirPath: string): Promise<number>;
  55. export declare const DO_NOT_USE_HARD_LINKS: (file: string) => boolean;
  56. export declare const USE_HARD_LINKS: (file: string) => boolean;
  57. export interface Link {
  58. readonly link: string;
  59. readonly file: string;
  60. }