|
1 | 1 | import {Command, flags} from '@oclif/command' |
2 | | -import * as avro from 'avsc' // includes all from avro-js and some more |
| 2 | +import * as avro from 'avsc' |
| 3 | +import * as chalk from 'chalk' // includes all from avro-js and some more |
3 | 4 |
|
4 | 5 | import Logger from '../utilities/logger' |
5 | 6 | import Utilities from '../utilities/utilities' |
@@ -60,14 +61,21 @@ export default class Avro extends Command { |
60 | 61 |
|
61 | 62 | } |
62 | 63 | private toJson(flags: any, args: any) { |
| 64 | + Utilities.truncateFile(this, flags.output) |
63 | 65 | avro.createFileDecoder(flags.file) |
64 | | - .on('data', function (data) { |
65 | | - return data |
| 66 | + .on('data', function (recordStr) { |
| 67 | + Utilities.appendStringToFile(this, flags.output, JSON.stringify(recordStr, null, '\t')) |
66 | 68 | }) |
67 | | - |
| 69 | + Logger.success(this, `output written to file: ${chalk.green(flags.output)}`) // this will output error and exit command |
68 | 70 | } |
69 | 71 | private toAvro(flags: any, args: any) { |
70 | 72 |
|
71 | 73 | } |
72 | 74 |
|
| 75 | + // private checkValidAvsc(){ |
| 76 | + // // Or we can specify a path to a schema file (not in the browser): |
| 77 | + // var type = avro.parse('./Person.avsc'); |
| 78 | + // var person = {name: 'Bob', address: {city: 'Cambridge', zip: '02139'}}; |
| 79 | + // var status = type.isValid(person); // Boolean status. |
| 80 | + // } |
73 | 81 | } |
0 commit comments