1

I'm using rubyzip library for zipping files.
But I encounter problems.
I try:

    Zip::ZipOutputStream.open('c:/sites/efiling2/test.zip') do |zos|
        zos.put_next_entry("test.rtf")
        zos.write IO.read('c:/sites/efiling2/test.rtf')
        zos.put_next_entry("test.jpg")
        zos.write IO.read('c:/sites/efiling2/test.jpg')
    end

But write method restricts a size of original files. For example my source file test.jpg has a size of 11913 bytes, but in archive there is a file test.jpg with size 11551 bytes. With test.rtf there is the same situations.

Any suggestions?

Casper
  • 33,403
  • 4
  • 84
  • 79
Lesha Pipiev
  • 3,251
  • 4
  • 31
  • 65

1 Answers1

1

I suspect your problem may be IO.read(). I'm not so sure it does binary data properly.

I would try this instead and see if it fixes the problem:

File.open(filename, "rb") { |f| f.read }
Casper
  • 33,403
  • 4
  • 84
  • 79
  • Thank you so much. I spent quite some time on this trying every angle to figure out why my images were missing pieces and your solution solved my problem! – James Testa Mar 06 '13 at 18:13