summaryrefslogtreecommitdiffstats
path: root/fastify-busboy/benchmarks/busboy/contestants
diff options
context:
space:
mode:
Diffstat (limited to 'fastify-busboy/benchmarks/busboy/contestants')
-rw-r--r--fastify-busboy/benchmarks/busboy/contestants/busboy.js40
-rw-r--r--fastify-busboy/benchmarks/busboy/contestants/fastify-busboy.js41
2 files changed, 81 insertions, 0 deletions
diff --git a/fastify-busboy/benchmarks/busboy/contestants/busboy.js b/fastify-busboy/benchmarks/busboy/contestants/busboy.js
new file mode 100644
index 0000000..6cb3414
--- /dev/null
+++ b/fastify-busboy/benchmarks/busboy/contestants/busboy.js
@@ -0,0 +1,40 @@
+'use strict'
+
+const Busboy = require('busboy')
+const { buffer, boundary } = require('../data')
+
+function process () {
+ const busboy = Busboy({
+ headers: {
+ 'content-type': 'multipart/form-data; boundary=' + boundary
+ }
+ })
+ let processedData = ''
+
+ return new Promise((resolve, reject) => {
+ busboy.on('file', (field, file, filename, encoding, mimetype) => {
+ // console.log('read file')
+ file.on('data', (data) => {
+ processedData += data.toString()
+ // console.log(`File [${filename}] got ${data.length} bytes`);
+ })
+ file.on('end', (fieldname) => {
+ // console.log(`File [${fieldname}] Finished`);
+ })
+ })
+
+ busboy.on('error', function (err) {
+ reject(err)
+ })
+ busboy.on('finish', function () {
+ resolve(processedData)
+ })
+ busboy.write(buffer, () => { })
+
+ busboy.end()
+ })
+}
+
+module.exports = {
+ process
+}
diff --git a/fastify-busboy/benchmarks/busboy/contestants/fastify-busboy.js b/fastify-busboy/benchmarks/busboy/contestants/fastify-busboy.js
new file mode 100644
index 0000000..6750f77
--- /dev/null
+++ b/fastify-busboy/benchmarks/busboy/contestants/fastify-busboy.js
@@ -0,0 +1,41 @@
+'use strict'
+
+const Busboy = require('../../../lib/main')
+const { buffer, boundary } = require('../data')
+
+function process () {
+ const busboy = new Busboy({
+ headers: {
+ 'content-type': 'multipart/form-data; boundary=' + boundary
+ }
+ })
+
+ let processedData = ''
+
+ return new Promise((resolve, reject) => {
+ busboy.on('file', (field, file, filename, encoding, mimetype) => {
+ // console.log('read file')
+ file.on('data', (data) => {
+ processedData += data.toString()
+ // console.log(`File [${filename}] got ${data.length} bytes`);
+ })
+ file.on('end', (fieldname) => {
+ // console.log(`File [${fieldname}] Finished`);
+ })
+ })
+
+ busboy.on('error', function (err) {
+ reject(err)
+ })
+ busboy.on('finish', function () {
+ resolve(processedData)
+ })
+ busboy.write(buffer, () => { })
+
+ busboy.end()
+ })
+}
+
+module.exports = {
+ process
+}