(original_options = {})
| 27 | }; |
| 28 | |
| 29 | const transform = function (original_options = {}) { |
| 30 | const info = { |
| 31 | bytes: 0, |
| 32 | bytes_records: 0, |
| 33 | comment_lines: 0, |
| 34 | empty_lines: 0, |
| 35 | invalid_field_length: 0, |
| 36 | lines: 1, |
| 37 | records: 0, |
| 38 | }; |
| 39 | const options = normalize_options(original_options); |
| 40 | return { |
| 41 | info: info, |
| 42 | original_options: original_options, |
| 43 | options: options, |
| 44 | state: init_state(options), |
| 45 | __needMoreData: function (i, bufLen, end) { |
| 46 | if (end) return false; |
| 47 | const { encoding, escape, quote } = this.options; |
| 48 | const { quoting, needMoreDataSize, recordDelimiterMaxLength } = |
| 49 | this.state; |
| 50 | const numOfCharLeft = bufLen - i - 1; |
| 51 | const requiredLength = Math.max( |
| 52 | needMoreDataSize, |
| 53 | // Skip if the remaining buffer smaller than record delimiter |
| 54 | // If "record_delimiter" is yet to be discovered: |
| 55 | // 1. It is equals to `[]` and "recordDelimiterMaxLength" equals `0` |
| 56 | // 2. We set the length to windows line ending in the current encoding |
| 57 | // Note, that encoding is known from user or bom discovery at that point |
| 58 | // recordDelimiterMaxLength, |
| 59 | recordDelimiterMaxLength === 0 |
| 60 | ? Buffer.from("\r\n", encoding).length |
| 61 | : recordDelimiterMaxLength, |
| 62 | // Skip if remaining buffer can be an escaped quote |
| 63 | quoting ? (escape === null ? 0 : escape.length) + quote.length : 0, |
| 64 | // Skip if remaining buffer can be record delimiter following the closing quote |
| 65 | quoting ? quote.length + recordDelimiterMaxLength : 0, |
| 66 | ); |
| 67 | return numOfCharLeft < requiredLength; |
| 68 | }, |
| 69 | // Central parser implementation |
| 70 | parse: function (nextBuf, end, push, close) { |
| 71 | const { |
| 72 | bom, |
| 73 | comment_no_infix, |
| 74 | delimiter_auto, |
| 75 | encoding, |
| 76 | from_line, |
| 77 | ltrim, |
| 78 | max_record_size, |
| 79 | raw, |
| 80 | relax_quotes, |
| 81 | rtrim, |
| 82 | skip_empty_lines, |
| 83 | to, |
| 84 | to_line, |
| 85 | } = this.options; |
| 86 | let { comment, escape, quote, record_delimiter } = this.options; |
no test coverage detected