Class: Avro::DataFile::Reader
- Inherits:
-
Object
- Object
- Avro::DataFile::Reader
- Includes:
- Enumerable
- Defined in:
- lib/avro/data_file.rb
Overview
Read files written by DataFileWriter
Instance Attribute Summary collapse
-
#block_count ⇒ Object
records remaining in current block.
-
#block_decoder ⇒ Object
readonly
The binary decoder for the contents of a block (after codec decompression).
-
#codec ⇒ Object
readonly
Returns the value of attribute codec.
-
#datum_reader ⇒ Object
readonly
Returns the value of attribute datum_reader.
-
#decoder ⇒ Object
readonly
The reader and binary decoder for the raw file stream.
-
#file_length ⇒ Object
readonly
Returns the value of attribute file_length.
-
#meta ⇒ Object
readonly
Returns the value of attribute meta.
-
#reader ⇒ Object
readonly
The reader and binary decoder for the raw file stream.
-
#sync_marker ⇒ Object
readonly
Returns the value of attribute sync_marker.
Instance Method Summary collapse
- #close ⇒ Object
-
#each ⇒ Object
Iterates through each datum in this file TODO(jmhodges): handle block of length zero.
- #eof? ⇒ Boolean
-
#initialize(reader, datum_reader) ⇒ Reader
constructor
A new instance of Reader.
Constructor Details
#initialize(reader, datum_reader) ⇒ Reader
Returns a new instance of Reader.
214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/avro/data_file.rb', line 214 def initialize(reader, datum_reader) @reader = reader @decoder = IO::BinaryDecoder.new(reader) @datum_reader = datum_reader # read the header: magic, meta, sync read_header @codec = DataFile.get_codec(['avro.codec']) # get ready to read @block_count = 0 datum_reader.writers_schema = Schema.parse ['avro.schema'] end |
Instance Attribute Details
#block_count ⇒ Object
records remaining in current block
212 213 214 |
# File 'lib/avro/data_file.rb', line 212 def block_count @block_count end |
#block_decoder ⇒ Object (readonly)
The binary decoder for the contents of a block (after codec decompression)
209 210 211 |
# File 'lib/avro/data_file.rb', line 209 def block_decoder @block_decoder end |
#codec ⇒ Object (readonly)
Returns the value of attribute codec.
211 212 213 |
# File 'lib/avro/data_file.rb', line 211 def codec @codec end |
#datum_reader ⇒ Object (readonly)
Returns the value of attribute datum_reader.
211 212 213 |
# File 'lib/avro/data_file.rb', line 211 def datum_reader @datum_reader end |
#decoder ⇒ Object (readonly)
The reader and binary decoder for the raw file stream
206 207 208 |
# File 'lib/avro/data_file.rb', line 206 def decoder @decoder end |
#file_length ⇒ Object (readonly)
Returns the value of attribute file_length.
211 212 213 |
# File 'lib/avro/data_file.rb', line 211 def file_length @file_length end |
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
211 212 213 |
# File 'lib/avro/data_file.rb', line 211 def @meta end |
#reader ⇒ Object (readonly)
The reader and binary decoder for the raw file stream
206 207 208 |
# File 'lib/avro/data_file.rb', line 206 def reader @reader end |
#sync_marker ⇒ Object (readonly)
Returns the value of attribute sync_marker.
211 212 213 |
# File 'lib/avro/data_file.rb', line 211 def sync_marker @sync_marker end |
Instance Method Details
#close ⇒ Object
252 253 254 |
# File 'lib/avro/data_file.rb', line 252 def close reader.close end |
#each ⇒ Object
Iterates through each datum in this file TODO(jmhodges): handle block of length zero
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/avro/data_file.rb', line 231 def each loop do if block_count == 0 case when eof?; break when skip_sync break if eof? read_block_header else read_block_header end end datum = datum_reader.read(block_decoder) self.block_count -= 1 yield(datum) end end |
#eof? ⇒ Boolean
250 |
# File 'lib/avro/data_file.rb', line 250 def eof?; reader.eof?; end |