DataPower

DataPower

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only

Buffer and Buffers datatypes

  • 1.  Buffer and Buffers datatypes

    Posted Wed July 01, 2020 06:15 AM

    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/
    ------------------------------