From: Robert Klemme Date: 2004-09-07T04:45:11+09:00 Subject: Re: ruby archiver "Martin DeMello" schrieb im Newsbeitrag news:uP2%c.315284$M95.37367@pd7tw1no... > Is there any pure-ruby way to pack multiple files into a single file, > and unpack them later? Compression is optional. Dunno, but you could easily create one using Marshal. Experimental (works only for text files and files that fit completely into memory): def archive(archive, *files) File.open(archive, "wb") do |io| files.each do |file| Marshal.dump(file, io) Marshal.dump(File.read(file), io) end end end def unarchive(archive) names = [] begin File.open(archive, "rb") do |io| file = Marshal.load( io ) File.open(file, "w") {|out| out.write( Marshal.load( io ) ) } names << file end rescue EOFError # ok, no more objects end names end archive( "test.rarc", "Rg.rb" ) File.rename "Rg.rb", "Rg-old.rb" p unarchive( "test.rarc" ) robert