* Converts an ArrayBuffer to a string. * * @param {ArrayBuffer} arrayBuffer * @param {boolean} [utf8=true] - Whether to attempt to decode the buffer as UTF-8 * @returns {string} * * @example * // returns "hello" * Utils.arrayBufferToStr(Uint8Array.from([104,10
(arrayBuffer, utf8=true)
| 691 | * Utils.arrayBufferToStr(Uint8Array.from([104,101,108,108,111]).buffer); |
| 692 | */ |
| 693 | static arrayBufferToStr(arrayBuffer, utf8=true) { |
| 694 | log.debug(`Converting array buffer[${arrayBuffer?.byteLength}] to str`); |
| 695 | if (!arrayBuffer || !arrayBuffer.byteLength) return ""; |
| 696 | const arr = new Uint8Array(arrayBuffer); |
| 697 | return utf8 ? Utils.byteArrayToUtf8(arr) : Utils.byteArrayToChars(arr); |
| 698 | } |
| 699 | |
| 700 | /** |
| 701 | * Calculates the Shannon entropy for a given set of data. |
no test coverage detected