File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ var param = null ;
2+ var dataToCSVLine = require ( "dataToCSVLine" ) ;
3+ process . on ( "message" , function ( msg ) {
4+ var cmd = msg [ 0 ] ;
5+ var data = msg . substr ( 1 ) ;
6+ switch ( cmd ) {
7+ case 0 :
8+ initParams ( data ) ;
9+ break ;
10+ case 1 :
11+ processData ( data ) ;
12+ break ;
13+ default :
14+ console . error ( "Unknown command: " , msg ) ;
15+ }
16+ } ) ;
17+
18+ function initParams ( data ) {
19+ if ( ! param ) {
20+ param = JSON . parse ( data ) ;
21+ }
22+ }
23+
24+ function processData ( data ) {
25+ if ( ! param ) {
26+ console . error ( "Parameter not initialised when processing data." ) ;
27+ process . exit ( 1 ) ;
28+ }
29+ var sepIdx = data . indexOf ( "|" ) ;
30+ var startIdx = parseInt ( data . substr ( 0 , sepIdx ) ) ;
31+ var csvData = data . substr ( sepIdx + 1 ) ;
32+ var lines = dataToCSVLine ( csvData , param ) ;
33+ process . send ( "0" + startIdx + "|" + lines . lines . length + "|" + lines . partial ) ;
34+ }
35+
You can’t perform that action at this time.
0 commit comments