• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

palcarazm / batchjs / 17580344153

09 Sep 2025 10:55AM UTC coverage: 98.387% (-1.4%) from 99.825%
17580344153

Pull #58

github

web-flow
Merge 5a02e8636 into a2981500d
Pull Request #58: fix: prevent write callback call before flushing

89 of 90 branches covered (98.89%)

Branch coverage included in aggregate %.

31 of 39 new or added lines in 8 files covered. (79.49%)

460 of 468 relevant lines covered (98.29%)

75.42 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.71
/src/streams/classes/FlatStream.ts
1
import { TransformCallback } from "stream";
2
import { InternalBufferDuplex, ObjectDuplexOptions } from "../interfaces/_index";
120✔
3

4
/**
5
 * @class
6
 * Class that allows you to transform an array stream into a flat stream.
7
 * @extends InternalBufferDuplex
8
 * @template T
9
 * @example
10
 * ```typescript
11
 * const stream:FlatStream<string> = new FlatStream({
12
 *     objectMode: true,
13
 *     matcher: (chunk: string) => chunk.length > 2
14
 * });
15
 * 
16
 * stream.write(["data1", "data2"]);
17
 * stream.write(["data3"]);
18
 * stream.end();
19
 * 
20
 * stream.on("data", (chunk: string) => {
21
 *     console.log(``Pushed chunk: ${chunk}```);
22
 * });
23
 * ```
24
 * ```shell
25
 * >> Pushed chunk: data1
26
 * >> Pushed chunk: data2
27
 * >> Pushed chunk: data3
28
 * ```
29
 */
30
export class FlatStream<T> extends InternalBufferDuplex<T[],T> {
120✔
31
    /**
32
     * @constructor
33
     * @param {ObjectDuplexOptions} options - The options for the FlatStream.
34
     */
35
    constructor(options: ObjectDuplexOptions) {
36
        super(options);
6✔
37
    }
38

39
    /**
40
     * A method to write data to the stream, push the chunk to the buffer, and execute the callback.
41
     *
42
     * @param {Array<T>} chunk - The data chunk to write to the stream.
43
     * @param {BufferEncoding} encoding - The encoding of the data.
44
     * @param {TransformCallback} callback - The callback function to be executed after writing the data.
45
     * @return {void} This function does not return anything.
46
     */
47
    _write(chunk: Array<T>, encoding: BufferEncoding, callback: TransformCallback): void {
48
        this.buffer.push(...chunk);
12✔
49
        this._flush()
12✔
50
            .then(()=>callback())
12✔
NEW
51
            .catch((e)=>callback(e));
×
52
    }
53
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc