MCPcopy Create free account
hub / github.com/nodejs/undici / utf8DecodeBytes

Function utf8DecodeBytes

lib/encoding/index.js:9–29  ·  view source on GitHub ↗

* @see https://encoding.spec.whatwg.org/#utf-8-decode * @param {Uint8Array} buffer

(buffer)

Source from the content-addressed store, hash-verified

7 * @param {Uint8Array} buffer
8 */
9function 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
31module.exports = {
32 utf8DecodeBytes

Callers 2

parseJSONFromBytesFunction · 0.85
#onSocketCloseMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected