Skip to content

Commit

Permalink
Replace zip/zip by zip in samples
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrien Siami committed Mar 31, 2014
1 parent e61f058 commit 2468c97
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 30 deletions.
4 changes: 2 additions & 2 deletions samples/example.rb
Expand Up @@ -3,7 +3,7 @@
$: << "../lib"
system("zip example.zip example.rb gtkRubyzip.rb")

require 'zip/zip'
require 'zip'

####### Using ZipInputStream alone: #######

Expand All @@ -23,7 +23,7 @@
zf = Zip::File.new("example.zip")
zf.each_with_index {
|entry, index|

puts "entry #{index} is #{entry.name}, size = #{entry.size}, compressed size = #{entry.compressed_size}"
# use zf.get_input_stream(entry) to get a ZipInputStream for the entry
# entry can be the ZipEntry object or any object which has a to_s method that
Expand Down
13 changes: 6 additions & 7 deletions samples/example_recursive.rb
@@ -1,4 +1,4 @@
require 'zip/zip'
require 'zip'

# This is a simple example which uses rubyzip to
# recursively generate a zip file from the contents of
Expand All @@ -7,7 +7,7 @@
#
# Usage:
# directoryToZip = "/tmp/input"
# outputFile = "/tmp/out.zip"
# outputFile = "/tmp/out.zip"
# zf = ZipFileGenerator.new(directoryToZip, outputFile)
# zf.write()
class ZipFileGenerator
Expand All @@ -20,7 +20,7 @@ def initialize(inputDir, outputFile)

# Zip the input directory.
def write()
entries = Dir.entries(@inputDir); entries.delete("."); entries.delete("..")
entries = Dir.entries(@inputDir); entries.delete("."); entries.delete("..")
io = Zip::File.open(@outputFile, Zip::File::CREATE);

writeEntries(entries, "", io)
Expand All @@ -30,20 +30,19 @@ def write()
# A helper method to make the recursion work.
private
def writeEntries(entries, path, io)

entries.each { |e|
zipFilePath = path == "" ? e : File.join(path, e)
diskFilePath = File.join(@inputDir, zipFilePath)
puts "Deflating " + diskFilePath
if File.directory?(diskFilePath)
io.mkdir(zipFilePath)
subdir =Dir.entries(diskFilePath); subdir.delete("."); subdir.delete("..")
subdir =Dir.entries(diskFilePath); subdir.delete("."); subdir.delete("..")
writeEntries(subdir, zipFilePath, io)
else
io.get_output_stream(zipFilePath) { |f| f.puts(File.open(diskFilePath, "rb").read())}
end
}
end

end

end
10 changes: 5 additions & 5 deletions samples/gtkRubyzip.rb
Expand Up @@ -5,7 +5,7 @@
$VERBOSE = true

require 'gtk'
require 'zip/zip'
require 'zip'

class MainApp < Gtk::Window
def initialize
Expand All @@ -26,7 +26,7 @@ def initialize
puts "Not implemented!"
}
box.pack_start(@buttonPanel, false, false, 0)

sw = Gtk::ScrolledWindow.new
sw.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC)
box.pack_start(sw, true, true, 0)
Expand Down Expand Up @@ -70,10 +70,10 @@ def show_file_selector
def open_zip(filename)
@zipfile = Zip::File.open(filename)
@clist.clear
@zipfile.each {
@zipfile.each {
|entry|
@clist.append([ entry.name,
entry.size.to_s,
@clist.append([ entry.name,
entry.size.to_s,
(100.0*entry.compressedSize/entry.size).to_s+"%" ])
}
end
Expand Down
16 changes: 8 additions & 8 deletions samples/qtzip.rb
Expand Up @@ -7,7 +7,7 @@
require 'Qt'
system('rbuic -o zipdialogui.rb zipdialogui.ui')
require 'zipdialogui.rb'
require 'zip/zip'
require 'zip'



Expand All @@ -31,27 +31,27 @@ def zipfile(&proc)
def each(&proc)
Zip::File.foreach(@zip_filename, &proc)
end

def refresh()
lv = child("entry_list_view")
lv.clear
each {
each {
|e|
lv.insert_item(Qt::ListViewItem.new(lv, e.name, e.size.to_s))
}
end


def load(zipfile)
@zip_filename = zipfile
refresh
end

def add_files
l = Qt::FileDialog.getOpenFileNames(nil, nil, self)
zipfile {
|zf|
l.each {
zipfile {
|zf|
l.each {
|path|
zf.add(File.basename(path), path)
}
Expand Down Expand Up @@ -82,7 +82,7 @@ def extract_files
else
zipfile { |zf| items.each { |e| zf.extract(e, File.join(d, e)) } }
end

end

slots 'add_files()', 'extract_files()'
Expand Down
2 changes: 1 addition & 1 deletion samples/write_simple.rb
Expand Up @@ -2,7 +2,7 @@

$: << "../lib"

require 'zip/zip'
require 'zip'

include Zip

Expand Down
14 changes: 7 additions & 7 deletions samples/zipfind.rb
Expand Up @@ -4,7 +4,7 @@

$: << "../lib"

require 'zip/zip'
require 'zip'
require 'find'

module Zip
Expand Down Expand Up @@ -38,21 +38,21 @@ def self.find_file(path, fileNamePattern, zipFilePattern = /\.zip$/i)

if __FILE__ == $0
module ZipFindConsoleRunner

PATH_ARG_INDEX = 0;
FILENAME_PATTERN_ARG_INDEX = 1;
ZIPFILE_PATTERN_ARG_INDEX = 2;

def self.run(args)
check_args(args)
Zip::ZipFind.find_file(args[PATH_ARG_INDEX],
Zip::ZipFind.find_file(args[PATH_ARG_INDEX],
args[FILENAME_PATTERN_ARG_INDEX],
args[ZIPFILE_PATTERN_ARG_INDEX]) {
|fileName|
report_entry_found fileName
}
end

def self.check_args(args)
if (args.size != 3)
usage
Expand All @@ -63,11 +63,11 @@ def self.check_args(args)
def self.usage
puts "Usage: #{$0} PATH ZIPFILENAME_PATTERN FILNAME_PATTERN"
end

def self.report_entry_found(fileName)
puts fileName
end

end

ZipFindConsoleRunner.run(ARGV)
Expand Down

0 comments on commit 2468c97

Please sign in to comment.