lib/avro/data_file.rb in avro-1.7.6 vs lib/avro/data_file.rb in avro-1.7.7

- old
+ new

@@ -18,11 +18,12 @@ module Avro module DataFile VERSION = 1 MAGIC = "Obj" + [VERSION].pack('c') - MAGIC_SIZE = MAGIC.size + MAGIC.force_encoding('BINARY') if MAGIC.respond_to?(:force_encoding) + MAGIC_SIZE = MAGIC.respond_to?(:bytesize) ? MAGIC.bytesize : MAGIC.size SYNC_SIZE = 16 SYNC_INTERVAL = 4000 * SYNC_SIZE META_SCHEMA = Schema.parse('{"type": "map", "values": "bytes"}') VALID_ENCODINGS = ['binary'] # not used yet @@ -96,10 +97,11 @@ # If writers_schema is not present, presume we're appending @writer = writer @encoder = IO::BinaryEncoder.new(@writer) @datum_writer = datum_writer @buffer_writer = StringIO.new('', 'w') + @buffer_writer.set_encoding('BINARY') if @buffer_writer.respond_to?(:set_encoding) @buffer_encoder = IO::BinaryEncoder.new(@buffer_writer) @block_count = 0 @meta = {} @@ -179,10 +181,10 @@ def write_block if block_count > 0 # write number of items in block and block size in bytes encoder.write_long(block_count) to_write = codec.compress(buffer_writer.string) - encoder.write_long(to_write.size) + encoder.write_long(to_write.respond_to?(:bytesize) ? to_write.bytesize : to_write.size) # write block contents writer.write(to_write) # write sync marker