hotplate 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +4 -0
- data/Rakefile +1 -0
- data/bin/toast +2 -0
- data/hotplate.gemspec +30 -0
- data/lib/hotplate/cli/build.rb +51 -0
- data/lib/hotplate/cli/init.rb +64 -0
- data/lib/hotplate/cli/main.rb +39 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/README.md +271 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/Rakefile +19 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/TODO +15 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/central_directory.rb +208 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/compressor.rb +10 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/constants.rb +63 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/crypto/encryption.rb +11 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/crypto/null_encryption.rb +45 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/crypto/traditional_encryption.rb +99 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/decompressor.rb +13 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/deflater.rb +32 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/dos_time.rb +49 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/entry.rb +696 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/entry_set.rb +86 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/errors.rb +16 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/extra_field/generic.rb +43 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/extra_field/ntfs.rb +92 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/extra_field/old_unix.rb +45 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/extra_field/universal_time.rb +47 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/extra_field/unix.rb +38 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/extra_field/zip64.rb +67 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/extra_field/zip64_placeholder.rb +16 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/extra_field.rb +101 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/file.rb +436 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/filesystem.rb +626 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/inflater.rb +66 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/input_stream.rb +164 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/ioextras/abstract_input_stream.rb +115 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/ioextras/abstract_output_stream.rb +45 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/ioextras.rb +38 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/null_compressor.rb +15 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/null_decompressor.rb +27 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/null_input_stream.rb +10 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/output_stream.rb +190 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/pass_thru_compressor.rb +23 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/pass_thru_decompressor.rb +41 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/streamable_directory.rb +15 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/streamable_stream.rb +56 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/version.rb +3 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip.rb +63 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/samples/example.rb +91 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/samples/example_filesystem.rb +33 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/samples/example_recursive.rb +48 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/samples/gtkRubyzip.rb +86 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/samples/qtzip.rb +101 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/samples/write_simple.rb +13 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/samples/zipfind.rb +74 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/test/basic_zip_file_test.rb +64 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/test/central_directory_entry_test.rb +73 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/test/central_directory_test.rb +104 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/test/crypto/null_encryption_test.rb +53 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/test/crypto/traditional_encryption_test.rb +80 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/test/data/WarnInvalidDate.zip +0 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/test/data/file1.txt +46 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/test/data/file1.txt.deflatedData +0 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/test/data/file2.txt +1504 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/test/data/globTest/foo/bar/baz/foo.txt +0 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/test/data/globTest/foo.txt +0 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/test/data/globTest/food.txt +0 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/test/data/globTest.zip +0 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/test/data/mimetype +1 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/test/data/notzippedruby.rb +7 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/test/data/ntfs.zip +0 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/test/data/rubycode.zip +0 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/test/data/rubycode2.zip +0 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/test/data/testDirectory.bin +0 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/test/data/zip64-sample.zip +0 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/test/data/zipWithDirs.zip +0 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/test/data/zipWithEncryption.zip +0 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/test/deflater_test.rb +67 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/test/encryption_test.rb +42 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/test/entry_set_test.rb +138 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/test/entry_test.rb +165 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/test/errors_test.rb +36 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/test/extra_field_test.rb +78 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/test/file_extract_directory_test.rb +56 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/test/file_extract_test.rb +90 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/test/file_split_test.rb +60 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/test/file_test.rb +559 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/test/filesystem/dir_iterator_test.rb +62 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/test/filesystem/directory_test.rb +131 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/test/filesystem/file_mutating_test.rb +100 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/test/filesystem/file_nonmutating_test.rb +514 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/test/filesystem/file_stat_test.rb +66 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/test/gentestfiles.rb +134 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/test/inflater_test.rb +14 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/test/input_stream_test.rb +170 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/test/ioextras/abstract_input_stream_test.rb +103 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/test/ioextras/abstract_output_stream_test.rb +106 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/test/ioextras/fake_io_test.rb +18 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/test/local_entry_test.rb +156 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/test/output_stream_test.rb +129 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/test/pass_thru_compressor_test.rb +31 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/test/pass_thru_decompressor_test.rb +15 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/test/settings_test.rb +92 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/test/test_helper.rb +228 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/test/unicode_file_names_and_comments_test.rb +52 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/test/zip64_full_test.rb +53 -0
- data/lib/hotplate/gems/rubyzip-1.1.7/test/zip64_support_test.rb +15 -0
- data/lib/hotplate/java/build.gradle +38 -0
- data/lib/hotplate/java/gradle/wrapper/gradle-wrapper.jar +0 -0
- data/lib/hotplate/java/gradle/wrapper/gradle-wrapper.properties +6 -0
- data/lib/hotplate/java/gradlew +164 -0
- data/lib/hotplate/java/gradlew.bat +90 -0
- data/lib/hotplate/java/template.java +25 -0
- data/lib/hotplate/version.rb +3 -0
- data/lib/hotplate.rb +2 -0
- metadata +186 -0
@@ -0,0 +1,56 @@
|
|
1
|
+
module Zip
|
2
|
+
class StreamableStream < DelegateClass(Entry) #nodoc:all
|
3
|
+
def initialize(entry)
|
4
|
+
super(entry)
|
5
|
+
dirname = if zipfile.is_a?(::String)
|
6
|
+
::File.dirname(zipfile)
|
7
|
+
else
|
8
|
+
'.'
|
9
|
+
end
|
10
|
+
@temp_file = Tempfile.new(::File.basename(name), dirname)
|
11
|
+
@temp_file.binmode
|
12
|
+
end
|
13
|
+
|
14
|
+
def get_output_stream
|
15
|
+
if block_given?
|
16
|
+
begin
|
17
|
+
yield(@temp_file)
|
18
|
+
ensure
|
19
|
+
@temp_file.close
|
20
|
+
end
|
21
|
+
else
|
22
|
+
@temp_file
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def get_input_stream
|
27
|
+
if !@temp_file.closed?
|
28
|
+
raise StandardError, "cannot open entry for reading while its open for writing - #{name}"
|
29
|
+
end
|
30
|
+
@temp_file.open # reopens tempfile from top
|
31
|
+
@temp_file.binmode
|
32
|
+
if block_given?
|
33
|
+
begin
|
34
|
+
yield(@temp_file)
|
35
|
+
ensure
|
36
|
+
@temp_file.close
|
37
|
+
end
|
38
|
+
else
|
39
|
+
@temp_file
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def write_to_zip_output_stream(aZipOutputStream)
|
44
|
+
aZipOutputStream.put_next_entry(self)
|
45
|
+
get_input_stream { |is| ::Zip::IOExtras.copy_stream(aZipOutputStream, is) }
|
46
|
+
end
|
47
|
+
|
48
|
+
def clean_up
|
49
|
+
@temp_file.unlink
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# Copyright (C) 2002, 2003 Thomas Sondergaard
|
55
|
+
# rubyzip is free software; you can redistribute it and/or
|
56
|
+
# modify it under the terms of the ruby license.
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'delegate'
|
2
|
+
require 'singleton'
|
3
|
+
require 'tempfile'
|
4
|
+
require 'fileutils'
|
5
|
+
require 'stringio'
|
6
|
+
require 'zlib'
|
7
|
+
require 'zip/dos_time'
|
8
|
+
require 'zip/ioextras'
|
9
|
+
require 'rbconfig'
|
10
|
+
require 'zip/entry'
|
11
|
+
require 'zip/extra_field'
|
12
|
+
require 'zip/entry_set'
|
13
|
+
require 'zip/central_directory'
|
14
|
+
require 'zip/file'
|
15
|
+
require 'zip/input_stream'
|
16
|
+
require 'zip/output_stream'
|
17
|
+
require 'zip/decompressor'
|
18
|
+
require 'zip/compressor'
|
19
|
+
require 'zip/null_decompressor'
|
20
|
+
require 'zip/null_compressor'
|
21
|
+
require 'zip/null_input_stream'
|
22
|
+
require 'zip/pass_thru_compressor'
|
23
|
+
require 'zip/pass_thru_decompressor'
|
24
|
+
require 'zip/crypto/encryption'
|
25
|
+
require 'zip/crypto/null_encryption'
|
26
|
+
require 'zip/crypto/traditional_encryption'
|
27
|
+
require 'zip/inflater'
|
28
|
+
require 'zip/deflater'
|
29
|
+
require 'zip/streamable_stream'
|
30
|
+
require 'zip/streamable_directory'
|
31
|
+
require 'zip/constants'
|
32
|
+
require 'zip/errors'
|
33
|
+
if defined? JRUBY_VERSION
|
34
|
+
require 'jruby'
|
35
|
+
JRuby.objectspace = true
|
36
|
+
end
|
37
|
+
|
38
|
+
module Zip
|
39
|
+
extend self
|
40
|
+
attr_accessor :unicode_names, :on_exists_proc, :continue_on_exists_proc, :sort_entries, :default_compression, :write_zip64_support, :warn_invalid_date
|
41
|
+
|
42
|
+
def reset!
|
43
|
+
@_ran_once = false
|
44
|
+
@unicode_names = false
|
45
|
+
@on_exists_proc = false
|
46
|
+
@continue_on_exists_proc = false
|
47
|
+
@sort_entries = false
|
48
|
+
@default_compression = ::Zlib::DEFAULT_COMPRESSION
|
49
|
+
@write_zip64_support = false
|
50
|
+
@warn_invalid_date = true
|
51
|
+
end
|
52
|
+
|
53
|
+
def setup
|
54
|
+
yield self unless @_ran_once
|
55
|
+
@_ran_once = true
|
56
|
+
end
|
57
|
+
|
58
|
+
reset!
|
59
|
+
end
|
60
|
+
|
61
|
+
# Copyright (C) 2002, 2003 Thomas Sondergaard
|
62
|
+
# rubyzip is free software; you can redistribute it and/or
|
63
|
+
# modify it under the terms of the ruby license.
|
@@ -0,0 +1,91 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$: << "../lib"
|
4
|
+
system("zip example.zip example.rb gtkRubyzip.rb")
|
5
|
+
|
6
|
+
require 'zip'
|
7
|
+
|
8
|
+
####### Using ZipInputStream alone: #######
|
9
|
+
|
10
|
+
Zip::InputStream.open("example.zip") {
|
11
|
+
|zis|
|
12
|
+
entry = zis.get_next_entry
|
13
|
+
print "First line of '#{entry.name} (#{entry.size} bytes): "
|
14
|
+
puts "'#{zis.gets.chomp}'"
|
15
|
+
entry = zis.get_next_entry
|
16
|
+
print "First line of '#{entry.name} (#{entry.size} bytes): "
|
17
|
+
puts "'#{zis.gets.chomp}'"
|
18
|
+
}
|
19
|
+
|
20
|
+
|
21
|
+
####### Using ZipFile to read the directory of a zip file: #######
|
22
|
+
|
23
|
+
zf = Zip::File.new("example.zip")
|
24
|
+
zf.each_with_index {
|
25
|
+
|entry, index|
|
26
|
+
|
27
|
+
puts "entry #{index} is #{entry.name}, size = #{entry.size}, compressed size = #{entry.compressed_size}"
|
28
|
+
# use zf.get_input_stream(entry) to get a ZipInputStream for the entry
|
29
|
+
# entry can be the ZipEntry object or any object which has a to_s method that
|
30
|
+
# returns the name of the entry.
|
31
|
+
}
|
32
|
+
|
33
|
+
|
34
|
+
####### Using ZipOutputStream to write a zip file: #######
|
35
|
+
|
36
|
+
Zip::OutputStream.open("exampleout.zip") {
|
37
|
+
|zos|
|
38
|
+
zos.put_next_entry("the first little entry")
|
39
|
+
zos.puts "Hello hello hello hello hello hello hello hello hello"
|
40
|
+
|
41
|
+
zos.put_next_entry("the second little entry")
|
42
|
+
zos.puts "Hello again"
|
43
|
+
|
44
|
+
# Use rubyzip or your zip client of choice to verify
|
45
|
+
# the contents of exampleout.zip
|
46
|
+
}
|
47
|
+
|
48
|
+
####### Using ZipFile to change a zip file: #######
|
49
|
+
|
50
|
+
Zip::File.open("exampleout.zip") {
|
51
|
+
|zf|
|
52
|
+
zf.add("thisFile.rb", "example.rb")
|
53
|
+
zf.rename("thisFile.rb", "ILikeThisName.rb")
|
54
|
+
zf.add("Again", "example.rb")
|
55
|
+
}
|
56
|
+
|
57
|
+
# Lets check
|
58
|
+
Zip::File.open("exampleout.zip") {
|
59
|
+
|zf|
|
60
|
+
puts "Changed zip file contains: #{zf.entries.join(', ')}"
|
61
|
+
zf.remove("Again")
|
62
|
+
puts "Without 'Again': #{zf.entries.join(', ')}"
|
63
|
+
}
|
64
|
+
|
65
|
+
####### Using ZipFile to split a zip file: #######
|
66
|
+
|
67
|
+
# Creating large zip file for splitting
|
68
|
+
Zip::OutputStream.open("large_zip_file.zip") do |zos|
|
69
|
+
puts "Creating zip file..."
|
70
|
+
10.times do |i|
|
71
|
+
zos.put_next_entry("large_entry_#{i}.txt")
|
72
|
+
zos.puts "Hello" * 104857600
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# Splitting created large zip file
|
77
|
+
part_zips_count = Zip::File.split("large_zip_file.zip", 2097152, false)
|
78
|
+
puts "Zip file splitted in #{part_zips_count} parts"
|
79
|
+
|
80
|
+
# Track splitting an archive
|
81
|
+
Zip::File.split("large_zip_file.zip", 1048576, true, 'part_zip_file') do
|
82
|
+
|part_count, part_index, chunk_bytes, segment_bytes|
|
83
|
+
puts "#{part_index} of #{part_count} part splitting: #{(chunk_bytes.to_f/segment_bytes.to_f * 100).to_i}%"
|
84
|
+
end
|
85
|
+
|
86
|
+
|
87
|
+
# For other examples, look at zip.rb and ziptest.rb
|
88
|
+
|
89
|
+
# Copyright (C) 2002 Thomas Sondergaard
|
90
|
+
# rubyzip is free software; you can redistribute it and/or
|
91
|
+
# modify it under the terms of the ruby license.
|
@@ -0,0 +1,33 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$: << "../lib"
|
4
|
+
|
5
|
+
require 'zip/zipfilesystem'
|
6
|
+
|
7
|
+
EXAMPLE_ZIP = "filesystem.zip"
|
8
|
+
|
9
|
+
File.delete(EXAMPLE_ZIP) if File.exists?(EXAMPLE_ZIP)
|
10
|
+
|
11
|
+
Zip::File.open(EXAMPLE_ZIP, Zip::File::CREATE) {
|
12
|
+
|zf|
|
13
|
+
zf.file.open("file1.txt", "w") { |os| os.write "first file1.txt" }
|
14
|
+
zf.dir.mkdir("dir1")
|
15
|
+
zf.dir.chdir("dir1")
|
16
|
+
zf.file.open("file1.txt", "w") { |os| os.write "second file1.txt" }
|
17
|
+
puts zf.file.read("file1.txt")
|
18
|
+
puts zf.file.read("../file1.txt")
|
19
|
+
zf.dir.chdir("..")
|
20
|
+
zf.file.open("file2.txt", "w") { |os| os.write "first file2.txt" }
|
21
|
+
puts "Entries: #{zf.entries.join(', ')}"
|
22
|
+
}
|
23
|
+
|
24
|
+
Zip::File.open(EXAMPLE_ZIP) {
|
25
|
+
|zf|
|
26
|
+
puts "Entries from reloaded zip: #{zf.entries.join(', ')}"
|
27
|
+
}
|
28
|
+
|
29
|
+
# For other examples, look at zip.rb and ziptest.rb
|
30
|
+
|
31
|
+
# Copyright (C) 2003 Thomas Sondergaard
|
32
|
+
# rubyzip is free software; you can redistribute it and/or
|
33
|
+
# modify it under the terms of the ruby license.
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'zip'
|
2
|
+
|
3
|
+
# This is a simple example which uses rubyzip to
|
4
|
+
# recursively generate a zip file from the contents of
|
5
|
+
# a specified directory. The directory itself is not
|
6
|
+
# included in the archive, rather just its contents.
|
7
|
+
#
|
8
|
+
# Usage:
|
9
|
+
# directoryToZip = "/tmp/input"
|
10
|
+
# outputFile = "/tmp/out.zip"
|
11
|
+
# zf = ZipFileGenerator.new(directoryToZip, outputFile)
|
12
|
+
# zf.write()
|
13
|
+
class ZipFileGenerator
|
14
|
+
|
15
|
+
# Initialize with the directory to zip and the location of the output archive.
|
16
|
+
def initialize(inputDir, outputFile)
|
17
|
+
@inputDir = inputDir
|
18
|
+
@outputFile = outputFile
|
19
|
+
end
|
20
|
+
|
21
|
+
# Zip the input directory.
|
22
|
+
def write()
|
23
|
+
entries = Dir.entries(@inputDir); entries.delete("."); entries.delete("..")
|
24
|
+
io = Zip::File.open(@outputFile, Zip::File::CREATE);
|
25
|
+
|
26
|
+
writeEntries(entries, "", io)
|
27
|
+
io.close();
|
28
|
+
end
|
29
|
+
|
30
|
+
# A helper method to make the recursion work.
|
31
|
+
private
|
32
|
+
def writeEntries(entries, path, io)
|
33
|
+
|
34
|
+
entries.each { |e|
|
35
|
+
zipFilePath = path == "" ? e : File.join(path, e)
|
36
|
+
diskFilePath = File.join(@inputDir, zipFilePath)
|
37
|
+
puts "Deflating " + diskFilePath
|
38
|
+
if File.directory?(diskFilePath)
|
39
|
+
io.mkdir(zipFilePath)
|
40
|
+
subdir =Dir.entries(diskFilePath); subdir.delete("."); subdir.delete("..")
|
41
|
+
writeEntries(subdir, zipFilePath, io)
|
42
|
+
else
|
43
|
+
io.get_output_stream(zipFilePath) { |f| f.puts(File.open(diskFilePath, "rb").read())}
|
44
|
+
end
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$: << "../lib"
|
4
|
+
|
5
|
+
$VERBOSE = true
|
6
|
+
|
7
|
+
require 'gtk'
|
8
|
+
require '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'
|
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,74 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$VERBOSE = true
|
4
|
+
|
5
|
+
$: << "../lib"
|
6
|
+
|
7
|
+
require '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
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class BasicZipFileTest < MiniTest::Test
|
4
|
+
include AssertEntry
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@zip_file = ::Zip::File.new(TestZipFile::TEST_ZIP2.zip_name)
|
8
|
+
@testEntryNameIndex=0
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_entries
|
12
|
+
assert_equal(TestZipFile::TEST_ZIP2.entry_names.sort,
|
13
|
+
@zip_file.entries.entries.sort.map { |e| e.name })
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_each
|
17
|
+
count = 0
|
18
|
+
visited = {}
|
19
|
+
@zip_file.each {
|
20
|
+
|entry|
|
21
|
+
assert(TestZipFile::TEST_ZIP2.entry_names.include?(entry.name))
|
22
|
+
assert(!visited.include?(entry.name))
|
23
|
+
visited[entry.name] = nil
|
24
|
+
count = count.succ
|
25
|
+
}
|
26
|
+
assert_equal(TestZipFile::TEST_ZIP2.entry_names.length, count)
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_foreach
|
30
|
+
count = 0
|
31
|
+
visited = {}
|
32
|
+
::Zip::File.foreach(TestZipFile::TEST_ZIP2.zip_name) {
|
33
|
+
|entry|
|
34
|
+
assert(TestZipFile::TEST_ZIP2.entry_names.include?(entry.name))
|
35
|
+
assert(!visited.include?(entry.name))
|
36
|
+
visited[entry.name] = nil
|
37
|
+
count = count.succ
|
38
|
+
}
|
39
|
+
assert_equal(TestZipFile::TEST_ZIP2.entry_names.length, count)
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_get_input_stream
|
43
|
+
count = 0
|
44
|
+
visited = {}
|
45
|
+
@zip_file.each do |entry|
|
46
|
+
assert_entry(entry.name, @zip_file.get_input_stream(entry), entry.name)
|
47
|
+
assert(!visited.include?(entry.name))
|
48
|
+
visited[entry.name] = nil
|
49
|
+
count = count.succ
|
50
|
+
end
|
51
|
+
assert_equal(TestZipFile::TEST_ZIP2.entry_names.length, count)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_get_input_streamBlock
|
55
|
+
fileAndEntryName = @zip_file.entries.first.name
|
56
|
+
@zip_file.get_input_stream(fileAndEntryName) {
|
57
|
+
|zis|
|
58
|
+
assert_entryContentsForStream(fileAndEntryName,
|
59
|
+
zis,
|
60
|
+
fileAndEntryName)
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|