module Avro::DataFile
Constants
- MAGIC
- MAGIC_SIZE
- META_SCHEMA
- SYNC_INTERVAL
- SYNC_SIZE
- VALID_CODECS
TODO this constant won’t be updated if you register another codec. Deprecated in favor of
Avro::DataFile::codecs
- VALID_ENCODINGS
- VERSION
Public Class Methods
codecs()
click to toggle source
# File lib/avro/data_file.rb 53 def self.codecs 54 @codecs 55 end
get_codec(codec)
click to toggle source
# File lib/avro/data_file.rb 63 def self.get_codec(codec) 64 codec ||= 'null' 65 if codec.respond_to?(:compress) && codec.respond_to?(:decompress) 66 codec # it's a codec instance 67 elsif codec.is_a?(Class) 68 codec.new # it's a codec class 69 elsif @codecs.include?(codec.to_s) 70 @codecs[codec.to_s] # it's a string or symbol (codec name) 71 else 72 raise DataFileError, "Unknown codec: #{codec.inspect}" 73 end 74 end
open(file_path, mode='r', schema=nil, codec=nil) { |io| ... }
click to toggle source
# File lib/avro/data_file.rb 33 def self.open(file_path, mode='r', schema=nil, codec=nil) 34 schema = Avro::Schema.parse(schema) if schema 35 case mode 36 when 'w' 37 unless schema 38 raise DataFileError, "Writing an Avro file requires a schema." 39 end 40 io = open_writer(File.open(file_path, 'wb'), schema, codec) 41 when 'r' 42 io = open_reader(File.open(file_path, 'rb'), schema) 43 else 44 raise DataFileError, "Only modes 'r' and 'w' allowed. You gave #{mode.inspect}." 45 end 46 47 yield io if block_given? 48 io 49 ensure 50 io.close if block_given? && io 51 end
register_codec(codec)
click to toggle source
# File lib/avro/data_file.rb 57 def self.register_codec(codec) 58 @codecs ||= {} 59 codec = codec.new if !codec.respond_to?(:codec_name) && codec.is_a?(Class) 60 @codecs[codec.codec_name.to_s] = codec 61 end
Private Class Methods
open_reader(file, schema)
click to toggle source
# File lib/avro/data_file.rb 83 def open_reader(file, schema) 84 reader = Avro::IO::DatumReader.new(nil, schema) 85 Avro::DataFile::Reader.new(file, reader) 86 end
open_writer(file, schema, codec=nil)
click to toggle source
# File lib/avro/data_file.rb 78 def open_writer(file, schema, codec=nil) 79 writer = Avro::IO::DatumWriter.new(schema) 80 Avro::DataFile::Writer.new(file, writer, schema, codec) 81 end