import { Transform } from 'stream';
function elt(buff, current) {
    return `${current} ${buff.map((elt, idx) => `${elt},${idx + 1}`).join(' ')}\n`;
}
export class TrixOutputTransform extends 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();
    }
}
//# sourceMappingURL=TrixOutputTransform.js.map