Is there a way to send large chunk of data over BLE in JavaScript?

I’m trying to send an image (15000 byte) to a BLE peripheral.

After searching I only found p5.ble.js library that supports BLE in JavaScript.

function setup() {
    myBLE = new p5ble();

    // Create a 'Write' button
    const writeButton = createButton('Write');
    // writeButton.position(input.x + input.width + 15, 100);
    writeButton.mousePressed(writeToBle);

    for(let i = 0; i < 15000; i++)
    {
      img[i] = i;
      // console.log(img[i]);
    }
}


function writeToBle() {
  var str1 = new TextDecoder().decode(img.slice(0,127));

  // sending 2nd chunk
setTimeout(function(){
    var str2 = new TextDecoder().decode(img.slice(128,255)); // this just result in garbage
      myBLE.write(myCharacteristic, str2);
    }, 1000);

    // sending first chunk
    myBLE.write(myCharacteristic, str1);
    // myBLE.write(myCharacteristic, img.slice(0,127)); // this doesn't send
}

This is my first JavaScript code (and it is just a modification of an example code from p5 ble).

With this code I can send str1 without any problems. I receive the right data and the right number of bytes.

But for some reason when sending str2 I receive around 500 bytes instead of 128 bytes and the data is just a repetition of these numbers 239, 191, 189!

What I’m doing wrong here?

Is there a better alternative for p5.ble library?