MCPcopy Index your code
hub / github.com/nodejs/node / decoder

Function decoder

lib/internal/encoding/single-byte.js:118–145  ·  view source on GitHub ↗
(buf)

Source from the content-addressed store, hash-verified

116
117 // Expects type-checked Buffer input
118 const decoder = (buf) => {
119 if (buf.byteLength === 0) return '';
120 if (isAscii(buf)) return buf.latin1Slice(); // .latin1Slice is faster than .asciiSlice
121 const o = new Uint16Array(buf.length);
122 TypedArrayPrototypeSet(o, buf); // Copy to modify in-place, also those are 16-bit now
123
124 let i = 0;
125 for (const end7 = o.length - 7; i < end7; i += 8) {
126 o[i] = map[o[i]];
127 o[i + 1] = map[o[i + 1]];
128 o[i + 2] = map[o[i + 2]];
129 o[i + 3] = map[o[i + 3]];
130 o[i + 4] = map[o[i + 4]];
131 o[i + 5] = map[o[i + 5]];
132 o[i + 6] = map[o[i + 6]];
133 o[i + 7] = map[o[i + 7]];
134 }
135
136 for (const end = o.length; i < end; i++) o[i] = map[o[i]];
137
138 const b = new FastBuffer(o.buffer, o.byteOffset, o.byteLength);
139 if (isBigEndian) b.swap16();
140 const string = b.ucs2Slice();
141 if (fatal && incomplete && StringPrototypeIncludes(string, '\uFFFD')) {
142 throw new ERR_ENCODING_INVALID_ENCODED_DATA(encoding, undefined);
143 }
144 return string;
145 };
146
147 decoders.set(id, decoder);
148 return decoder;

Callers 2

decodeStrFunction · 0.85
showNodesFunction · 0.85

Calls 4

isAsciiFunction · 0.85
latin1SliceMethod · 0.80
swap16Method · 0.80
ucs2SliceMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…