UNPKG

1.37 kBTypeScriptView Raw
1declare namespace cpFile {
2 interface Options {
3 /**
4 Overwrite existing file.
5
6 @default true
7 */
8 readonly overwrite?: boolean;
9 }
10
11 interface ProgressData {
12 /**
13 Absolute path to source.
14 */
15 src: string;
16
17 /**
18 Absolute path to destination.
19 */
20 dest: string;
21
22 /**
23 File size in bytes.
24 */
25 size: number;
26
27 /**
28 Copied size in bytes.
29 */
30 written: number;
31
32 /**
33 Copied percentage, a value between `0` and `1`.
34 */
35 percent: number;
36 }
37
38 interface ProgressEmitter {
39 /**
40 For empty files, the `progress` event is emitted only once.
41 */
42 on(event: 'progress', handler: (data: ProgressData) => void): Promise<void>;
43 }
44}
45
46declare const cpFile: {
47 /**
48 Copy a file.
49
50 @param source - File you want to copy.
51 @param destination - Where you want the file copied.
52 @returns A `Promise` that resolves when the file is copied.
53
54 @example
55 ```
56 import cpFile = require('cp-file');
57
58 (async () => {
59 await cpFile('source/unicorn.png', 'destination/unicorn.png');
60 console.log('File copied');
61 })();
62 ```
63 */
64 (source: string, destination: string, options?: cpFile.Options): Promise<void> & cpFile.ProgressEmitter;
65
66 /**
67 Copy a file synchronously.
68
69 @param source - File you want to copy.
70 @param destination - Where you want the file copied.
71 */
72 sync(source: string, destination: string, options?: cpFile.Options): void;
73};
74
75export = cpFile;