| 210 | }, |
| 211 | |
| 212 | flush(controller) { |
| 213 | // Handle any remaining content in buffer |
| 214 | buffer += decoder.decode(); |
| 215 | |
| 216 | // Trailing \r at end of stream is a line ending |
| 217 | if (buffer[buffer.length - 1] === "\r") { |
| 218 | buffer = buffer.slice(0, -1); |
| 219 | if (parseLine(buffer, message, ignoreComments)) { |
| 220 | hasFields = true; |
| 221 | } |
| 222 | // The \r was a line ending, so dispatch if we have fields |
| 223 | if (hasFields) { |
| 224 | controller.enqueue(message); |
| 225 | return; |
| 226 | } |
| 227 | } else if (buffer) { |
| 228 | if (parseLine(buffer, message, ignoreComments)) { |
| 229 | hasFields = true; |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | // Dispatch final message if non-empty |
| 234 | if (hasFields) { |
| 235 | controller.enqueue(message); |
| 236 | } |
| 237 | }, |
| 238 | }); |
| 239 | } |
| 240 | } |