export class StreamParser {
    buffer = '';
    ended = false;
    onChunk;
    onDone;
    constructor(opts) {
        this.onChunk = opts.onChunk;
        this.onDone = opts.onDone;
    }
    write(data) {
        if (this.ended)
            return;
        const text = typeof data === 'string' ? data : data.toString('utf-8');
        if (text.length === 0)
            return;
        this.buffer += text;
        this.onChunk(text);
    }
    end() {
        if (this.ended)
            return;
        this.ended = true;
        this.onDone(this.buffer);
    }
}
//# sourceMappingURL=stream-parser.js.map