UNPKG

528 BJavaScriptView Raw
1/**
2 * @name u8aEmpty
3 * @summary Tests for a `Uint8Array` for emptyness
4 * @description
5 * Checks to see if the input `Uint8Array` has zero length or contains all 0 values.
6 */
7export function u8aEmpty(value) {
8 const len = value.length | 0;
9 // on smaller sizes, the byte-by-byte compare is faster than allocating
10 // another object for DataView (on very large arrays the DataView is faster)
11 for (let i = 0; i < len; i++) {
12 if (value[i] | 0) {
13 return false;
14 }
15 }
16 return true;
17}