@@ -105,6 +105,7 @@ Converter.prototype._transform = function (data, encoding, cb) {
105105 * The code below is to check if a single utf8 char (which could be multiple bytes) being split.
106106 * If the char being split, the buffer from two chunk needs to be concat
107107 * check how utf8 being encoded to understand the code below.
108+ * If anyone has any better way to do this, please let me know.
108109 */
109110 if ( ( data [ idx ] & 1 << 7 ) != 0 ) {
110111 while ( ( data [ idx ] & 3 << 6 ) === 128 ) {
@@ -307,6 +308,9 @@ Converter.prototype.processHead = function (fileLine, cb) {
307308 }
308309 configIgnoreIncludeColumns ( params ) ;
309310 params . _headers = require ( "./filterRow" ) ( params . _headers , params ) ;
311+ if ( this . _needEmitHeader && this . param . _headers ) {
312+ this . emit ( "header" , this . param . _headers ) ;
313+ }
310314 var lines = fileLineToCSVLine ( fileLine , params ) ;
311315 this . setPartialData ( lines . partial ) ;
312316 if ( this . param . workerNum > 1 ) {
@@ -386,9 +390,6 @@ Converter.prototype.emitResult = function (r) {
386390 this . transform ( resultJson , row , index ) ;
387391 resultStr = null ;
388392 }
389- if ( this . _needEmitHeader && this . param . _headers && index === 0 ) {
390- this . emit ( "header" , this . param . _headers ) ;
391- }
392393 if ( this . _needEmitJson ) {
393394 this . emit ( "json" , resultJson , index ) ;
394395 }
0 commit comments