Gathering detailed insights and metrics for @fastify/busboy
Gathering detailed insights and metrics for @fastify/busboy
Gathering detailed insights and metrics for @fastify/busboy
Gathering detailed insights and metrics for @fastify/busboy
fastify-busboy
[![Continuous Integration](https://github.com/climba03003/fastify-busboy/actions/workflows/ci.yml/badge.svg)](https://github.com/climba03003/fastify-busboy/actions/workflows/ci.yml) [![Package Manager CI](https://github.com/climba03003/fastify-busboy/acti
@nerd-coder/fastify-busboy-rx
Fastify Busboy Plugin (RX version)
@xxmichas/bussinboy
A small promise based wrapper for [@fastify/busboy](https://github.com/fastify/busboy) that focuses on ease of use and simplicity.
@fastify/multipart
Multipart plugin for Fastify
A streaming parser for HTML form data for node.js
npm install @fastify/busboy
99.3
Supply Chain
99.6
Quality
84.5
Maintenance
100
Vulnerability
100
License
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
87 Stars
325 Commits
17 Forks
6 Watching
2 Branches
39 Contributors
Updated on 25 Nov 2024
Minified
Minified + Gzipped
JavaScript (92.71%)
TypeScript (7.06%)
Batchfile (0.23%)
Cumulative downloads
Total Downloads
Last day
1.1%
1,636,806
Compared to previous day
Last week
2.8%
8,522,163
Compared to previous week
Last month
8.1%
35,552,999
Compared to previous month
Last year
486.9%
345,609,599
Compared to previous year
9
A Node.js module for parsing incoming HTML form data.
This is an officially supported fork by fastify organization of the amazing library originally created by Brian White, aimed at addressing long-standing issues with it.
Benchmark (Mean time for 500 Kb payload, 2000 cycles, 1000 cycle warmup):
Library | Version | Mean time in nanoseconds (less is better) |
---|---|---|
busboy | 0.3.1 | 340114 |
@fastify/busboy | 1.0.0 | 270984 |
Changelog since busboy 0.31.
npm i @fastify/busboy
1const http = require('node:http'); 2const { inspect } = require('node:util'); 3const Busboy = require('busboy'); 4 5http.createServer((req, res) => { 6 if (req.method === 'POST') { 7 const busboy = new Busboy({ headers: req.headers }); 8 busboy.on('file', (fieldname, file, filename, encoding, mimetype) => { 9 console.log(`File [${fieldname}]: filename: ${filename}, encoding: ${encoding}, mimetype: ${mimetype}`); 10 file.on('data', data => { 11 console.log(`File [${fieldname}] got ${data.length} bytes`); 12 }); 13 file.on('end', () => { 14 console.log(`File [${fieldname}] Finished`); 15 }); 16 }); 17 busboy.on('field', (fieldname, val, fieldnameTruncated, valTruncated, encoding, mimetype) => { 18 console.log(`Field [${fieldname}]: value: ${inspect(val)}`); 19 }); 20 busboy.on('finish', () => { 21 console.log('Done parsing form!'); 22 res.writeHead(303, { Connection: 'close', Location: '/' }); 23 res.end(); 24 }); 25 req.pipe(busboy); 26 } else if (req.method === 'GET') { 27 res.writeHead(200, { Connection: 'close' }); 28 res.end(`<html><head></head><body> 29 <form method="POST" enctype="multipart/form-data"> 30 <input type="text" name="textfield"><br> 31 <input type="file" name="filefield"><br> 32 <input type="submit"> 33 </form> 34 </body></html>`); 35 } 36}).listen(8000, () => { 37 console.log('Listening for requests'); 38}); 39 40// Example output, using http://nodejs.org/images/ryan-speaker.jpg as the file: 41// 42// Listening for requests 43// File [filefield]: filename: ryan-speaker.jpg, encoding: binary 44// File [filefield] got 11971 bytes 45// Field [textfield]: value: 'testing! :-)' 46// File [filefield] Finished 47// Done parsing form!
1const http = require('node:http'); 2const path = require('node:path'); 3const os = require('node:os'); 4const fs = require('node:fs'); 5 6const Busboy = require('busboy'); 7 8http.createServer(function(req, res) { 9 if (req.method === 'POST') { 10 const busboy = new Busboy({ headers: req.headers }); 11 busboy.on('file', function(fieldname, file, filename, encoding, mimetype) { 12 var saveTo = path.join(os.tmpdir(), path.basename(fieldname)); 13 file.pipe(fs.createWriteStream(saveTo)); 14 }); 15 busboy.on('finish', function() { 16 res.writeHead(200, { 'Connection': 'close' }); 17 res.end("That's all folks!"); 18 }); 19 return req.pipe(busboy); 20 } 21 res.writeHead(404); 22 res.end(); 23}).listen(8000, function() { 24 console.log('Listening for requests'); 25});
1const http = require('node:http'); 2const { inspect } = require('node:util'); 3 4const Busboy = require('busboy'); 5 6http.createServer(function(req, res) { 7 if (req.method === 'POST') { 8 const busboy = new Busboy({ headers: req.headers }); 9 busboy.on('file', function(fieldname, file, filename, encoding, mimetype) { 10 console.log('File [' + fieldname + ']: filename: ' + filename); 11 file.on('data', function(data) { 12 console.log('File [' + fieldname + '] got ' + data.length + ' bytes'); 13 }); 14 file.on('end', function() { 15 console.log('File [' + fieldname + '] Finished'); 16 }); 17 }); 18 busboy.on('field', function(fieldname, val, fieldnameTruncated, valTruncated) { 19 console.log('Field [' + fieldname + ']: value: ' + inspect(val)); 20 }); 21 busboy.on('finish', function() { 22 console.log('Done parsing form!'); 23 res.writeHead(303, { Connection: 'close', Location: '/' }); 24 res.end(); 25 }); 26 req.pipe(busboy); 27 } else if (req.method === 'GET') { 28 res.writeHead(200, { Connection: 'close' }); 29 res.end('<html><head></head><body>\ 30 <form method="POST">\ 31 <input type="text" name="textfield"><br />\ 32 <select name="selectfield">\ 33 <option value="1">1</option>\ 34 <option value="10">10</option>\ 35 <option value="100">100</option>\ 36 <option value="9001">9001</option>\ 37 </select><br />\ 38 <input type="checkbox" name="checkfield">Node.js rules!<br />\ 39 <input type="submit">\ 40 </form>\ 41 </body></html>'); 42 } 43}).listen(8000, function() { 44 console.log('Listening for requests'); 45}); 46 47// Example output: 48// 49// Listening for requests 50// Field [textfield]: value: 'testing! :-)' 51// Field [selectfield]: value: '9001' 52// Field [checkfield]: value: 'on' 53// Done parsing form!
Busboy is a Writable stream
file(< string >fieldname, < ReadableStream >stream, < string >filename, < string >transferEncoding, < string >mimeType) - Emitted for each new file form field found. transferEncoding
contains the 'Content-Transfer-Encoding' value for the file stream. mimeType
contains the 'Content-Type' value for the file stream.
stream
no matter if you care about the file contents or not (e.g. you can simply just do stream.resume();
if you want to discard the contents), otherwise the 'finish' event will never fire on the Busboy instance. However, if you don't care about any incoming files, you can simply not listen for the 'file' event at all and any/all files will be automatically and safely discarded (these discarded files do still count towards files
and parts
limits).stream
will both have a boolean property truncated
(best checked at the end of the stream) and emit a 'limit' event to notify you when this happens.bytesRead
informs about the number of bytes that have been read so far.field(< string >fieldname, < string >value, < boolean >fieldnameTruncated, < boolean >valueTruncated, < string >transferEncoding, < string >mimeType) - Emitted for each new non-file field found.
partsLimit() - Emitted when specified parts
limit has been reached. No more 'file' or 'field' events will be emitted.
filesLimit() - Emitted when specified files
limit has been reached. No more 'file' events will be emitted.
fieldsLimit() - Emitted when specified fields
limit has been reached. No more 'field' events will be emitted.
(constructor)(< object >config) - Creates and returns a new Busboy instance.
The constructor takes the following valid config
settings:
headers - object - These are the HTTP headers of the incoming request, which are used by individual parsers.
autoDestroy - boolean - Whether this stream should automatically call .destroy() on itself after ending. (Default: false).
highWaterMark - integer - highWaterMark to use for this Busboy instance (Default: WritableStream default).
fileHwm - integer - highWaterMark to use for file streams (Default: ReadableStream default).
defCharset - string - Default character set to use when one isn't defined (Default: 'utf8').
preservePath - boolean - If paths in the multipart 'filename' field shall be preserved. (Default: false).
isPartAFile - function - Use this function to override the default file detection functionality. It has following parameters:
fieldName - string The name of the field.
contentType - string The content-type of the part, e.g. text/plain
, image/jpeg
, application/octet-stream
fileName - string The name of a file supplied by the part.
(Default: (fieldName, contentType, fileName) => (contentType === 'application/octet-stream' || fileName !== undefined)
)
limits - object - Various limits on incoming data. Valid properties are:
fieldNameSize - integer - Max field name size (in bytes) (Default: 100 bytes).
fieldSize - integer - Max field value size (in bytes) (Default: 1 MiB, which is 1024 x 1024 bytes).
fields - integer - Max number of non-file fields (Default: Infinity).
fileSize - integer - For multipart forms, the max file size (in bytes) (Default: Infinity).
files - integer - For multipart forms, the max number of file fields (Default: Infinity).
parts - integer - For multipart forms, the max number of parts (fields + files) (Default: Infinity).
headerPairs - integer - For multipart forms, the max number of header key=>value pairs to parse Default: 2000
headerSize - integer - For multipart forms, the max size of a multipart header Default: 81920.
The constructor can throw errors:
Busboy expected an options-Object. - Busboy expected an Object as first parameters.
Busboy expected an options-Object with headers-attribute. - The first parameter is lacking of a headers-attribute.
Limit $limit is not a valid number - Busboy expected the desired limit to be of type number. Busboy throws this Error to prevent a potential security issue by falling silently back to the Busboy-defaults. Potential source for this Error can be the direct use of environment variables without transforming them to the type number.
Unsupported Content-Type. - The Content-Type
isn't one Busboy can parse.
Missing Content-Type-header. - The provided headers don't include Content-Type
at all.
No vulnerabilities found.
No security vulnerabilities found.