You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

@fastify/multipart

Package Overview
Dependencies
Maintainers
19
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fastify/multipart - npm Package Compare versions

Comparing version
8.3.0
to
8.3.1
+3
-2
index.js

@@ -455,9 +455,10 @@ 'use strict'

this.tmpUploads = []
let i = 0
for await (const file of files) {
const filepath = path.join(tmpdir, generateId() + path.extname(file.filename))
const filepath = path.join(tmpdir, generateId() + path.extname(file.filename || ('file' + i++)))
const target = createWriteStream(filepath)
try {
this.tmpUploads.push(filepath)
await pump(file.file, target)
this.savedRequestFiles.push({ ...file, filepath })
this.tmpUploads.push(filepath)
} catch (err) {

@@ -464,0 +465,0 @@ this.log.error({ err }, 'save request file')

+6
-6
{
"name": "@fastify/multipart",
"version": "8.3.0",
"version": "8.3.1",
"description": "Multipart plugin for Fastify",

@@ -9,5 +9,5 @@ "main": "index.js",

"dependencies": {
"@fastify/busboy": "^2.1.0",
"@fastify/deepmerge": "^1.0.0",
"@fastify/error": "^3.0.0",
"@fastify/busboy": "^3.0.0",
"@fastify/deepmerge": "^2.0.0",
"@fastify/error": "^4.0.0",
"fastify-plugin": "^4.0.0",

@@ -20,3 +20,3 @@ "secure-json-parse": "^2.4.0",

"@fastify/swagger": "^8.10.1",
"@fastify/swagger-ui": "^3.0.0",
"@fastify/swagger-ui": "^4.0.0",
"@types/node": "^20.1.0",

@@ -69,2 +69,2 @@ "@typescript-eslint/eslint-plugin": "^7.1.0",

}
}
}

@@ -46,4 +46,4 @@ 'use strict'

const memory = process.memoryUsage()
t.ok(memory.rss < 400 * 1024 * 1024) // 200MB
t.ok(memory.heapTotal < 400 * 1024 * 1024) // 200MB
t.ok(memory.rss < 500 * 1024 * 1024)
t.ok(memory.heapTotal < 500 * 1024 * 1024)

@@ -50,0 +50,0 @@ reply.send()

'use strict'
const util = require('node:util')
const test = require('tap').test

@@ -9,2 +8,3 @@ const FormData = require('form-data')

const http = require('node:http')
const util = require('node:util')
const sleep = util.promisify(setTimeout)

@@ -14,4 +14,6 @@ const { writableNoopStream } = require('noop-stream')

const pipeline = util.promisify(stream.pipeline)
const { once } = require('node:events')
const fs = require('node:fs/promises')
test('should finish with error on partial upload', async function (t) {
test('should finish with error on partial upload - files api', async function (t) {
t.plan(4)

@@ -65,1 +67,48 @@

})
test('should finish with error on partial upload - saveRequestFiles', async function (t) {
t.plan(3)
const fastify = Fastify()
t.teardown(fastify.close.bind(fastify))
await fastify.register(multipart)
let tmpUploads
fastify.post('/', async function (req) {
t.ok(req.isMultipart())
try {
await req.saveRequestFiles()
} finally {
tmpUploads = req.tmpUploads
}
})
await fastify.listen({ port: 0 })
const dataSize = 1024 * 1024 * 1024
// request
const form = new FormData()
form.append('upload', Buffer.alloc(dataSize))
const opts = {
protocol: 'http:',
hostname: 'localhost',
port: fastify.server.address().port,
path: '/',
headers: form.getHeaders(),
method: 'POST'
}
const req = http.request(opts)
const data = form.getBuffer()
req.write(data.slice(0, dataSize / 4))
req.write(data.slice(dataSize / 4, dataSize / 2))
req.end()
const [res] = await once(req, 'response')
t.equal(res.statusCode, 500)
for (const tmpUpload of tmpUploads) {
await t.rejects(fs.access(tmpUpload))
}
})