Debian Codegraph @

fastify-busboy/benchmarks/busboy/contestants/busboy.js

raw symbols SCIP
1 'use strict'
2
3 const Busboy = require('busboy')
4 const { buffer, boundary } = require('../data')
5
6 function process () {
7 const busboy = Busboy({
8 headers: {
9 'content-type': 'multipart/form-data; boundary=' + boundary
10 }
11 })
12 let processedData = ''
13
14 return new Promise((resolve, reject) => {
15 busboy.on('file', (field, file, filename, encoding, mimetype) => {
16 // console.log('read file')
17 file.on('data', (data) => {
18 processedData += data.toString()
19 // console.log(`File [${filename}] got ${data.length} bytes`);
20 })
21 file.on('end', (fieldname) => {
22 // console.log(`File [${fieldname}] Finished`);
23 })
24 })
25
26 busboy.on('error', function (err) {
27 reject(err)
28 })
29 busboy.on('finish', function () {
30 resolve(processedData)
31 })
32 busboy.write(buffer, () => { })
33
34 busboy.end()
35 })
36 }
37
38 module.exports = {
39 process
40 }