koraktor / rbzip2

bzip2 for Ruby
BSD 3-Clause "New" or "Revised" License
40 stars 10 forks source link

Calling #write more than once is ignored #12

Closed reidmorrison closed 4 years ago

reidmorrison commented 4 years ago

When calling the write method more than once is ignoring new data:

def bz2_read_file(file_name)
  File.open(file_name) do |file|
    io   = RBzip2.default_adapter::Decompressor.new(file)
    data = io.read
    io.close
    data
  end
end

File.open("test3.bz2", "wb") do |file|
  writer  = RBzip2.default_adapter::Compressor.new(file)
  writer.write("line1\n")
  writer.write("line2\n")
  writer.write("line3\n")
  writer.close
end

bz2_read_file("test3.bz2")

Only the first line is returned from the output file:

"line1\n"
reidmorrison commented 4 years ago

Never mind, it appears that .read differs from the regular .read on IO in that instead of returning the entire file, it returns the first line.