]> git.codecow.com Git - libnemo.git/commitdiff
Allow byte conversion to hex from buffer as well as typed array.
authorChris Duncan <chris@zoso.dev>
Fri, 22 Aug 2025 09:04:52 +0000 (02:04 -0700)
committerChris Duncan <chris@zoso.dev>
Fri, 22 Aug 2025 09:04:52 +0000 (02:04 -0700)
src/lib/convert.ts

index c270fb34bddb137e98eaa755194c33b630572a62..ba29b6a79bb40048f0cf872e7de6cdbeecda25e6 100644 (file)
@@ -151,7 +151,8 @@ export class bytes {
        * @param {Uint8Array} bytes - Byte array to convert\r
        * @returns {string} Hexadecimal string representation of the input bytes\r
        */\r
-       static toHex (bytes: Uint8Array): string {\r
+       static toHex (bytes: ArrayBuffer | Uint8Array): string {\r
+               if (bytes instanceof ArrayBuffer) bytes = new Uint8Array(bytes)\r
                if (bytes.buffer instanceof ArrayBuffer && bytes.buffer.detached) return ''\r
                return [...bytes]\r
                        .map(byte => byte.toString(16).padStart(2, '0'))\r