avro2json 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +17 -0
  3. data/avro2json.gemspec +1 -1
  4. data/bin/avro2json +32 -5
  5. metadata +2 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6670630fee93dbe8c61a54150c502bcd774961e3
4
- data.tar.gz: 4f9252353eb70dcf467b7618852ccb2df4890172
3
+ metadata.gz: df05647076cef6b928dc3123f326fd04239ead17
4
+ data.tar.gz: f7a4d9c0da6101f7f220069562722aff245b06f3
5
5
  SHA512:
6
- metadata.gz: 4c8439080cf5aa9e96bf7a1fe0aa5a060afad1d2a1a9ec78fb084172e997cac21b73546b290d1b8f696dbf21ab1dcfa05667019a297307e91f435a3bdddfddeb
7
- data.tar.gz: 82ce1fa3f603743e793bce6be62926664070aca88fa260dfeeb52a41281256d2182fdbd9a4d774140c99b6fcbff43b7a726182de16496085fe334cbe93f71de8
6
+ metadata.gz: 0a152f2b0844ba3a4800a0834ba3d41b806f065c439e3d6a07077780bfb3a49145b463bd3e9a03fccbafde87ff24ac751a828d4c8284c6f0bccab71a377140df
7
+ data.tar.gz: f341ff83748fb27a54ee89a1ab7bb6490ea21c254bd75cb1fae5e156c6e9efb73459f97c56efb8815425bf44fe3637c07eb2534406415764d2f2eb6910dac82f
@@ -0,0 +1,17 @@
1
+ # avro2json
2
+
3
+ Converts Avro-encoded data to JSON.
4
+
5
+ ```
6
+ curl http://example.com/data.avro | avro2json
7
+ cat somefile.avro | avro2json
8
+ avro2json < somefile.avro
9
+ ```
10
+
11
+ It's possible to use a custom schema when reading the Avro data:
12
+
13
+ ```
14
+ avro2json --schema=some-schema.avsc < data.avro
15
+ ```
16
+
17
+ Run `avro2json -h` for more information.
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "avro2json"
5
- spec.version = "0.0.1"
5
+ spec.version = "0.1.0"
6
6
  spec.authors = ["Daniel Schierbeck"]
7
7
  spec.email = ["dasch@zendesk.com"]
8
8
  spec.summary = "Decodes Avro data files and converts the data to JSON"
@@ -3,12 +3,39 @@
3
3
  require 'rubygems'
4
4
  require 'avro'
5
5
  require 'json'
6
+ require 'optparse'
6
7
 
7
- # Buffer the input in order to allow seeking -- otherwise Avro blows up.
8
- io = StringIO.new($stdin.read)
8
+ def load_records(input, options)
9
+ schema_path = options[:schema_path]
10
+ schema = schema_path && Avro::Schema.parse(File.read(schema_path))
11
+ Avro::DataFile::Reader.new(input, Avro::IO::DatumReader.new(nil, schema))
12
+ end
13
+
14
+ def main
15
+ options = {}
16
+
17
+ option_parser = OptionParser.new do |opts|
18
+ opts.banner = "Usage: avro2json [options]"
19
+
20
+ opts.on("-sSCHEMA", "--schema=SCHEMA", "Use the specified schema file when decoding") do |schema|
21
+ options[:schema_path] = schema
22
+ end
9
23
 
10
- reader = Avro::DataFile::Reader.new(io, Avro::IO::DatumReader.new)
24
+ opts.on("-h", "--help", "Prints this help") do
25
+ puts opts
26
+ exit
27
+ end
28
+ end
11
29
 
12
- reader.each do |record|
13
- puts JSON.pretty_generate(record)
30
+ option_parser.parse!
31
+
32
+ # Buffer the input in order to allow seeking -- otherwise Avro blows up.
33
+ input = StringIO.new($stdin.read)
34
+ records = load_records(input, options)
35
+
36
+ records.each do |record|
37
+ puts JSON.pretty_generate(record)
38
+ end
14
39
  end
40
+
41
+ main
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: avro2json
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Schierbeck
@@ -63,6 +63,7 @@ files:
63
63
  - ".gitignore"
64
64
  - Gemfile
65
65
  - LICENSE.txt
66
+ - README.md
66
67
  - Rakefile
67
68
  - avro2json.gemspec
68
69
  - bin/avro2json