Skip to content

Commit d58a40e

Browse files
perf: move from Buffer to Uint8Array
1 parent 6fb070a commit d58a40e

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

eslint.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import antfu from '@antfu/eslint-config'
22

33
export default await antfu({
44
rules: {
5-
'node/prefer-global/buffer': 'off',
65
'node/prefer-global/process': 'off',
76
},
87
})

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@
5757
"ohash": "^1.1.3",
5858
"pathe": "^1.1.2",
5959
"scule": "^1.3.0",
60-
"ufo": "^1.4.0"
60+
"ufo": "^1.4.0",
61+
"uint8array-extras": "^1.1.0"
6162
},
6263
"devDependencies": {
6364
"@antfu/eslint-config": "^2.8.1",

pnpm-lock.yaml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/runtime/server/handler.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { consola } from 'consola'
22
import { createError, defineEventHandler, getRouterParam, readBody, send, setResponseHeader, setResponseStatus, splitCookiesString } from 'h3'
3+
import { base64ToUint8Array, uint8ArrayToBase64, uint8ArrayToString } from 'uint8array-extras'
34
import type { ModuleOptions } from '../../module'
45
import { createAuthHeader } from '../utils'
56
import type { ServerFetchOptions } from '../types'
@@ -50,8 +51,8 @@ async function fetcher({
5051
})
5152

5253
// Serialize the response data
53-
const buffer = Buffer.from(response._data ?? ([] as unknown as ArrayBuffer))
54-
const data = buffer.toString('base64')
54+
const buffer = new Uint8Array(response._data ?? ([] as unknown as ArrayBuffer))
55+
const data = uint8ArrayToBase64(buffer)
5556

5657
return {
5758
status: response.status,
@@ -97,12 +98,12 @@ export default defineEventHandler(async (event) => {
9798
? await cachedFetcher({ key, ...body })
9899
: await fetcher({ key, ...body })
99100

100-
const buffer = Buffer.from(response.data, 'base64')
101+
const buffer = base64ToUint8Array(response.data)
101102

102103
if (response.status >= 400 && response.status < 600) {
103104
if (isQueryRequest) {
104105
consola.error(`Failed KQL query "${body.query?.query}" (...) with status code ${response.status}:\n`, tryParseJSON(
105-
buffer.toString('utf-8'),
106+
uint8ArrayToString(buffer),
106107
))
107108
if (kql.server.verboseErrors)
108109
consola.log('Full KQL query request:', body.query)

0 commit comments

Comments
 (0)