"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ReadableWithEventPipe = exports.TransformWithEventPipe = void 0;
const stream_1 = require("stream");
/**
 * A Transform stream that forwards events to the destination stream
 */
class TransformWithEventPipe extends stream_1.Transform {
    constructor(opts = { objectMode: true }) {
        super(opts);
        if (opts.passThrough) {
            this._transform = (data, _, next) => next(null, data);
        }
    }
    /**
     * Pipe that also forwards events
     * @param {TransformWithEventPipe | Transform | Writable} destination Destination stream
     * @param {Array<string>} events Events to pipe
     * @param {any} pipeOpts Pipe options
     * @returns
     */
    eventPipe(destination, events, pipeOpts) {
        this.on('error', err => destination.emit('error', err));
        for (const event of events || []) {
            this.on(event, (...args) => destination.emit(event, ...args));
        }
        return this.pipe(destination, pipeOpts);
    }
}
exports.TransformWithEventPipe = TransformWithEventPipe;
/**
 * A Readable stream that forwards events to the destination stream
 */
class ReadableWithEventPipe extends stream_1.Readable {
    constructor(opts = { objectMode: true }) {
        super(opts);
    }
    /**
     * Pipe that also forwards events
     * @param {TransformWithEventPipe | Transform | Writable} destination Destination stream
     * @param {Array<string>} events Events to pipe
     * @param {any} pipeOpts Pipe options
     * @returns
     */
    eventPipe(destination, events, pipeOpts) {
        this.on('error', err => destination.emit('error', err));
        for (const event of events || []) {
            this.on(event, (...args) => destination.emit(event, ...args));
        }
        return this.pipe(destination, pipeOpts);
    }
}
exports.ReadableWithEventPipe = ReadableWithEventPipe;
//# sourceMappingURL=streamWithEventPipe.js.map