Function concatArrayBuffers

  • Concatenate an array of typed arrays into a single ArrayBuffer. This is a fast path.

    You can do this manually if you'd like, but this function will generally be a little faster.

    If you want a Uint8Array instead, consider Buffer.concat.

    Returns

    An ArrayBuffer with the data from all the buffers.

    Here is similar code to do it manually, except about 30% slower:

      var chunks = [...];
    var size = 0;
    for (const chunk of chunks) {
    size += chunk.byteLength;
    }
    var buffer = new ArrayBuffer(size);
    var view = new Uint8Array(buffer);
    var offset = 0;
    for (const chunk of chunks) {
    view.set(chunk, offset);
    offset += chunk.byteLength;
    }
    return buffer;

    This function is faster because it uses uninitialized memory when copying. Since the entire length of the buffer is known, it is safe to use uninitialized memory.

    Parameters

    • buffers: (ArrayBufferLike | ArrayBufferView)[]

      An array of typed arrays to concatenate.

    Returns ArrayBuffer

  • Concatenate an array of typed arrays into a single ArrayBuffer. This is a fast path.

    You can do this manually if you'd like, but this function will generally be a little faster.

    If you want a Uint8Array instead, consider Buffer.concat.

    Returns

    An ArrayBuffer with the data from all the buffers.

    Here is similar code to do it manually, except about 30% slower:

      var chunks = [...];
    var size = 0;
    for (const chunk of chunks) {
    size += chunk.byteLength;
    }
    var buffer = new ArrayBuffer(size);
    var view = new Uint8Array(buffer);
    var offset = 0;
    for (const chunk of chunks) {
    view.set(chunk, offset);
    offset += chunk.byteLength;
    }
    return buffer;

    This function is faster because it uses uninitialized memory when copying. Since the entire length of the buffer is known, it is safe to use uninitialized memory.

    Parameters

    • buffers: (ArrayBufferLike | ArrayBufferView)[]

      An array of typed arrays to concatenate.

    Returns ArrayBuffer

Generated using TypeDoc