"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TrixOutputTransform = void 0;
const stream_1 = require("stream");
function elt(buff, current) {
    return `${current} ${buff.map((elt, idx) => `${elt},${idx + 1}`).join(' ')}\n`;
}
class TrixOutputTransform extends stream_1.Transform {
    constructor() {
        super(...arguments);
        this.buff = [];
        this.current = '';
    }
    _transform(chunk, _encoding, done) {
        // weird: need to strip nulls from string, xref
        // https://github.com/GMOD/jbrowse-components/pull/2451
        const [id, data] = chunk.toString().replace(/\0/g, '').split(' ');
        if (this.current !== id) {
            if (this.buff.length) {
                this.push(elt(this.buff, this.current));
                this.buff = [];
            }
            this.current = id;
        }
        this.buff.push(data);
        done();
    }
    _flush(done) {
        if (this.buff.length) {
            this.push(elt(this.buff, this.current));
        }
        done();
    }
}
exports.TrixOutputTransform = TrixOutputTransform;
//# sourceMappingURL=TrixOutputTransform.js.map