lib/json/streamer/json_streamer.rb in json-streamer-1.0.0 vs lib/json/streamer/json_streamer.rb in json-streamer-1.1.0

- old
+ new

@@ -3,12 +3,13 @@ module Json module Streamer class JsonStreamer attr_reader :aggregator + attr_reader :parser - def initialize(file_io, chunk_size = 1000) + def initialize(file_io = nil, chunk_size = 1000) @parser = JSON::Stream::Parser.new @file_io = file_io @chunk_size = chunk_size @@ -62,11 +63,13 @@ end @current_nesting_level -= 1 end - @file_io.each(@chunk_size) do |chunk| - @parser << chunk + if @file_io + @file_io.each(@chunk_size) do |chunk| + @parser << chunk + end end end def yield_object?(yield_nesting_level, wanted_key) @current_nesting_level.eql? yield_nesting_level or (not wanted_key.nil? and wanted_key == @temp_aggregator_keys[@current_nesting_level-1])