New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

fastify-multipart

Package Overview
Dependencies
Maintainers
7
Versions
46
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 0.5.0 to 0.5.1

37

index.js

@@ -6,2 +6,3 @@ 'use strict'

const kMultipart = Symbol('multipart')
const eos = require('end-of-stream')

@@ -50,6 +51,13 @@ function setMultipart (req, done) {

const stream = new Busboy(busboyOptions)
var completed = false
var files = 0
var count = 0
var callDoneOnNextEos = false
req.on('error', function (err) {
stream.destroy()
done(err)
if (!completed) {
completed = true
done(err)
}
})

@@ -59,3 +67,8 @@

log.debug('finished multipart parsing')
done()
if (!completed && count === files) {
completed = true
setImmediate(done)
} else {
callDoneOnNextEos = true
}
})

@@ -69,5 +82,25 @@

log.debug({ field, filename, encoding, mimetype }, 'parsing part')
files++
eos(file, waitForFiles)
handler(field, file, filename, encoding, mimetype)
}
function waitForFiles (err) {
if (err) {
completed = true
done(err)
return
}
if (completed) {
return
}
++count
if (callDoneOnNextEos && count === files) {
completed = true
done()
}
}
return stream

@@ -74,0 +107,0 @@ }

15

package.json
{
"name": "fastify-multipart",
"version": "0.5.0",
"version": "0.5.1",
"description": "Multipart plugin for Fastify",

@@ -8,14 +8,15 @@ "main": "index.js",

"busboy": "^0.2.14",
"fastify-plugin": "^0.2.2"
"end-of-stream": "^1.4.1",
"fastify-plugin": "^1.0.0"
},
"devDependencies": {
"climem": "^1.0.3",
"concat-stream": "^1.6.0",
"pump": "^3.0.0",
"fastify": "^1.2.0",
"concat-stream": "^1.6.2",
"fastify": "^1.7.0",
"form-data": "^2.3.2",
"pre-commit": "^1.2.2",
"snazzy": "^7.0.0",
"pump": "^3.0.0",
"snazzy": "^7.1.1",
"standard": "^11.0.0",
"tap": "^11.1.0"
"tap": "^12.0.0"
},

@@ -22,0 +23,0 @@ "scripts": {

'use strict'
const os = require('os')
const test = require('tap').test

@@ -83,2 +83,58 @@ const FormData = require('form-data')

test('should call finished when both files are pumped', function (t) {
t.plan(8)
const fastify = Fastify()
t.tearDown(fastify.close.bind(fastify))
fastify.register(multipart)
fastify.post('/', function (req, reply) {
var fileCount = 0
t.ok(req.isMultipart())
req.multipart(handler, function (err) {
t.error(err)
t.equal(fileCount, 2)
reply.code(200).send()
})
function handler (field, file, filename, encoding, mimetype) {
const saveTo = path.join(os.tmpdir(), path.basename(filename))
pump(file, fs.createWriteStream(saveTo), function (err) {
t.error(err)
fileCount++
})
}
})
fastify.listen(0, function () {
// request
var form = new FormData()
var opts = {
protocol: 'http:',
hostname: 'localhost',
port: fastify.server.address().port,
path: '/',
headers: form.getHeaders(),
method: 'POST'
}
var req = http.request(opts, (res) => {
t.equal(res.statusCode, 200)
res.resume()
res.on('end', () => {
t.pass('res ended successfully')
})
})
form.append('upload', fs.createReadStream(filePath))
form.append('upload2', fs.createReadStream(filePath))
form.append('hello', 'world')
form.append('willbe', 'dropped')
pump(form, req, function (err) {
t.error(err, 'client pump: no err')
})
})
})
test('should error if it is not multipart', function (t) {

@@ -85,0 +141,0 @@ t.plan(4)

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc