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.
215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/avro/data_file.rb', line 215 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
213 214 215 |
# File 'lib/avro/data_file.rb', line 213 def block_count @block_count end |
#block_decoder ⇒ Object (readonly)
The binary decoder for the contents of a block (after codec decompression)
210 211 212 |
# File 'lib/avro/data_file.rb', line 210 def block_decoder @block_decoder end |
#codec ⇒ Object (readonly)
Returns the value of attribute codec.
212 213 214 |
# File 'lib/avro/data_file.rb', line 212 def codec @codec end |
#datum_reader ⇒ Object (readonly)
Returns the value of attribute datum_reader.
212 213 214 |
# File 'lib/avro/data_file.rb', line 212 def datum_reader @datum_reader end |
#decoder ⇒ Object (readonly)
The reader and binary decoder for the raw file stream
207 208 209 |
# File 'lib/avro/data_file.rb', line 207 def decoder @decoder end |
#file_length ⇒ Object (readonly)
Returns the value of attribute file_length.
212 213 214 |
# File 'lib/avro/data_file.rb', line 212 def file_length @file_length end |
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
212 213 214 |
# File 'lib/avro/data_file.rb', line 212 def @meta end |
#reader ⇒ Object (readonly)
The reader and binary decoder for the raw file stream
207 208 209 |
# File 'lib/avro/data_file.rb', line 207 def reader @reader end |
#sync_marker ⇒ Object (readonly)
Returns the value of attribute sync_marker.
212 213 214 |
# File 'lib/avro/data_file.rb', line 212 def sync_marker @sync_marker end |
Instance Method Details
#close ⇒ Object
253 254 255 |
# File 'lib/avro/data_file.rb', line 253 def close reader.close end |
#each ⇒ Object
Iterates through each datum in this file TODO(jmhodges): handle block of length zero
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/avro/data_file.rb', line 232 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
251 |
# File 'lib/avro/data_file.rb', line 251 def eof?; reader.eof?; end |