* @see https://encoding.spec.whatwg.org/#utf-8-decode * @param {Uint8Array} buffer
(buffer)
| 7 | * @param {Uint8Array} buffer |
| 8 | */ |
| 9 | function utf8DecodeBytes (buffer) { |
| 10 | if (buffer.length === 0) { |
| 11 | return '' |
| 12 | } |
| 13 | |
| 14 | // 1. Let buffer be the result of peeking three bytes from |
| 15 | // ioQueue, converted to a byte sequence. |
| 16 | |
| 17 | // 2. If buffer is 0xEF 0xBB 0xBF, then read three |
| 18 | // bytes from ioQueue. (Do nothing with those bytes.) |
| 19 | if (buffer[0] === 0xEF && buffer[1] === 0xBB && buffer[2] === 0xBF) { |
| 20 | buffer = buffer.subarray(3) |
| 21 | } |
| 22 | |
| 23 | // 3. Process a queue with an instance of UTF-8’s |
| 24 | // decoder, ioQueue, output, and "replacement". |
| 25 | const output = textDecoder.decode(buffer) |
| 26 | |
| 27 | // 4. Return output. |
| 28 | return output |
| 29 | } |
| 30 | |
| 31 | module.exports = { |
| 32 | utf8DecodeBytes |
no outgoing calls
no test coverage detected