Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: use @fastify/busboy #2211

Merged
merged 8 commits into from
Sep 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions lib/fetch/body.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const Busboy = require('busboy')
const Busboy = require('@fastify/busboy')
const util = require('../core/util')
const {
ReadableStreamFrom,
Expand Down Expand Up @@ -385,10 +385,9 @@ function bodyMixinMethods (instance) {
let busboy

try {
busboy = Busboy({
busboy = new Busboy({
headers,
preservePath: true,
defParamCharset: 'utf8'
preservePath: true
})
} catch (err) {
throw new DOMException(`${err}`, 'AbortError')
Expand All @@ -397,8 +396,7 @@ function bodyMixinMethods (instance) {
busboy.on('field', (name, value) => {
responseFormData.append(name, value)
})
busboy.on('file', (name, value, info) => {
const { filename, encoding, mimeType } = info
busboy.on('file', (name, value, filename, encoding, mimeType) => {
const chunks = []

if (encoding === 'base64' || encoding.toLowerCase() === 'base64') {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,6 @@
]
},
"dependencies": {
"busboy": "^1.6.0"
"@fastify/busboy": "^2.0.0"
}
}
4 changes: 2 additions & 2 deletions test/node-fetch/utils/server.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const http = require('http')
const zlib = require('zlib')
const { once } = require('events')
const newBusboy = require('busboy')
const Busboy = require('@fastify/busboy')

module.exports = class TestServer {
constructor () {
Expand Down Expand Up @@ -435,7 +435,7 @@ module.exports = class TestServer {
if (p === '/multipart') {
res.statusCode = 200
res.setHeader('Content-Type', 'application/json')
const busboy = newBusboy({ headers: request.headers })
const busboy = new Busboy({ headers: request.headers })
let body = ''
busboy.on('file', async (fieldName, file, fileName) => {
body += `${fieldName}=${fileName}`
Expand Down
10 changes: 5 additions & 5 deletions test/utils/formdata.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const busboy = require('busboy')
const Busboy = require('@fastify/busboy')

function parseFormDataString (
body,
Expand All @@ -9,15 +9,15 @@ function parseFormDataString (
fields: []
}

const bb = busboy({
const bb = new Busboy({
headers: {
'content-type': contentType
}
})

return new Promise((resolve, reject) => {
bb.on('file', (name, file, info) => {
cache.fileMap.set(name, { data: [], info })
bb.on('file', (name, file, filename, encoding, mimeType) => {
cache.fileMap.set(name, { data: [], info: { filename, encoding, mimeType } })

file.on('data', (data) => {
const old = cache.fileMap.get(name)
Expand All @@ -37,7 +37,7 @@ function parseFormDataString (
})

bb.on('field', (key, value) => cache.fields.push({ key, value }))
bb.on('close', () => resolve(cache))
bb.on('finish', () => resolve(cache))
bb.on('error', (e) => reject(e))

bb.end(body)
Expand Down
Loading