@@ -88,78 +88,78 @@ export default class Avro extends Command {
88
88
// tslint:disable-next-line:no-unused
89
89
private toJson ( flags : any , args : any ) {
90
90
Logger . progressStart ( this , 'Converting Avro To Json' )
91
- setTimeout ( ( ) => {
92
- Logger . progressStop ( this , ' Done ' )
93
- Utilities . truncateFile ( this , flags . output )
94
- avro . createFileDecoder ( flags . file )
95
- . on ( 'data' , function ( recordStr ) {
91
+ // setTimeout(() => {
92
+ Logger . progressStop ( this , ' Converting Avro To Json ' )
93
+ Utilities . truncateFile ( this , flags . output )
94
+ avro . createFileDecoder ( flags . file )
95
+ . on ( 'data' , function ( recordStr ) {
96
96
// @ts -ignore
97
- Utilities . appendStringToFile ( this , flags . output , JSON . stringify ( recordStr ) )
98
- } )
99
- Logger . success ( this , `${ chalk . blue ( 'Json' ) } written to file: ${ chalk . green ( flags . output ) } ` ) // this will output error and exit command
100
- } , 1000 )
97
+ Utilities . appendStringToFile ( this , flags . output , JSON . stringify ( recordStr ) )
98
+ } )
99
+ Logger . success ( this , `${ chalk . blue ( 'Json' ) } written to file: ${ chalk . green ( flags . output ) } ` ) // this will output error and exit command
100
+ // }, 1000)
101
101
}
102
102
103
103
// tslint:disable-next-line:no-unused
104
104
private toCsv ( flags : any , args : any ) {
105
105
Logger . progressStart ( this , 'Converting Avro To Csv' )
106
106
107
- setTimeout ( ( ) => {
108
- Logger . progressStop ( this , ' Done ' )
109
- Utilities . truncateFile ( this , flags . output )
110
- let prependHeader = true // only write on the first line
111
- avro . createFileDecoder ( flags . file )
112
- . on ( 'data' , function ( recordStr ) {
107
+ // setTimeout(() => {
108
+ Logger . progressStop ( this , ' Converting Avro To Csv ' )
109
+ Utilities . truncateFile ( this , flags . output )
110
+ let prependHeader = true // only write on the first line
111
+ avro . createFileDecoder ( flags . file )
112
+ . on ( 'data' , function ( recordStr ) {
113
113
// @ts -ignore
114
- let json = JSON . parse ( JSON . stringify ( recordStr ) )
115
- Json2Csv . json2csv ( json , ( err ?: Error , csv ?: string ) => {
116
- if ( csv ) {
114
+ let json = JSON . parse ( JSON . stringify ( recordStr ) )
115
+ Json2Csv . json2csv ( json , ( err ?: Error , csv ?: string ) => {
116
+ if ( csv ) {
117
117
// @ts -ignore
118
- Utilities . appendStringToFile ( this , flags . output , csv + '\n' )
119
- }
120
- if ( err ) {
118
+ Utilities . appendStringToFile ( this , flags . output , csv + '\n' )
119
+ }
120
+ if ( err ) {
121
121
// @ts -ignore
122
- Logger . error ( this , err . toString ( ) )
123
- }
124
- } , { prependHeader} )
125
- prependHeader = false
126
- } )
127
- Logger . success ( this , `${ chalk . blue ( 'Csv' ) } written to file: ${ chalk . green ( flags . output ) } ` ) // this will output error and exit command
128
- } , 1000 )
122
+ Logger . error ( this , err . toString ( ) )
123
+ }
124
+ } , { prependHeader} )
125
+ prependHeader = false
126
+ } )
127
+ Logger . success ( this , `${ chalk . blue ( 'Csv' ) } written to file: ${ chalk . green ( flags . output ) } ` ) // this will output error and exit command
128
+ // }, 300 )
129
129
}
130
130
131
131
private toAvro ( flags : any , args : any ) {
132
132
if ( ! flags . schemaType )
133
133
Logger . error ( this , 'Schema file is not provided' )
134
134
135
135
Logger . progressStart ( this , 'Generating Avro' )
136
- setTimeout ( ( ) => {
137
- Logger . progressStop ( this , ' Done ' )
136
+ // setTimeout(() => {
137
+ Logger . progressStop ( this , ' Generating Avro ' )
138
138
139
- let schema = avro . parse ( flags . schemaType )
140
- let avroEncoder = new avro . streams . BlockEncoder ( schema )
139
+ let schema = avro . parse ( flags . schemaType )
140
+ let avroEncoder = new avro . streams . BlockEncoder ( schema )
141
141
142
- avroEncoder . pipe ( fs . createWriteStream ( flags . output ) )
142
+ avroEncoder . pipe ( fs . createWriteStream ( flags . output ) )
143
143
144
144
// We write the records to the block encoder, which will take care of serializing them
145
145
// into an object container file.
146
146
147
- let inputString = Utilities . getInputString ( this , flags , args )
148
- let jsonStr = this . convertAvroJsonToValidJson ( inputString )
147
+ let inputString = Utilities . getInputString ( this , flags , args )
148
+ let jsonStr = this . convertAvroJsonToValidJson ( inputString )
149
149
150
- let jsonObjects = JSON . parse ( jsonStr )
150
+ let jsonObjects = JSON . parse ( jsonStr )
151
151
152
- jsonObjects . forEach ( function ( data : any ) {
153
- if ( schema . isValid ( data ) ) {
154
- avroEncoder . write ( data )
155
- } else {
152
+ jsonObjects . forEach ( function ( data : any ) {
153
+ if ( schema . isValid ( data ) ) {
154
+ avroEncoder . write ( data )
155
+ } else {
156
156
// @ts -ignore
157
- Logger . warn ( this , `${ chalk . yellow ( '[SKIPPING RECORD]' ) } schema is invalid: ${ chalk . yellowBright ( JSON . stringify ( data ) ) } ` )
158
- }
159
- } )
160
- Logger . success ( this , `${ chalk . blue ( 'Avro' ) } written to file: ${ chalk . green ( flags . output ) } ` ) // this will output error and exit command
161
- avroEncoder . end ( )
162
- } , 1000 )
157
+ Logger . warn ( this , `${ chalk . yellow ( '[SKIPPING RECORD]' ) } schema is invalid: ${ chalk . yellowBright ( JSON . stringify ( data ) ) } ` )
158
+ }
159
+ } )
160
+ Logger . success ( this , `${ chalk . blue ( 'Avro' ) } written to file: ${ chalk . green ( flags . output ) } ` ) // this will output error and exit command
161
+ avroEncoder . end ( )
162
+ // }, 300 )
163
163
164
164
}
165
165
0 commit comments