blog icon indicating copy to clipboard operation
blog copied to clipboard

help-wanted

Open mainak0907 opened this issue 1 year ago • 1 comments

Greetings @nevo-david , I was implementing the Resume maker with ChatGPT and encountered this error.

image

mainak0907 avatar Dec 07 '23 15:12 mainak0907

Hey Mainak,

As shown in the error, the issue is that the message must be shorter than 262144 bytes, to solve this, split your message into sections split by 262144. Here's how you would do it in TypeScript

function splitStringByBytes(str: string, byteSize: number): string[] {
    const buffer = Buffer.from(str, 'utf-8');
    let start = 0;
    const result = [];

    while (start < buffer.length) {
        let end = start + byteSize;
        if (end > buffer.length) {
            end = buffer.length;
        }
        result.push(buffer.slice(start, end).toString('utf-8'));
        start = end;
    }

    return result;
}

const chunks = splitStringByBytes('The Resume Message', 262144);

Kind Regards, WillKirkmanM

WillKirkmanM avatar Jan 16 '24 21:01 WillKirkmanM