
Security News
Socket Releases Free Certified Patches for Critical vm2 Sandbox Escape
A critical vm2 sandbox escape can allow untrusted JavaScript to break isolation and execute commands on the host Node.js process.
multiparser
Advanced tools
__ __ __
.--------.--.--.| | |_|__|.-----.---.-.----.-----.-----.----.
| | | || | _| || _ | _ | _|__ --| -__| _|
|__|__|__|_____||__|____|__|| __|___._|__| |_____|_____|__|
|__|
A streams2 compatible multipart-form parser. Hacked from formidable.
Formidable currently doesn't work with node >= 9.4. Also a good excuse to learn streams2.
The module exports a class Multiparser which inherits from Stream.Writable. Http request streams can be piped to instances which will emit 'part' events (essentially instances of Stream.PassThrough) that can then be piped around as needed (to file, s3, etc). Backpressure from parts' destinations are magically transmitted back to the Multiparser's source.
npm install multiparser
The code below is pretty much straight from example/http.js
var fs = require('fs')
var Multiparser = require('multiparser')
var http = require("http")
var updir = '/tmp/'
http.createServer(function (req, res) {
if (req.url === '/upload' && req.method === 'POST') {
var error = null
var progress = 0
var parser = new Multiparser(req)
parser.on('error', function (err) {
error = err
})
parser.on('progress', function (parsed, total) {
var currentProgress = ~~(parsed / total * 100)
if (currentProgress != progress) {
console.log('uploading...', currentProgress, req._readableState.length)
progress = currentProgress
}
})
parser.on('part', function (part) {
part.on('end', function () {
if (part.filename) {
console.log('uploaded file "' + part.name + '" to ' + updir + part.filename)
} else if (part.value) {
console.log('parsed field "' + part.name + '" as "' + part.value + '"')
}
})
if (part.filename) {
var file = fs.createWriteStream(updir + part.filename)
part.pipe(file)
} else {
part.value = ''
part.on('readable', function () {
part.value += part.read()
})
part.read(0)
}
})
parser.on('end', function () {
if (error) {
res.writeHeaders(500)
return res.end(err.message)
} else {
res.end('all parsed!')
}
})
} else {
res.end('<html>\
<form enctype="multipart/form-data" method="POST" action="/upload">\
<input name="fieldup" type="text" /><br>\
<input name="fileup" type="file" multiple="true" /><br>\
<input type="submit" value="upload" />\
</form>\
</html>')
}
}).listen(8080)
MIT
FAQs
a streams2 compatible multipart-form parser
We found that multiparser demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
A critical vm2 sandbox escape can allow untrusted JavaScript to break isolation and execute commands on the host Node.js process.

Research
Five malicious NuGet packages impersonate Chinese .NET libraries to deploy a stealer targeting browser credentials, crypto wallets, SSH keys, and local files.

Security News
pnpm 11 turns on a 1-day Minimum Release Age and blocks exotic subdeps by default, adding safeguards against fast-moving supply chain attacks.