SFN-Output-Buffer
Simple Friendly Node.js Output Buffer.
Install
npm install sfn-output-buffer --save
Import
const OutputBuffer = ;
Example
var ob = size: 50 filename: "example.log"; var count = 0;var i = ;
API
new OutputBuffer()
Creates a new output buffer.ob.push(...data: any[])
Pushes data into the buffer.ob.get(): string
Gets buffer contents.ob.clean()
Cleans buffer contents without flushing.ob.destroy()
Destroys the buffer without flushing.ob.close()
Closes the buffer safely, buffer will be flushed before destroying.ob.closed
Whether the buffer is closed.
new OutputBuffer()
new OutputBuffer(filename?: string)
new OutputBuffer(options?: object)
Creates a new output buffer.-
options
Include these options:ttl
Time to live, default is1000
ms.size
Buffer size, if set, thenttl
will be ignored.filename
Flush buffer to a disk file.fileSize
Maximum size of the output file.limitHandler
A function called when the output file's size up to limit, rewrite by default.errorHandler
A function called when any error occurred in the asynchronous timer scope.
If this parameter is passed as a string, then it will be treated as a
filename
.
-
// Simplest way, buffer will be flushed to console every 1000 ms.var ob = ; // Flush buffer to a file in 1000 ms:var ob = "example.log"; // Flush buffer to a file when the buffer size up to 1 Mb:var ob = size: 1024 * 1024 filename: "example.log"; // Rewrite the output file when its size up to 10 Mb:var ob = size: 1024 * 1024 filename: "example.log" fileSize: 1024 * 1024 * 10; // Customize handlers:var ob = ttl: 10000 // Flush buffer every 10 seconds. filename: "example.log" fileSize: 1024 * 1024 * 10 { // Do some stuffs... ; // Must call next(), otherwise the timer-chain will be broken. } { console; };