diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-21 20:56:19 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-21 20:56:19 +0000 |
commit | 0b6210cd37b68b94252cb798598b12974a20e1c1 (patch) | |
tree | e371686554a877842d95aa94f100bee552ff2a8e /fastify-busboy/benchmarks/busboy/contestants | |
parent | Initial commit. (diff) | |
download | node-undici-0b6210cd37b68b94252cb798598b12974a20e1c1.tar.xz node-undici-0b6210cd37b68b94252cb798598b12974a20e1c1.zip |
Adding upstream version 5.28.2+dfsg1+~cs23.11.12.3.upstream/5.28.2+dfsg1+_cs23.11.12.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'fastify-busboy/benchmarks/busboy/contestants')
-rw-r--r-- | fastify-busboy/benchmarks/busboy/contestants/busboy.js | 40 | ||||
-rw-r--r-- | fastify-busboy/benchmarks/busboy/contestants/fastify-busboy.js | 41 |
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 +} |