MCPcopy Create free account
hub / github.com/Effect-TS/effect / decodeUtf8

Function decodeUtf8

packages/sql/pg/src/PgTypes.ts:223–243  ·  view source on GitHub ↗
(bytes: Uint8Array, offset: number, size: number)

Source from the content-addressed store, hash-verified

221 ?.prototype?.utf8Slice
222
223const decodeUtf8 = (bytes: Uint8Array, offset: number, size: number): string => {
224 if (size <= asciiDecodeLimit) {
225 let text = ""
226 let index = 0
227 for (; index < size; index++) {
228 const code = bytes[offset + index]
229 if (code > 0x7f) break
230 text += String.fromCharCode(code)
231 }
232 if (index === size) return text
233 }
234 if (utf8Slice !== undefined) {
235 const text = utf8Slice.call(bytes, offset, offset + size)
236 if (text.indexOf("\ufffd") === -1) return text
237 }
238 try {
239 return textDecoder.decode(region(bytes, offset, size))
240 } catch {
241 return fail("Invalid UTF-8 in text value")
242 }
243}
244
245/**
246 * The UTF-8 fallback for an OID with no codec. PostgreSQL's text output never

Callers 2

decodeUnregisteredFunction · 0.70
PgTypes.tsFile · 0.70

Calls 4

regionFunction · 0.70
failFunction · 0.70
callMethod · 0.45
decodeMethod · 0.45

Tested by

no test coverage detected