| 1 |
'use strict' |
| 2 |
|
| 3 |
const boundary = '-----------------------------paZqsnEHRufoShdX6fh0lUhXBP4k' |
| 4 |
const randomContent = Buffer.from(makeString(1024 * 500), 'utf8') |
| 5 |
const buffer = createMultipartBuffer(boundary) |
| 6 |
|
| 7 |
function makeString (length) { |
| 8 |
let result = '' |
| 9 |
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' |
| 10 |
const charactersLength = characters.length |
| 11 |
for (var i = 0; i < length; i++) { |
| 12 |
result += characters.charAt(Math.floor(Math.random() * |
| 13 |
charactersLength)) |
| 14 |
} |
| 15 |
return result |
| 16 |
} |
| 17 |
|
| 18 |
function createMultipartBuffer (boundary) { |
| 19 |
const payload = [ |
| 20 |
'--' + boundary, |
| 21 |
'Content-Disposition: form-data; name="upload_file_0"; filename="1k_a.dat"', |
| 22 |
'Content-Type: application/octet-stream', |
| 23 |
'', |
| 24 |
randomContent, |
| 25 |
'--' + boundary + '--' |
| 26 |
].join('\r\n') |
| 27 |
return Buffer.from(payload, 'ascii') |
| 28 |
} |
| 29 |
|
| 30 |
module.exports = { |
| 31 |
boundary, |
| 32 |
buffer, |
| 33 |
randomContent |
| 34 |
} |