1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | import * as fs from "fs";
|
9 |
|
10 | type Data = string|Buffer|Uint8Array;
|
11 |
|
12 | interface CommonOptions {
|
13 | newline?: boolean | undefined;
|
14 | overwrite?: boolean | undefined;
|
15 | increment?: boolean | undefined;
|
16 | }
|
17 |
|
18 | type Options = Omit<fs.WriteFileOptions, "encoding"> &
|
19 | Omit<fs.MakeDirectoryOptions, "recursive"> &
|
20 | CommonOptions;
|
21 |
|
22 | type CreateWriteStreamOptions = Extract<Parameters<typeof fs.createWriteStream>[1], Record<string, any>>;
|
23 |
|
24 | type StreamOptions = Omit<CreateWriteStreamOptions, "encoding"> &
|
25 | Omit<fs.MakeDirectoryOptions, "recursive"> &
|
26 | CommonOptions;
|
27 |
|
28 | interface Result<T extends Data> {
|
29 | path: string;
|
30 | data: T;
|
31 | }
|
32 |
|
33 | type Callback<T extends Data> = (err: Error|null, result?: Result<T>) => any;
|
34 |
|
35 | declare function write<T extends Data>(filepath: string, data: T, options: Options, callback: Callback<T>): void;
|
36 | declare function write<T extends Data>(filepath: string, data: T, callback: Callback<T>): void;
|
37 | declare function write<T extends Data>(filepath: string, data: T, options?: Options): Promise<Result<T>>;
|
38 |
|
39 | declare namespace write {
|
40 | function sync<T extends Data>(filepath: string, data: T, options?: Options): Result<T>;
|
41 |
|
42 | function stream(filepath: string, options?: StreamOptions): fs.WriteStream;
|
43 | }
|
44 |
|
45 | export = write;
|