(boundary)
| 40 | // of the passed `options` (second) param, because when you decide |
| 41 | // to test the plugin you can pass custom `this` context to it (and so `this.options`) |
| 42 | function createInitMultipart(boundary) { |
| 43 | return function initMultipart() { |
| 44 | this.type = multipartType; |
| 45 | |
| 46 | const parser = new MultipartParser(this.options); |
| 47 | let headerField; |
| 48 | let headerValue; |
| 49 | let part; |
| 50 | |
| 51 | parser.initWithBoundary(boundary); |
| 52 | |
| 53 | // eslint-disable-next-line max-statements, consistent-return |
| 54 | parser.on('data', async ({ name, buffer, start, end }) => { |
| 55 | if (name === 'partBegin') { |
| 56 | part = new Stream(); |
| 57 | part.readable = true; |
| 58 | part.headers = {}; |
| 59 | part.name = null; |
| 60 | part.originalFilename = null; |
| 61 | part.mimetype = null; |
| 62 | |
| 63 | part.transferEncoding = this.options.encoding; |
| 64 | part.transferBuffer = ''; |
| 65 | |
| 66 | headerField = ''; |
| 67 | headerValue = ''; |
| 68 | } else if (name === 'headerField') { |
| 69 | headerField += buffer.toString(this.options.encoding, start, end); |
| 70 | } else if (name === 'headerValue') { |
| 71 | headerValue += buffer.toString(this.options.encoding, start, end); |
| 72 | } else if (name === 'headerEnd') { |
| 73 | headerField = headerField.toLowerCase(); |
| 74 | part.headers[headerField] = headerValue; |
| 75 | |
| 76 | // matches either a quoted-string or a token (RFC 2616 section 19.5.1) |
| 77 | const m = headerValue.match( |
| 78 | // eslint-disable-next-line no-useless-escape |
| 79 | /\bname=("([^"]*)"|([^\(\)<>@,;:\\"\/\[\]\?=\{\}\s\t/]+))/i, |
| 80 | ); |
| 81 | if (headerField === 'content-disposition') { |
| 82 | if (m) { |
| 83 | part.name = m[2] || m[3] || ''; |
| 84 | } |
| 85 | |
| 86 | part.originalFilename = this._getFileName(headerValue); |
| 87 | } else if (headerField === 'content-type') { |
| 88 | part.mimetype = headerValue; |
| 89 | } else if (headerField === 'content-transfer-encoding') { |
| 90 | part.transferEncoding = headerValue.toLowerCase(); |
| 91 | } |
| 92 | |
| 93 | headerField = ''; |
| 94 | headerValue = ''; |
| 95 | } else if (name === 'headersEnd') { |
| 96 | switch (part.transferEncoding) { |
| 97 | case 'binary': |
| 98 | case '7bit': |
| 99 | case '8bit': |
no test coverage detected
searching dependent graphs…