Skip to content

Commit

Permalink
minor minor minor optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
iccicci committed Apr 29, 2020
1 parent 630dcda commit 3dd96d9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
2 changes: 1 addition & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export class RotatingFileStream extends Writable {
done();
});

if(this.options.teeToStdout) process.stdout.write(chunk.chunk, chunk.encoding, () => {});
if(this.options.teeToStdout) process.stdout.write(chunk.chunk, chunk.encoding);
};

if(this.stream) {
Expand Down
13 changes: 4 additions & 9 deletions test/05options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,7 @@ describe("options", () => {
const events = test({ options: { size: "10B", teeToStdout: true } }, rfs => {
const write = process.stdout.write;

process.stdout.write = (str: string | Uint8Array, encoding?: string | ((err?: Error) => void), cb?: (err?: Error) => void): boolean => {
content.push({ str, encoding });
cb();

return false;
};
process.stdout.write = (str: string | Uint8Array, encoding?: string | ((err?: Error) => void), cb?: (err?: Error) => void): boolean => content.push({ str, encoding, cb }) === 0;

rfs.write("test\n");
rfs.write("test\n");
Expand All @@ -156,9 +151,9 @@ describe("options", () => {
it("events", () => deq(events, { finish: 1, open: ["test.log", "test.log"], rotated: ["1-test.log"], rotation: 1, write: 1, writev: 1 }));
it("stdout", () =>
deq(content, [
{ encoding: "buffer", str: Buffer.from("test\n") },
{ encoding: "buffer", str: Buffer.from("test\n") },
{ encoding: "buffer", str: Buffer.from("test\n") },
{ str: Buffer.from("test\n"), encoding: "buffer", cb: undefined },
{ str: Buffer.from("test\n"), encoding: "buffer", cb: undefined },
{ str: Buffer.from("test\n"), encoding: "buffer", cb: undefined }
]));
it("file content", () => eq(readFileSync("test.log", "utf8"), "test\n"));
it("rotated file content", () => eq(readFileSync("1-test.log", "utf8"), "test\ntest\n"));
Expand Down

0 comments on commit 3dd96d9

Please sign in to comment.