superp-rubyzip 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,86 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $: << "../lib"
4
+
5
+ $VERBOSE = true
6
+
7
+ require 'gtk'
8
+ require 'zip/zip'
9
+
10
+ class MainApp < Gtk::Window
11
+ def initialize
12
+ super()
13
+ set_usize(400, 256)
14
+ set_title("rubyzip")
15
+ signal_connect(Gtk::Window::SIGNAL_DESTROY) { Gtk.main_quit }
16
+
17
+ box = Gtk::VBox.new(false, 0)
18
+ add(box)
19
+
20
+ @zipfile = nil
21
+ @buttonPanel = ButtonPanel.new
22
+ @buttonPanel.openButton.signal_connect(Gtk::Button::SIGNAL_CLICKED) {
23
+ show_file_selector
24
+ }
25
+ @buttonPanel.extractButton.signal_connect(Gtk::Button::SIGNAL_CLICKED) {
26
+ puts "Not implemented!"
27
+ }
28
+ box.pack_start(@buttonPanel, false, false, 0)
29
+
30
+ sw = Gtk::ScrolledWindow.new
31
+ sw.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC)
32
+ box.pack_start(sw, true, true, 0)
33
+
34
+ @clist = Gtk::CList.new(["Name", "Size", "Compression"])
35
+ @clist.set_selection_mode(Gtk::SELECTION_BROWSE)
36
+ @clist.set_column_width(0, 120)
37
+ @clist.set_column_width(1, 120)
38
+ @clist.signal_connect(Gtk::CList::SIGNAL_SELECT_ROW) {
39
+ |w, row, column, event|
40
+ @selected_row = row
41
+ }
42
+ sw.add(@clist)
43
+ end
44
+
45
+ class ButtonPanel < Gtk::HButtonBox
46
+ attr_reader :openButton, :extractButton
47
+ def initialize
48
+ super
49
+ set_layout(Gtk::BUTTONBOX_START)
50
+ set_spacing(0)
51
+ @openButton = Gtk::Button.new("Open archive")
52
+ @extractButton = Gtk::Button.new("Extract entry")
53
+ pack_start(@openButton)
54
+ pack_start(@extractButton)
55
+ end
56
+ end
57
+
58
+ def show_file_selector
59
+ @fileSelector = Gtk::FileSelection.new("Open zip file")
60
+ @fileSelector.show
61
+ @fileSelector.ok_button.signal_connect(Gtk::Button::SIGNAL_CLICKED) {
62
+ open_zip(@fileSelector.filename)
63
+ @fileSelector.destroy
64
+ }
65
+ @fileSelector.cancel_button.signal_connect(Gtk::Button::SIGNAL_CLICKED) {
66
+ @fileSelector.destroy
67
+ }
68
+ end
69
+
70
+ def open_zip(filename)
71
+ @zipfile = Zip::File.open(filename)
72
+ @clist.clear
73
+ @zipfile.each {
74
+ |entry|
75
+ @clist.append([ entry.name,
76
+ entry.size.to_s,
77
+ (100.0*entry.compressedSize/entry.size).to_s+"%" ])
78
+ }
79
+ end
80
+ end
81
+
82
+ mainApp = MainApp.new()
83
+
84
+ mainApp.show_all
85
+
86
+ Gtk.main
@@ -0,0 +1,101 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $VERBOSE=true
4
+
5
+ $: << "../lib"
6
+
7
+ require 'Qt'
8
+ system('rbuic -o zipdialogui.rb zipdialogui.ui')
9
+ require 'zipdialogui.rb'
10
+ require 'zip/zip'
11
+
12
+
13
+
14
+ a = Qt::Application.new(ARGV)
15
+
16
+ class ZipDialog < ZipDialogUI
17
+
18
+
19
+ def initialize()
20
+ super()
21
+ connect(child('add_button'), SIGNAL('clicked()'),
22
+ self, SLOT('add_files()'))
23
+ connect(child('extract_button'), SIGNAL('clicked()'),
24
+ self, SLOT('extract_files()'))
25
+ end
26
+
27
+ def zipfile(&proc)
28
+ Zip::File.open(@zip_filename, &proc)
29
+ end
30
+
31
+ def each(&proc)
32
+ Zip::File.foreach(@zip_filename, &proc)
33
+ end
34
+
35
+ def refresh()
36
+ lv = child("entry_list_view")
37
+ lv.clear
38
+ each {
39
+ |e|
40
+ lv.insert_item(Qt::ListViewItem.new(lv, e.name, e.size.to_s))
41
+ }
42
+ end
43
+
44
+
45
+ def load(zipfile)
46
+ @zip_filename = zipfile
47
+ refresh
48
+ end
49
+
50
+ def add_files
51
+ l = Qt::FileDialog.getOpenFileNames(nil, nil, self)
52
+ zipfile {
53
+ |zf|
54
+ l.each {
55
+ |path|
56
+ zf.add(File.basename(path), path)
57
+ }
58
+ }
59
+ refresh
60
+ end
61
+
62
+ def extract_files
63
+ selected_items = []
64
+ unselected_items = []
65
+ lv_item = entry_list_view.first_child
66
+ while (lv_item)
67
+ if entry_list_view.is_selected(lv_item)
68
+ selected_items << lv_item.text(0)
69
+ else
70
+ unselected_items << lv_item.text(0)
71
+ end
72
+ lv_item = lv_item.next_sibling
73
+ end
74
+ puts "selected_items.size = #{selected_items.size}"
75
+ puts "unselected_items.size = #{unselected_items.size}"
76
+ items = selected_items.size > 0 ? selected_items : unselected_items
77
+ puts "items.size = #{items.size}"
78
+
79
+ d = Qt::FileDialog.get_existing_directory(nil, self)
80
+ if (!d)
81
+ puts "No directory chosen"
82
+ else
83
+ zipfile { |zf| items.each { |e| zf.extract(e, File.join(d, e)) } }
84
+ end
85
+
86
+ end
87
+
88
+ slots 'add_files()', 'extract_files()'
89
+ end
90
+
91
+ if !ARGV[0]
92
+ puts "usage: #{$0} zipname"
93
+ exit
94
+ end
95
+
96
+ zd = ZipDialog.new
97
+ zd.load(ARGV[0])
98
+
99
+ a.mainWidget = zd
100
+ zd.show()
101
+ a.exec()
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $: << "../lib"
4
+
5
+ require 'zip/zip'
6
+
7
+ include Zip
8
+
9
+ OutputStream.open('simple.zip') {
10
+ |zos|
11
+ ze = zos.put_next_entry 'entry.txt'
12
+ zos.puts "Hello world"
13
+ }
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $VERBOSE = true
4
+
5
+ $: << "../lib"
6
+
7
+ require 'zip/zip'
8
+ require 'find'
9
+
10
+ module Zip
11
+ module ZipFind
12
+ def self.find(path, zipFilePattern = /\.zip$/i)
13
+ Find.find(path) {
14
+ |fileName|
15
+ yield(fileName)
16
+ if zipFilePattern.match(fileName) && File.file?(fileName)
17
+ begin
18
+ Zip::File.foreach(fileName) {
19
+ |zipEntry|
20
+ yield(fileName + File::SEPARATOR + zipEntry.to_s)
21
+ }
22
+ rescue Errno::EACCES => ex
23
+ puts ex
24
+ end
25
+ end
26
+ }
27
+ end
28
+
29
+ def self.find_file(path, fileNamePattern, zipFilePattern = /\.zip$/i)
30
+ self.find(path, zipFilePattern) {
31
+ |fileName|
32
+ yield(fileName) if fileNamePattern.match(fileName)
33
+ }
34
+ end
35
+
36
+ end
37
+ end
38
+
39
+ if __FILE__ == $0
40
+ module ZipFindConsoleRunner
41
+
42
+ PATH_ARG_INDEX = 0;
43
+ FILENAME_PATTERN_ARG_INDEX = 1;
44
+ ZIPFILE_PATTERN_ARG_INDEX = 2;
45
+
46
+ def self.run(args)
47
+ check_args(args)
48
+ Zip::ZipFind.find_file(args[PATH_ARG_INDEX],
49
+ args[FILENAME_PATTERN_ARG_INDEX],
50
+ args[ZIPFILE_PATTERN_ARG_INDEX]) {
51
+ |fileName|
52
+ report_entry_found fileName
53
+ }
54
+ end
55
+
56
+ def self.check_args(args)
57
+ if (args.size != 3)
58
+ usage
59
+ exit
60
+ end
61
+ end
62
+
63
+ def self.usage
64
+ puts "Usage: #{$0} PATH ZIPFILENAME_PATTERN FILNAME_PATTERN"
65
+ end
66
+
67
+ def self.report_entry_found(fileName)
68
+ puts fileName
69
+ end
70
+
71
+ end
72
+
73
+ ZipFindConsoleRunner.run(ARGV)
74
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: superp-rubyzip
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Alexander Simonov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-21 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - alex@simonov.me
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - samples/example.rb
21
+ - samples/example_filesystem.rb
22
+ - samples/example_recursive.rb
23
+ - samples/gtkRubyzip.rb
24
+ - samples/qtzip.rb
25
+ - samples/write_simple.rb
26
+ - samples/zipfind.rb
27
+ - lib/zip/central_directory.rb
28
+ - lib/zip/compressor.rb
29
+ - lib/zip/constants.rb
30
+ - lib/zip/decompressor.rb
31
+ - lib/zip/deflater.rb
32
+ - lib/zip/dos_time.rb
33
+ - lib/zip/entry.rb
34
+ - lib/zip/entry_set.rb
35
+ - lib/zip/errors.rb
36
+ - lib/zip/extra_field/generic.rb
37
+ - lib/zip/extra_field/universal_time.rb
38
+ - lib/zip/extra_field/unix.rb
39
+ - lib/zip/extra_field.rb
40
+ - lib/zip/file.rb
41
+ - lib/zip/filesystem.rb
42
+ - lib/zip/inflater.rb
43
+ - lib/zip/input_stream.rb
44
+ - lib/zip/ioextras.rb
45
+ - lib/zip/null_compressor.rb
46
+ - lib/zip/null_decompressor.rb
47
+ - lib/zip/null_input_stream.rb
48
+ - lib/zip/output_stream.rb
49
+ - lib/zip/pass_thru_compressor.rb
50
+ - lib/zip/pass_thru_decompressor.rb
51
+ - lib/zip/streamable_directory.rb
52
+ - lib/zip/streamable_stream.rb
53
+ - lib/zip/version.rb
54
+ - lib/zip.rb
55
+ - README.md
56
+ - NEWS
57
+ - TODO
58
+ - Rakefile
59
+ homepage: http://github.com/simonoff/rubyzip
60
+ licenses: []
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: 1.8.7
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.0.3
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: rubyzip is a ruby module for reading and writing zip files
82
+ test_files: []