Skip to content

Commit 0f10e50

Browse files
committed
Fix porsager#22 Use documented node buffer methods
1 parent d0c63f1 commit 0f10e50

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

lib/backend.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ function Backend({
6666
let index = 9
6767
while (x[index++] !== 0);
6868
onnotify(
69-
x.utf8Slice(9, index - 1),
70-
x.utf8Slice(index, x.length - 1)
69+
x.toString('utf8', 9, index - 1),
70+
x.toString('utf8', index, x.length - 1)
7171
)
7272
}
7373

@@ -77,9 +77,9 @@ function Backend({
7777

7878
for (let i = x.length - 1; i > 0; i--) {
7979
if (x[i] === 32 && x[i + 1] < 58 && backend.query.result.count === null)
80-
backend.query.result.count = +x.utf8Slice(i + 1, x.length - 1)
80+
backend.query.result.count = +x.toString('utf8', i + 1, x.length - 1)
8181
if (x[i - 1] >= 65) {
82-
backend.query.result.command = x.utf8Slice(5, i)
82+
backend.query.result.command = x.toString('utf8', 5, i)
8383
break
8484
}
8585
}
@@ -103,10 +103,10 @@ function Backend({
103103
value = length === -1
104104
? null
105105
: column.p === undefined
106-
? x.utf8Slice(index, index += length)
106+
? x.toString('utf8', index, index += length)
107107
: column.p.array === true
108-
? column.p(x.utf8Slice(index + 1, index += length))
109-
: column.p(x.utf8Slice(index, index += length))
108+
? column.p(x.toString('utf8', index + 1, index += length))
109+
: column.p(x.toString('utf8', index, index += length))
110110

111111
row[column.n] = transform.value ? transform.value(value) : value
112112
}
@@ -157,7 +157,7 @@ function Backend({
157157
}
158158

159159
function ParameterStatus(x) {
160-
const [k, v] = x.utf8Slice(5, x.length - 1).split(N)
160+
const [k, v] = x.toString('utf8', 5, x.length - 1).split(N)
161161
onparameter(k, v)
162162
}
163163

@@ -195,8 +195,8 @@ function Backend({
195195
while (x[index++] !== 0);
196196
backend.query.statement.columns[i] = {
197197
n: transform.column
198-
? transform.column(x.utf8Slice(start, index - 1))
199-
: x.utf8Slice(start, index - 1),
198+
? transform.column(x.toString('utf8', start, index - 1))
199+
: x.toString('utf8', start, index - 1),
200200
p: parsers[x.readInt32BE(index + 6)]
201201
}
202202
index += 18
@@ -230,7 +230,7 @@ function parseError(x) {
230230
let start = 5
231231
for (let i = 5; i < x.length - 1; i++) {
232232
if (x[i] === 0) {
233-
error[errorFields[x[start]]] = x.utf8Slice(start + 1, i)
233+
error[errorFields[x[start]]] = x.toString('utf8', start + 1, i)
234234
start = i + 1
235235
}
236236
}

lib/bytes.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const b = {
3737
str(x) {
3838
const length = Buffer.byteLength(x)
3939
fit(length)
40-
b.i += buffer.utf8Write(x, b.i, length)
40+
b.i += buffer.write(x, b.i, length, 'utf8')
4141
return b
4242
},
4343
i16(x) {

lib/frontend.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ function SASL(type, x, options) {
101101
}
102102

103103
function SASLContinue(type, x, options, pass) {
104-
const res = x.utf8Slice(9).split(',').reduce((acc, x) => (acc[x[0]] = x.slice(2), acc), {})
104+
const res = x.toString('utf8', 9).split(',').reduce((acc, x) => (acc[x[0]] = x.slice(2), acc), {})
105105

106106
const saltedPassword = crypto.pbkdf2Sync(
107107
pass,
@@ -124,7 +124,7 @@ function SASLContinue(type, x, options, pass) {
124124
}
125125

126126
function SASLFinal(type, x, options) {
127-
if (x.utf8Slice(9).split(N, 1)[0].slice(2) === options.serverSignature)
127+
if (x.toString('utf8', 9).split(N, 1)[0].slice(2) === options.serverSignature)
128128
return ''
129129
/* c8 ignore next 4 */
130130
throw errors.generic({

0 commit comments

Comments
 (0)