This is followup on posting How to determine maximal GatewayScript String and Buffer lengths.
Buffer maximal length is 2GB-1byte. If you need longer, use Buffers datatype.
That can be read via "session.input.readAsBuffers()", or created by passing an array of Buffer objects.
You can slice out a part from Buffers object, but the result is a Buffer object, and therefore restricted to 2GB-1byte in size. You can create another Buffers object from array of sliced out Buffer objects.
APIs:
https://www.ibm.com/support/knowledgecenter/SS9H2Y_7.7.0/com.ibm.dp.doc/buffer_js.html
https://www.ibm.com/support/knowledgecenter/SS9H2Y_7.7.0/com.ibm.dp.doc/buffers_js.html
Small sample demonstration with nearly 6GB Buffers object:
$ coproc2 buffers.js <('') dp3-l3.boeblingen.de.ibm.com:2227; echo
2147483647: 2147483647,2147483647
$
$ cat buffers.js
'use strict';
const N = 2*1024*1024*1024-1;
const b1 = Buffer.alloc(N,0x01);
const b2 = Buffer.alloc(N,0x02);
const b3 = Buffer.alloc(N,0x03);
const bufs = new Buffers([b1,b2,b3]);
var sp1 = bufs.slice( N/2, 3*N/2);
var sp2 = bufs.slice(3*N/2, 5*N/2);
session.output.write(N+": "+sp1.length+","+sp2.length);
$
------------------------------
Hermann Stamm-Wilbrandt
Compiler Level 3 support & Fixpack team lead
IBM DataPower Gateways (⬚ᵈᵃᵗᵃ / ⣏⠆⡮⡆⢹⠁⡮⡆⡯⠂⢎⠆⡧⡇⣟⡃⡿⡃)
https://stamm-wilbrandt.de/en/blog/------------------------------