Uint8Arrays bring memory-efficient(ish) byte handling to browsers - they are similar to Node.js Buffers but lack a lot of the utility methods present on that class.
This module exports a number of function that let you do common operations - joining Uint8Arrays together, seeing if they have the same contents etc.
Since Node.js Buffers are also Uint8Arrays, it falls back to Buffer internally where it makes sense for performance reasons.
Uint8Arrays bring memory-efficient(ish) byte handling to browsers - they are similar to Node.jsBuffers but lack a lot of the utility methods present on that class.This module exports a number of function that let you do common operations - joining Uint8Arrays together, seeing if they have the same contents etc.
Since Node.js
Buffers are alsoUint8Arrays, it falls back toBufferinternally where it makes sense for performance reasons.alloc(size)
Create a new
Uint8Array. When running under Node.js,Bufferwill be used in preference toUint8Array.Example
allocUnsafe(size)
Create a new
Uint8Array. When running under Node.js,Bufferwill be used in preference toUint8Array.On platforms that support it, memory referenced by the returned
Uint8Arraywill not be initialized.Example
compare(a, b)
Compare two
Uint8ArraysExample
concat(arrays, [length])
Concatenate one or more
Uint8Arrays and return aUint8Arraywith their contents.If you know the length of the arrays, pass it as a second parameter, otherwise it will be calculated by traversing the list of arrays.
Example
equals(a, b)
Returns true if the two arrays are the same array or if they have the same length and contents.
Example
fromString(string, encoding = 'utf8')
Returns a new
Uint8Arraycreated from the passed string and interpreted as the passed encoding.Supports
utf8and any of the multibase encodings as implemented by the multiformats module.Example
toString(array, encoding = 'utf8')
Returns a string created from the passed
Uint8Arrayin the passed encoding.Supports
utf8and any of the multibase encodings as implemented by the multiformats module.Example
xor(a, b)
Returns a
Uint8Arraycontainingaandbxored together.Example
xorCompare(a, b)
Compares the distances between two xor
Uint8Arrays.Example