MCPcopy Create free account
hub / github.com/denodrivers/postgres / decodeByteaEscape

Function decodeByteaEscape

query/decoders.ts:88–116  ·  view source on GitHub ↗
(byteaStr: string)

Source from the content-addressed store, hash-verified

86}
87
88function decodeByteaEscape(byteaStr: string): Uint8Array {
89 const bytes = [];
90 let i = 0;
91 let k = 0;
92 while (i < byteaStr.length) {
93 if (byteaStr[i] !== "\\") {
94 bytes.push(byteaStr.charCodeAt(i));
95 ++i;
96 } else {
97 if (/[0-7]{3}/.test(byteaStr.substring(i + 1, i + 4))) {
98 bytes.push(parseInt(byteaStr.substring(i + 1, i + 4), 8));
99 i += 4;
100 } else {
101 let backslashes = 1;
102 while (
103 i + backslashes < byteaStr.length &&
104 byteaStr[i + backslashes] === "\\"
105 ) {
106 backslashes++;
107 }
108 for (k = 0; k < Math.floor(backslashes / 2); ++k) {
109 bytes.push(BACKSLASH_BYTE_VALUE);
110 }
111 i += Math.floor(backslashes / 2) * 2;
112 }
113 }
114 }
115 return new Uint8Array(bytes);
116}
117
118function decodeByteaHex(byteaStr: string): Uint8Array {
119 const bytesStr = byteaStr.slice(2);

Callers 1

decodeByteaFunction · 0.85

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected