(csv: string, finalChunk: boolean)
| 73 | }) |
| 74 | } |
| 75 | private processCSV(csv: string, finalChunk: boolean): Promise<ProcessLineResult[]> { |
| 76 | const params = this.params; |
| 77 | const runtime = this.runtime; |
| 78 | if (!runtime.eol) { |
| 79 | getEol(csv, runtime); |
| 80 | } |
| 81 | if (this.needEmitEol && !this.eolEmitted && runtime.eol) { |
| 82 | this.converter.emit("eol", runtime.eol); |
| 83 | this.eolEmitted = true; |
| 84 | } |
| 85 | // trim csv file has initial blank lines. |
| 86 | if (params.ignoreEmpty && !runtime.started) { |
| 87 | csv = trimLeft(csv); |
| 88 | } |
| 89 | const stringToLineResult = stringToLines(csv, runtime); |
| 90 | if (!finalChunk) { |
| 91 | this.prependLeftBuf(bufFromString(stringToLineResult.partial)); |
| 92 | } else { |
| 93 | stringToLineResult.lines.push(stringToLineResult.partial); |
| 94 | stringToLineResult.partial = ""; |
| 95 | } |
| 96 | if (stringToLineResult.lines.length > 0) { |
| 97 | let prom: Promise<string[]>; |
| 98 | if (runtime.preFileLineHook) { |
| 99 | prom = this.runPreLineHook(stringToLineResult.lines); |
| 100 | } else { |
| 101 | prom = Promise.resolve(stringToLineResult.lines); |
| 102 | } |
| 103 | return prom.then((lines) => { |
| 104 | if (!runtime.started |
| 105 | && !this.runtime.headers |
| 106 | ) { |
| 107 | return this.processDataWithHead(lines); |
| 108 | } else { |
| 109 | return this.processCSVBody(lines); |
| 110 | } |
| 111 | |
| 112 | }) |
| 113 | |
| 114 | } else { |
| 115 | |
| 116 | return Promise.resolve([]); |
| 117 | } |
| 118 | |
| 119 | } |
| 120 | private processDataWithHead(lines: string[]): ProcessLineResult[] { |
| 121 | if (this.params.noheader) { |
| 122 | if (this.params.headers) { |
no test coverage detected