You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							42 lines
						
					
					
						
							1.1 KiB
						
					
					
				
			
		
		
	
	
							42 lines
						
					
					
						
							1.1 KiB
						
					
					
				| /**
 | |
|  * Convert input to process stdout
 | |
|  */
 | |
| 
 | |
| //implementation
 | |
| var Converter = require("../../core/Converter.js");
 | |
| function _initConverter(){
 | |
|     var csvConverter = new Converter();
 | |
|     var started = false;
 | |
|     var writeStream = process.stdout;
 | |
|     csvConverter.on("record_parsed",function(rowJSON){
 | |
|         if (started){
 | |
|             writeStream.write(",\n");
 | |
|         }
 | |
|         writeStream.write(JSON.stringify(rowJSON));  //write parsed JSON object one by one.
 | |
|         if (started === false){
 | |
|             started = true;
 | |
|         }
 | |
|     });
 | |
|     writeStream.write("[\n"); //write array symbol
 | |
| 
 | |
|     csvConverter.on("end_parsed",function(){
 | |
|         writeStream.write("\n]"); //end array symbol
 | |
|     });
 | |
|     csvConverter.on("error",function(err){
 | |
|         console.error(err);
 | |
|         process.exit(-1);
 | |
|     });
 | |
|     return csvConverter;
 | |
| }
 | |
| function convertFile(fileName){
 | |
|     var csvConverter=_initConverter();
 | |
|     csvConverter.from(fileName);
 | |
| }
 | |
| 
 | |
| function convertString(csvString){
 | |
|     var csvConverter=_initConverter();
 | |
|     csvConverter.from(csvString);
 | |
| }
 | |
| //module interfaces
 | |
| module.exports.convertFile = convertFile;
 | |
| module.exports.convertString = convertString; |