* Convert a primitive chunk to Uint8Array. * - string: UTF-8 encoded * - ArrayBuffer: wrapped as Uint8Array view (no copy) * - ArrayBufferView: converted to Uint8Array view of same memory * @param {string|ArrayBuffer|ArrayBufferView} chunk * @returns {Uint8Array}
(chunk)
| 96 | * @returns {Uint8Array} |
| 97 | */ |
| 98 | function primitiveToUint8Array(chunk) { |
| 99 | if (typeof chunk === 'string') { |
| 100 | return toUint8Array(chunk); |
| 101 | } |
| 102 | if (isAnyArrayBuffer(chunk)) { |
| 103 | return new Uint8Array(chunk); |
| 104 | } |
| 105 | if (isUint8Array(chunk)) { |
| 106 | return chunk; |
| 107 | } |
| 108 | // Other ArrayBufferView types (Int8Array, DataView, etc.) |
| 109 | return arrayBufferViewToUint8Array(chunk); |
| 110 | } |
| 111 | |
| 112 | function arrayBufferViewToUint8Array(chunk) { |
| 113 | if (isTypedArray(chunk)) { |
no test coverage detected
searching dependent graphs…