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