blob: 6750f77babc93750e59c6f3a00e8af8cafe704e0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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
}
|