-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
139 additions
and
66 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/// <reference types="node" /> | ||
import { Writable } from "stream"; | ||
export declare type Compressor = (source: string, dest: string) => string; | ||
export declare type Generator = (time: number | Date, index?: number) => string; | ||
export interface Options { | ||
compress?: boolean | string | Compressor; | ||
encoding?: BufferEncoding; | ||
history?: string; | ||
immutable?: boolean; | ||
initialRotation?: boolean; | ||
interval?: string; | ||
intervalBoundary?: boolean; | ||
maxFiles?: number; | ||
maxSize?: string; | ||
mode?: number; | ||
path?: string; | ||
rotate?: number; | ||
size?: string; | ||
teeToStdout?: boolean; | ||
} | ||
interface Opts { | ||
compress?: string | Compressor; | ||
encoding?: BufferEncoding; | ||
history?: string; | ||
immutable?: boolean; | ||
initialRotation?: boolean; | ||
interval?: { | ||
num: number; | ||
unit: string; | ||
}; | ||
intervalBoundary?: boolean; | ||
maxFiles?: number; | ||
maxSize?: number; | ||
mode?: number; | ||
path?: string; | ||
rotate?: number; | ||
size?: number; | ||
teeToStdout?: boolean; | ||
} | ||
declare type Callback = (error?: Error) => void; | ||
interface Chunk { | ||
chunk: Buffer; | ||
encoding: BufferEncoding; | ||
next: Chunk; | ||
} | ||
export declare class RotatingFileStream extends Writable { | ||
private createGzip; | ||
private destroyer; | ||
private error; | ||
private exec; | ||
private filename; | ||
private finished; | ||
private fsClose; | ||
private fsCreateReadStream; | ||
private fsCreateWriteStream; | ||
private fsMkdir; | ||
private fsOpen; | ||
private fsReadFile; | ||
private fsRename; | ||
private fsStat; | ||
private fsUnlink; | ||
private fsWrite; | ||
private fsWriteFile; | ||
private generator; | ||
private last; | ||
private maxTimeout; | ||
private next; | ||
private opened; | ||
private options; | ||
private prev; | ||
private rotatedName; | ||
private rotation; | ||
private size; | ||
private stream; | ||
private timer; | ||
constructor(generator: Generator, options: Opts); | ||
_destroy(error: Error, callback: Callback): void; | ||
_final(callback: Callback): void; | ||
_write(chunk: Buffer, encoding: BufferEncoding, callback: Callback): void; | ||
_writev(chunks: Chunk[], callback: Callback): void; | ||
private rewrite; | ||
private init; | ||
private makePath; | ||
private reopen; | ||
private reclose; | ||
private now; | ||
private rotate; | ||
private findName; | ||
private move; | ||
private touch; | ||
private classical; | ||
private clear; | ||
private intervalBoundsBig; | ||
private intervalBounds; | ||
private interval; | ||
private compress; | ||
private external; | ||
private gzip; | ||
private rotated; | ||
private history; | ||
private historyGather; | ||
private historyRemove; | ||
private historyCheckFiles; | ||
private historyCheckSize; | ||
private historyWrite; | ||
private immutate; | ||
} | ||
export declare function createStream(filename: string | Generator, options?: Options): RotatingFileStream; | ||
export {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,10 @@ | ||
"use strict"; | ||
|
||
import { readFile, unlink, writeFile } from "fs"; | ||
import { unlink, writeFile } from "fs"; | ||
|
||
const common: string[] = ["*gz", "*log", "*tmp", "*txt", ".gitignore", ".npmignore", ".nyc_output", "coverage", "node_modules", ""]; | ||
const git: string[] = ["index.d.ts", "index.js"]; | ||
const npm: string[] = [".*", "index.ts", "test", "tsconfig.json", "tslint.json", "utils.ts"]; | ||
const git: string[] = ["index.js"]; | ||
const npm: string[] = [".*", "index.ts", "test", "tsconfig.json", "utils.ts"]; | ||
|
||
const readme: (err: Error, data: string) => void = (err, data) => { | ||
if(err) return process.stderr.write(`Error reading README.md: ${err.message}`); | ||
|
||
const input = data.split("\n"); | ||
|
||
readFile("index.d.ts", "utf8", (err: Error, data: string) => { | ||
if(err) return process.stderr.write(`Error reading index.d.ts: ${err.message}`); | ||
|
||
const output = []; | ||
let begin: boolean, end: boolean; | ||
|
||
input.map((line: string) => { | ||
if(begin) { | ||
if(end) output.push(line); | ||
else if(line === "```") { | ||
output.push(line); | ||
end = true; | ||
} | ||
} | ||
|
||
if(! begin) { | ||
output.push(line); | ||
if(line === "```typescript") { | ||
let first: boolean, interf: boolean; | ||
begin = true; | ||
data.split("\n").map((line: string) => { | ||
if(! first) return (first = true); | ||
if(interf) return (interf = ! line.match(/}$/)); | ||
if(line.match(/interface Chunk/) || line.match(/interface Opts/)) return (interf = true); | ||
if(line.match(/class RotatingFileStream/)) interf = ((line = line.replace("{", "{}")) as unknown) as boolean; | ||
if(! line.match(/Callback/) && ! line.match(/export \{}/)) output.push(line.replace(" ", " ")); | ||
}); | ||
output.pop(); | ||
} | ||
} | ||
}); | ||
|
||
writeFile("README.md", output.join("\n"), () => {}); | ||
}); | ||
}; | ||
|
||
if(process.argv[2] === "clean") unlink("index.js", (): void => unlink("index.d.ts", (): void => {})); | ||
if(process.argv[2] === "clean") unlink("index.js", (): void => {}); | ||
if(process.argv[2] === "ignore") writeFile(".gitignore", git.concat(common).join("\n"), (): void => writeFile(".npmignore", npm.concat(common).join("\n"), (): void => {})); | ||
if(process.argv[2] === "readme") readFile("README.md", "utf8", readme); |