ZIP: Writing binary file fails

  • Thread starter Dmytro Bablinyuk
  • Start date
D

Dmytro Bablinyuk

Hi,

Ruby version 1.8.2 (windows XP)
RubyZip version 0.5.11

I am trying to zip a binary file.
For example

Zip::ZipFile.open(target, Zip::ZipFile::CREATE) { |zipfile|
zipfile.dir.mkdir('bin')
zipfile.file.open('bin\eclipse.exe', 'w'){ |f|
f.write(File.open('bin\eclipse.exe', 'rb').read)
}
}

This zips the file but file has only first 163 bytes written (original
file size ~100K)

What I am doing wrong?

Thank you
 
T

Thomas Sondergaard

Dmytro said:
Hi,

Ruby version 1.8.2 (windows XP)
RubyZip version 0.5.11

I am trying to zip a binary file.
For example

Zip::ZipFile.open(target, Zip::ZipFile::CREATE) { |zipfile|
zipfile.dir.mkdir('bin')
zipfile.file.open('bin\eclipse.exe', 'w'){ |f|
f.write(File.open('bin\eclipse.exe', 'rb').read)
}
}

This zips the file but file has only first 163 bytes written (original
file size ~100K)

What I am doing wrong?

You are using backslashes in the zip-file, which you shouldn't do, but I
doubt that is the cause of the problem. Other than that your code works
fine on my linux box. I'll try it in windows when I get home. I suspect
it is a bug in rubyzip.

Thomas
 
T

Thomas Sondergaard

Dmytro said:
I am trying to zip a binary file.
For example

Zip::ZipFile.open(target, Zip::ZipFile::CREATE) { |zipfile|
zipfile.dir.mkdir('bin')
zipfile.file.open('bin\eclipse.exe', 'w'){ |f|
f.write(File.open('bin\eclipse.exe', 'rb').read)
}
}

This zips the file but file has only first 163 bytes written (original
file size ~100K)

What I am doing wrong?

Nothing. You found yet another bug in rubyzip - this time Windows
specific, so I'm semi-excused :). I have fixed it and put up
rubyzip-0.5.12.

gem install rubyzip

or get it from http://rubyforge.org/projects/rubyzip.

Thomas
 
D

Dmytro Bablinyuk

Nothing. You found yet another bug in rubyzip - this time Windows
specific, so I'm semi-excused :). I have fixed it and put up
rubyzip-0.5.12.

gem install rubyzip

or get it from http://rubyforge.org/projects/rubyzip.
Wow, it's really great and really quick fix!
Thank you very much Thomas for your work - it's working now!

As for path separator I am using File::SEPARATOR if this is ok. e.g.
zipfile.file.open('bin' + File::SEPARATOR + 'eclipse.exe', 'w'){ |f|
..

Dimitry
 
T

Thomas Sondergaard

Dmytro said:
As for path separator I am using File::SEPARATOR if this is ok. e.g.
zipfile.file.open('bin' + File::SEPARATOR + 'eclipse.exe', 'w'){ |f|

It's only okay if File::SEPARATOR is a forward slash. The zip spec says
that the path separator is a forward slash. Perhaps I should define
Zip::SEPARATOR='/' or just make sure to substitute all copies of
File::SEPARATOR with '/'.

Thomas
 
T

Tim Ferrell

Dmytro said:
As for path separator I am using File::SEPARATOR if this is ok. e.g.
zipfile.file.open('bin' + File::SEPARATOR + 'eclipse.exe', 'w'){ |f|
..

Dimitry

I may be wrong, but I believe you can just use forward slashes and ruby
will handle it properly regardless of platform. Of course if you are
generating paths for consumption outside of ruby then File::SEPARATOR is
the ticket...

Cheers,
Tim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,052
Latest member
LucyCarper

Latest Threads

Top