[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Need to create zip files

DaZoner

2/4/2005 7:29:00 PM


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?


10 Answers

Nathaniel Talbott

2/4/2005 11:33:00 PM

0

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.sourceforg....

HTH,


Nathaniel
Terralien, Inc.

<:((><



DaZoner

2/7/2005 6:58:00 PM

0


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.sourceforg....
>
> HTH,
>
>
> Nathaniel
> Terralien, Inc.
>
> <:((><
>
>
>


walter

2/7/2005 7:45:00 PM

0

>
> 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





Assaph Mehr

2/7/2005 11:50:00 PM

0


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/projec...), 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

Nathaniel Talbott

2/8/2005 1:01:00 AM

0

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?

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.

<:((><



thomas

2/17/2005 8:53:00 AM

0

"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

James Britt

2/17/2005 1:26:00 PM

0

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


Stephan Kämper

2/17/2005 6:22:00 PM

0

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

thomas

2/18/2005 9:11:00 AM

0

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.sourc....

Thomas

ruby talk

2/18/2005 2:59:00 PM

0

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.


Oh, super cool. Must go see ...


James