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 52 def self.codecs 53 @codecs 54 end
get_codec(codec)
click to toggle source
# File lib/avro/data_file.rb 62 def self.get_codec(codec) 63 codec ||= 'null' 64 if codec.respond_to?(:compress) && codec.respond_to?(:decompress) 65 codec # it's a codec instance 66 elsif codec.is_a?(Class) 67 codec.new # it's a codec class 68 elsif @codecs.include?(codec.to_s) 69 @codecs[codec.to_s] # it's a string or symbol (codec name) 70 else 71 raise DataFileError, "Unknown codec: #{codec.inspect}" 72 end 73 end
open(file_path, mode='r', schema=nil, codec=nil) { |io| ... }
click to toggle source
# File lib/avro/data_file.rb 32 def self.open(file_path, mode='r', schema=nil, codec=nil) 33 schema = Avro::Schema.parse(schema) if schema 34 case mode 35 when 'w' 36 unless schema 37 raise DataFileError, "Writing an Avro file requires a schema." 38 end 39 io = open_writer(File.open(file_path, 'wb'), schema, codec) 40 when 'r' 41 io = open_reader(File.open(file_path, 'rb'), schema) 42 else 43 raise DataFileError, "Only modes 'r' and 'w' allowed. You gave #{mode.inspect}." 44 end 45 46 yield io if block_given? 47 io 48 ensure 49 io.close if block_given? && io 50 end
register_codec(codec)
click to toggle source
# File lib/avro/data_file.rb 56 def self.register_codec(codec) 57 @codecs ||= {} 58 codec = codec.new if !codec.respond_to?(:codec_name) && codec.is_a?(Class) 59 @codecs[codec.codec_name.to_s] = codec 60 end
Private Class Methods
open_reader(file, schema)
click to toggle source
# File lib/avro/data_file.rb 82 def open_reader(file, schema) 83 reader = Avro::IO::DatumReader.new(nil, schema) 84 Avro::DataFile::Reader.new(file, reader) 85 end
open_writer(file, schema, codec=nil)
click to toggle source
# File lib/avro/data_file.rb 77 def open_writer(file, schema, codec=nil) 78 writer = Avro::IO::DatumWriter.new(schema) 79 Avro::DataFile::Writer.new(file, writer, schema, codec) 80 end