Need to create zip files

I'm wanting a programmatic way to create zip files (which I'd like to use in
conjunction with Rake to build my releases on Windows). Is rubyzip the way
to do this or am I missing something about Zlib? If its rubyzip does anyone
have a reference to some docs or examples?

Actually, you'll need both rubyzip and zlib, since zlib does the compression/decomcompression, and rubyzip handles the zip file system. However, as long as you have zlib installed (including the ruby extension for it) you won't have to use it directly - rubyzip just uses it for the heavy lifting.

You can find rubyzip documentation at http://rubyzip.sourceforge.net/doc/.

HTH,

Nathaniel
Terralien, Inc.

<:((><

···

On Feb 4, 2005, at 14:50, DaZoner wrote:

I'm wanting a programmatic way to create zip files (which I'd like to use in
conjunction with Rake to build my releases on Windows). Is rubyzip the way
to do this or am I missing something about Zlib? If its rubyzip does anyone
have a reference to some docs or examples?

RubyZip's docs do not have a "hey! this is how you use this to make a zip"
explanation and the methods aren't really documented - just source code is
shown. Anyone have examples or other docs?

"Nathaniel Talbott" <nathaniel@talbott.ws> wrote in message
news:2bc84bc15f263d2ef6a8aa41948db4c7@talbott.ws...

···

On Feb 4, 2005, at 14:50, DaZoner wrote:

I'm wanting a programmatic way to create zip files (which I'd like to use
in
conjunction with Rake to build my releases on Windows). Is rubyzip the
way
to do this or am I missing something about Zlib? If its rubyzip does
anyone
have a reference to some docs or examples?

Actually, you'll need both rubyzip and zlib, since zlib does the
compression/decomcompression, and rubyzip handles the zip file system.
However, as long as you have zlib installed (including the ruby extension
for it) you won't have to use it directly - rubyzip just uses it for the
heavy lifting.

You can find rubyzip documentation at http://rubyzip.sourceforge.net/doc/.

HTH,

Nathaniel
Terralien, Inc.

<:((><

RubyZip's docs do not have a "hey! this is how you use this to make a zip"
explanation and the methods aren't really documented - just source code is
shown. Anyone have examples or other docs?

The following creates a zip dynamically, but you could traverse the file
system and do the same thing if you need.

hth,

Walt

require 'zip'

Zip::ZipOutputStream.open("c:/zip_test.zip") do |zos|
  zos.put_next_entry("dir_1")
  zos.puts "Hello " * 1000

  zos.put_next_entry("dir_2")
  zos.puts "Hello again"

  zos.put_next_entry("dir_1/sub_dir_1")
  zos.puts "boo!"*10
end

Zip::ZipInputStream.open("c:/zip_test.zip") do |zis|
  while e = zis.get_next_entry
    puts "*******************************************************"
    puts "#{e.name}, orig = #{e.size}, compressed = #{e.compressed_size}"
    puts zis.read
  end
end

···

--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.8.5 - Release Date: 2/3/2005

DaZoner wrote:

RubyZip's docs do not have a "hey! this is how you use this to make a

zip"

explanation and the methods aren't really documented - just source

code is

shown. Anyone have examples or other docs?

Do you mind if you generate a .tar.gz instead of .zip? Both can be
opened in windows by winzip. I really like minitar
(http://raa.ruby-lang.org/project/minitar/), and zipping a bunch of
files can be as easy as:

  files = Dir['*.htm']

  tar = File.open 'guides.tar', 'wb'
  Minitar.pack files, tar

  # zip into .tar.gz:
  tgz = Zlib::GzipWriter.open('guides.tar.gz')
  tgz.write File.open('guides.tar', 'rb').read
  tgz.close

Just note that the files are always opened in binary mode.

HTH,
Assaph

Sorry, I should have mentioned that there are samples (and tests) in the rubyzip archive. You should download it and have a look.

HTH,

Nathaniel
Terralien, Inc.

<:((><

···

On Feb 7, 2005, at 14:20, DaZoner wrote:

RubyZip's docs do not have a "hey! this is how you use this to make a zip"
explanation and the methods aren't really documented - just source code is
shown. Anyone have examples or other docs?

"DaZoner" <bugmenot@world.com> wrote in message news:<cu8dmv$8u$1@news.doit.wisc.edu>...

RubyZip's docs do not have a "hey! this is how you use this to make a zip"
explanation and the methods aren't really documented - just source code is
shown. Anyone have examples or other docs?

You are right the documentation really needs improvement. I'll see if
I can crank out something useful.

Cheers,

Thomas

Thomas Sondergaard wrote:

"DaZoner" <bugmenot@world.com> wrote in message news:<cu8dmv$8u$1@news.doit.wisc.edu>...

RubyZip's docs do not have a "hey! this is how you use this to make a zip" explanation and the methods aren't really documented - just source code is shown. Anyone have examples or other docs?

ooo4r.rubyforge.org creates OOo docs, which are zip files.

(I haven't looked at the code in a while, but I recall having issues with corrupt headers when generating the zip files)

James

James Britt wrote:

Thomas Sondergaard wrote:

"DaZoner" <bugmenot@world.com> wrote in message news:<cu8dmv$8u$1@news.doit.wisc.edu>...

RubyZip's docs do not have a "hey! this is how you use this to make a zip" explanation and the methods aren't really documented - just source code is shown. Anyone have examples or other docs?

file_name: The (base) name of a to-be-zipped file
FILES_DIR: The directory where the file lives
PACKED_DIR: The directory where the zip file is created

Zip::ZipFile.open( "#{ PACKED_DIR }/#{ file_name }.zip",
                    Zip::ZipFile::CREATE ) { | zip |
                        zip.add( "#{ file_name }.rb" ,
                                 "#{ FILES_DIR }#{ file_name }.rb" )
       }

Beware of the line breaks.

HTH

Happy rubying

Stephan

James Britt <jamesUNDERBARb@neurogami.com> wrote in message

ooo4r.rubyforge.org creates OOo docs, which are zip files.

(I haven't looked at the code in a while, but I recall having issues
with corrupt headers when generating the zip files)

James

I think I fixed the issue(s) with header corruption.

To the original poster: I have been busy last night writing rdoc
comments in rubyzip - check it out at http://rubyzip.sourceforge.net.

Thomas

Oh, super cool. Must go see ...

James

···

On Fri, 18 Feb 2005 18:14:47 +0900, Thomas Sondergaard <thomas@sondergaard.cc> wrote:

James Britt <jamesUNDERBARb@neurogami.com> wrote in message
> ooo4r.rubyforge.org creates OOo docs, which are zip files.
>
> (I haven't looked at the code in a while, but I recall having issues
> with corrupt headers when generating the zip files)
>
> James

I think I fixed the issue(s) with header corruption.