batchjs
Version:
Batch processing framework for NodeJS
45 lines (44 loc) • 1.41 kB
TypeScript
import { TransformCallback } from "stream";
import { SingleObjectDuplex, ObjectDuplexOptions } from "../interfaces/_index";
/**
* @class
* Class that allows you to count the number of chunks in a stream.
* @extends SingleObjectDuplex
* @template T
* @example
* ```typescript
* const stream:CountStream<string> = new CountStream({
* objectMode: true,
* });
*
* stream.write("data1");
* stream.write("data2");
* stream.write("data3");
* stream.end();
*
* stream.on("data", (chunk: number) => {
* console.log(``Received chunks: ${chunk}```);
* });
* ```
* ```shell
* >> Received chunks: 3
* ```
*/
export declare class CountStream<T extends NonNullable<unknown>> extends SingleObjectDuplex<T, number> {
protected result: number;
/**
* @constructor
* @param {ObjectDuplexOptions} options - The options for the GroupBy.
*/
constructor(options: ObjectDuplexOptions);
/**
* Writes a chunk of data to the stream, groups it according to a specified function,
* and executes the callback.
*
* @param {T} chunk - The data chunk to write to the stream.
* @param {BufferEncoding} encoding - The encoding of the data.
* @param {TransformCallback} callback - The callback function to be executed after writing the data.
* @return {void}
*/
_write(chunk: T, encoding: BufferEncoding, callback: TransformCallback): void;
}