UNPKG

4.19 kBTypeScriptView Raw
1import { Readable, Writable } from "stream";
2export declare class RotatingFileStreamError extends Error {
3 code: string;
4 constructor();
5}
6export type Compressor = (source: string, dest: string) => string;
7export type Generator = (time: number | Date, index?: number) => string;
8interface RotatingFileStreamEvents {
9 close: () => void;
10 drain: () => void;
11 error: (err: Error) => void;
12 finish: () => void;
13 pipe: (src: Readable) => void;
14 unpipe: (src: Readable) => void;
15 external: (stdout: string, stderr: string) => void;
16 history: () => void;
17 open: (filename: string) => void;
18 removed: (filename: string, number: boolean) => void;
19 rotation: () => void;
20 rotated: (filename: string) => void;
21 warning: (error: Error) => void;
22}
23export declare interface RotatingFileStream extends Writable {
24 addListener<Event extends keyof RotatingFileStreamEvents>(event: Event, listener: RotatingFileStreamEvents[Event]): this;
25 emit<Event extends keyof RotatingFileStreamEvents>(event: Event, ...args: Parameters<RotatingFileStreamEvents[Event]>): boolean;
26 on<Event extends keyof RotatingFileStreamEvents>(event: Event, listener: RotatingFileStreamEvents[Event]): this;
27 once<Event extends keyof RotatingFileStreamEvents>(event: Event, listener: RotatingFileStreamEvents[Event]): this;
28 prependListener<Event extends keyof RotatingFileStreamEvents>(event: Event, listener: RotatingFileStreamEvents[Event]): this;
29 prependOnceListener<Event extends keyof RotatingFileStreamEvents>(event: Event, listener: RotatingFileStreamEvents[Event]): this;
30 removeListener<Event extends keyof RotatingFileStreamEvents>(event: Event, listener: RotatingFileStreamEvents[Event]): this;
31}
32export interface Options {
33 compress?: boolean | string | Compressor;
34 encoding?: BufferEncoding;
35 history?: string;
36 immutable?: boolean;
37 initialRotation?: boolean;
38 interval?: string;
39 intervalBoundary?: boolean;
40 intervalUTC?: boolean;
41 maxFiles?: number;
42 maxSize?: string;
43 mode?: number;
44 omitExtension?: boolean;
45 path?: string;
46 rotate?: number;
47 size?: string;
48 teeToStdout?: boolean;
49}
50interface Opts {
51 compress?: string | Compressor;
52 encoding?: BufferEncoding;
53 history?: string;
54 immutable?: boolean;
55 initialRotation?: boolean;
56 interval?: {
57 num: number;
58 unit: string;
59 };
60 intervalBoundary?: boolean;
61 intervalUTC?: boolean;
62 maxFiles?: number;
63 maxSize?: number;
64 mode?: number;
65 omitExtension?: boolean;
66 path?: string;
67 rotate?: number;
68 size?: number;
69 teeToStdout?: boolean;
70}
71type Callback = (error?: Error) => void;
72interface Chunk {
73 chunk: Buffer;
74 encoding: BufferEncoding;
75}
76export declare class RotatingFileStream extends Writable {
77 private createGzip;
78 private exec;
79 private file;
80 private filename;
81 private finished;
82 private fsCreateReadStream;
83 private fsCreateWriteStream;
84 private fsOpen;
85 private fsReadFile;
86 private fsStat;
87 private fsUnlink;
88 private generator;
89 private initPromise;
90 private last;
91 private maxTimeout;
92 private next;
93 private options;
94 private prev;
95 private rotation;
96 private size;
97 private stdout;
98 private timeout;
99 private timeoutPromise;
100 constructor(generator: Generator, options: Opts);
101 _destroy(error: Error, callback: Callback): void;
102 _final(callback: Callback): void;
103 _write(chunk: Buffer, encoding: BufferEncoding, callback: Callback): void;
104 _writev(chunks: Chunk[], callback: Callback): void;
105 private refinal;
106 private rewrite;
107 private init;
108 private makePath;
109 private reopen;
110 private reclose;
111 private now;
112 private rotate;
113 private findName;
114 private move;
115 private touch;
116 private classical;
117 private clear;
118 private intervalBoundsBig;
119 private intervalBounds;
120 private interval;
121 private compress;
122 private gzip;
123 private rotated;
124 private history;
125 private immutate;
126 private unlink;
127}
128export declare function createStream(filename: string | Generator, options?: Options): RotatingFileStream;
129export {};