I'd like to merge multiple arraybuffers to create a Blob. however, as you know, TypedArray dosen't have "push" or useful methods...
E.g.:
var a = new Int8Array( [ 1, 2, 3 ] ); var b = new Int8Array( [ 4, 5, 6 ] );
As a result, I'd like to get [ 1, 2, 3, 4, 5, 6 ]
.
You can use the set method. Create a new typed array with all the sizes. Example: var arrayOne = new Uint8Array([2,4,8]); var arrayTwo = new Uint8Array([16,32,64]); var mergedArray = new Uint8Array(arrayOne.
The ArrayBuffer object is used to represent a generic, fixed-length raw binary data buffer. It is an array of bytes, often referred to in other languages as a "byte array".
JavaScript typed arrays are array-like objects that provide a mechanism for reading and writing raw binary data in memory buffers. Array objects grow and shrink dynamically and can have any JavaScript value. JavaScript engines perform optimizations so that these arrays are fast.
The Uint8Array() constructor creates a typed array of 8-bit unsigned integers. The contents are initialized to 0 . Once established, you can reference elements in the array using the object's methods, or using standard array index syntax (that is, using bracket notation).
Use the set
method. But note, that you now need twice the memory!
var a = new Int8Array( [ 1, 2, 3 ] ); var b = new Int8Array( [ 4, 5, 6 ] ); var c = new Int8Array(a.length + b.length); c.set(a); c.set(b, a.length); console.log(a); console.log(b); console.log(c);
for client-side ~ok solution:
const a = new Int8Array( [ 1, 2, 3 ] ) const b = new Int8Array( [ 4, 5, 6 ] ) const c = Int8Array.from([...a, ...b])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With