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