hotplate 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: fba850693cc228819c3a4e0e52b62f2d6bbec008
|
|
4
|
+
data.tar.gz: 7b8636e8846d340bd2feb44198cdeafbf42d0c98
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: f29ba82dadbacc47cdb18130728cae5475cfcb71dee43c54858a9a77099bda47ccd340812244a9afd209381c7291c62e1bad1170f50ac94a89d18d812258aee2
|
|
7
|
+
data.tar.gz: e6b3dad697fb6826601f9794e2cd05874c61b948420f08b83371c23d57a438c701a60f33d781fcc8e162eb0d6e1cea74ea937d5753c1cb3f31619cc9ea648cfd
|
data/Gemfile
ADDED
data/Rakefile
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/toast
ADDED
data/hotplate.gemspec
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'hotplate/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "hotplate"
|
|
8
|
+
spec.version = HotPlate::VERSION
|
|
9
|
+
spec.authors = ["Jaci R"]
|
|
10
|
+
spec.email = ["jaci.brunning@gmail.com"]
|
|
11
|
+
|
|
12
|
+
spec.summary = %q{Toast module deployment made easy}
|
|
13
|
+
spec.homepage = "http://github.com/Open-RIO/HotPlate"
|
|
14
|
+
|
|
15
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
|
16
|
+
# delete this section to allow pushing this gem to any host.
|
|
17
|
+
# if spec.respond_to?(:metadata)
|
|
18
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
|
19
|
+
# else
|
|
20
|
+
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
|
21
|
+
# end
|
|
22
|
+
|
|
23
|
+
spec.bindir = "bin"
|
|
24
|
+
spec.files = Dir.glob("lib/**/*") + ['Rakefile', 'hotplate.gemspec', 'Gemfile', 'Rakefile']
|
|
25
|
+
spec.executables = ["toast"]
|
|
26
|
+
spec.require_paths = ["lib"]
|
|
27
|
+
|
|
28
|
+
spec.add_development_dependency "bundler"
|
|
29
|
+
spec.add_development_dependency "rake"
|
|
30
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
if File.exist? "#{dir}/build.gradle"
|
|
2
|
+
puts "Attempting to build Java Project"
|
|
3
|
+
if os == :windows
|
|
4
|
+
system("(cd #{dir} && gradlew build)")
|
|
5
|
+
else
|
|
6
|
+
system("(cd #{dir} && ./gradlew build)")
|
|
7
|
+
end
|
|
8
|
+
elsif File.exist? "#{dir}/module.json"
|
|
9
|
+
prebuild = File.absolute_path(File.join(dir, "prebuild.rb"))
|
|
10
|
+
build = File.absolute_path(File.join(dir, "build.rb"))
|
|
11
|
+
|
|
12
|
+
require prebuild if File.exist? prebuild
|
|
13
|
+
|
|
14
|
+
require 'zip'
|
|
15
|
+
puts "Attempting to build JavaScript project"
|
|
16
|
+
exppath = File.expand_path(".", dir)
|
|
17
|
+
buildfiles = Dir[exppath + "/**/*"]
|
|
18
|
+
exclusions = ["build", "build/*.jsm"]
|
|
19
|
+
exclusions << File.read("#{dir}/exclude.build").split(/\r?\n/) if File.exist? "#{dir}/exclude.build"
|
|
20
|
+
exclusion_list = []
|
|
21
|
+
exclusions = exclusions.flatten
|
|
22
|
+
exclusions.each {|excl| exclusion_list << Dir[exppath + "/" + excl]}
|
|
23
|
+
file_list = buildfiles - exclusion_list.flatten
|
|
24
|
+
|
|
25
|
+
moduleconfig = File.read(File.join(dir, "module.json"))
|
|
26
|
+
archive_name = moduleconfig.scan(/"name"\s*:\s*"(.*)"/)[0][0]
|
|
27
|
+
version_match = moduleconfig.scan(/"version"\s*:\s*"(.*)"/)
|
|
28
|
+
archive_name += "_#{version_match[0][0]}" if version_match.length > 0
|
|
29
|
+
|
|
30
|
+
archive_name += ".jsm"
|
|
31
|
+
FileUtils.mkdir "#{dir}/build" unless File.exist? "#{dir}/build"
|
|
32
|
+
archive_path = "#{dir}/build/#{archive_name}"
|
|
33
|
+
|
|
34
|
+
require build if File.exist? build
|
|
35
|
+
|
|
36
|
+
puts "Building Archive: #{archive_name}"
|
|
37
|
+
puts "Including Files: "
|
|
38
|
+
puts file_list.map {|x| "\t#{x.gsub(/\\/, "/").gsub(dir.gsub(/\\/, "/"), "")}\n"}
|
|
39
|
+
|
|
40
|
+
FileUtils.rm_rf archive_path if File.exist? archive_path
|
|
41
|
+
Zip::File.open(archive_path, Zip::File::CREATE) do |zipfile|
|
|
42
|
+
file_list.each do |fn|
|
|
43
|
+
relative = fn.gsub(/\\/, "/").gsub(dir.gsub(/\\/, "/"), "")
|
|
44
|
+
zipfile.add(relative[1..relative.length], fn)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
puts "Build Complete"
|
|
49
|
+
else
|
|
50
|
+
puts "Can't build: not a valid Toast Project"
|
|
51
|
+
end
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
require 'FileUtils'
|
|
2
|
+
|
|
3
|
+
def java
|
|
4
|
+
puts "What is your Team Number? (0000)"
|
|
5
|
+
team = gets.chop!.to_i.to_s # Ensures it's a proper number :)
|
|
6
|
+
clazz = "#{@path}/src/main/java/frc/team#{team}/#{@name}/RobotModule.java"
|
|
7
|
+
jin = File.expand_path "../../java", __FILE__
|
|
8
|
+
FileUtils.cp_r "#{jin}/.", @path
|
|
9
|
+
|
|
10
|
+
build = File.read File.join(@path, "build.gradle")
|
|
11
|
+
build = build.gsub "%%TEAM", team
|
|
12
|
+
build = build.gsub "%%NAME", @name
|
|
13
|
+
File.write File.join(@path, "build.gradle"), build
|
|
14
|
+
|
|
15
|
+
templ = File.join(@path, "template.java")
|
|
16
|
+
template = File.read templ
|
|
17
|
+
template = template.gsub "%%TEAM", team
|
|
18
|
+
template = template.gsub "%%NAMED", @name.downcase
|
|
19
|
+
template = template.gsub "%%NAME", @name
|
|
20
|
+
FileUtils.mkdir_p File.expand_path("..", clazz)
|
|
21
|
+
File.write clazz, template
|
|
22
|
+
File.delete templ
|
|
23
|
+
|
|
24
|
+
begin
|
|
25
|
+
FileUtils.chmod 0777, %w(build.gradle, gradlew)
|
|
26
|
+
rescue; end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def javascript
|
|
30
|
+
puts "What is your main script class name? [main.js]"
|
|
31
|
+
name = gets.chop!
|
|
32
|
+
name = "main.js" if name == ""
|
|
33
|
+
name += ".js" unless name =~ /^(.*)\.js$/
|
|
34
|
+
File.write("#{@path}/module.json", "{\n\t\"name\": \"#{@name}\",\n\t\"script\": \"#{name}\"\n}")
|
|
35
|
+
File.write("#{@path}/#{name}", "console.log('Hello Toast!');")
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
puts "Creating a new Toast Module."
|
|
39
|
+
|
|
40
|
+
puts "What is the name of your Module?"
|
|
41
|
+
@name = gets.chop!
|
|
42
|
+
@path = File.join dir, @name
|
|
43
|
+
if File.exist? @path
|
|
44
|
+
puts "Module already exists? Want to override? (THIS CANNOT BE UNDONE) [y/n]"
|
|
45
|
+
inp = gets.chop!
|
|
46
|
+
if inp =~ /(y(es)?)|1|(t(rue)?)/i
|
|
47
|
+
puts "Overriding..."
|
|
48
|
+
FileUtils.rm_rf @path
|
|
49
|
+
else
|
|
50
|
+
puts "Aborting..."
|
|
51
|
+
exit
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
FileUtils.mkdir @path
|
|
55
|
+
|
|
56
|
+
puts "What kind of Toast Module would you like to create? [java/javascript] (java)"
|
|
57
|
+
option = gets.chop!
|
|
58
|
+
if option =~ /javas(cript)?/i
|
|
59
|
+
javascript
|
|
60
|
+
else
|
|
61
|
+
java
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
puts "Toast Module Created! #{@name}"
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
require 'optparse'
|
|
2
|
+
|
|
3
|
+
trap("INT"){exit}
|
|
4
|
+
|
|
5
|
+
OptionParser.new do |o|
|
|
6
|
+
o.on("-d DIRECTORY", "--directory", "The directory to start in") {|dir| @dir = dir}
|
|
7
|
+
end.parse!
|
|
8
|
+
|
|
9
|
+
def dir
|
|
10
|
+
@dir ||= "."
|
|
11
|
+
File.absolute_path @dir
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def os
|
|
15
|
+
if (/Windows/ =~ ENV['OS']) != nil
|
|
16
|
+
return :windows
|
|
17
|
+
elsif (/darwin/ =~ RUBY_PLATFORM) != nil
|
|
18
|
+
return :darwin
|
|
19
|
+
else
|
|
20
|
+
return :linux
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def gemload name
|
|
25
|
+
libroot = File.expand_path "../../gems", __FILE__
|
|
26
|
+
$:.unshift Dir[libroot + "/#{name}-*/lib"][0]
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
gemload "rubyzip"
|
|
30
|
+
|
|
31
|
+
puts "Error: No option selected!" unless ARGV.length > 0
|
|
32
|
+
first_arg = ARGV.shift
|
|
33
|
+
|
|
34
|
+
begin
|
|
35
|
+
(puts "recursion is a bad idea idea idea idea"; exit;) if first_arg == 'main'
|
|
36
|
+
require_relative "#{first_arg}"
|
|
37
|
+
rescue LoadError
|
|
38
|
+
puts "Invalid Option: #{first_arg}"
|
|
39
|
+
end
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
# rubyzip
|
|
2
|
+
[](http://badge.fury.io/rb/rubyzip)
|
|
3
|
+
[](http://travis-ci.org/rubyzip/rubyzip)
|
|
4
|
+
[](https://codeclimate.com/github/rubyzip/rubyzip)
|
|
5
|
+
[](https://coveralls.io/r/rubyzip/rubyzip?branch=master)
|
|
6
|
+
|
|
7
|
+
rubyzip is a ruby library for reading and writing zip files.
|
|
8
|
+
|
|
9
|
+
## Important note
|
|
10
|
+
|
|
11
|
+
Rubyzip interface changed!!! No need to do `require "zip/zip"` and `Zip` prefix in class names removed.
|
|
12
|
+
|
|
13
|
+
If you have issues with any third-party gems that require an old version of rubyzip, you can use this workaround:
|
|
14
|
+
|
|
15
|
+
```ruby
|
|
16
|
+
gem 'rubyzip', '>= 1.0.0' # will load new rubyzip version
|
|
17
|
+
gem 'zip-zip' # will load compatibility for old rubyzip API.
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Requirements
|
|
21
|
+
|
|
22
|
+
* Ruby 1.9.2 or greater
|
|
23
|
+
|
|
24
|
+
## Installation
|
|
25
|
+
rubyzip is available on RubyGems, so:
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
gem install rubyzip
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Or in your Gemfile:
|
|
32
|
+
|
|
33
|
+
```ruby
|
|
34
|
+
gem 'rubyzip'
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Usage
|
|
38
|
+
|
|
39
|
+
### Basic zip archive creation
|
|
40
|
+
|
|
41
|
+
```ruby
|
|
42
|
+
require 'rubygems'
|
|
43
|
+
require 'zip'
|
|
44
|
+
|
|
45
|
+
folder = "Users/me/Desktop/stuff_to_zip"
|
|
46
|
+
input_filenames = ['image.jpg', 'description.txt', 'stats.csv']
|
|
47
|
+
|
|
48
|
+
zipfile_name = "/Users/me/Desktop/archive.zip"
|
|
49
|
+
|
|
50
|
+
Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile|
|
|
51
|
+
input_filenames.each do |filename|
|
|
52
|
+
# Two arguments:
|
|
53
|
+
# - The name of the file as it will appear in the archive
|
|
54
|
+
# - The original file, including the path to find it
|
|
55
|
+
zipfile.add(filename, folder + '/' + filename)
|
|
56
|
+
end
|
|
57
|
+
zipfile.get_output_stream("myFile") { |os| os.write "myFile contains just this" }
|
|
58
|
+
end
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Zipping a directory recursively
|
|
62
|
+
Copy from [here](https://github.com/rubyzip/rubyzip/blob/05916bf89181e1955118fd3ea059f18acac28cc8/samples/example_recursive.rb )
|
|
63
|
+
|
|
64
|
+
```ruby
|
|
65
|
+
require 'rubygems'
|
|
66
|
+
require 'zip'
|
|
67
|
+
# This is a simple example which uses rubyzip to
|
|
68
|
+
# recursively generate a zip file from the contents of
|
|
69
|
+
# a specified directory. The directory itself is not
|
|
70
|
+
# included in the archive, rather just its contents.
|
|
71
|
+
#
|
|
72
|
+
# Usage:
|
|
73
|
+
# require /path/to/the/ZipFileGenerator/Class
|
|
74
|
+
# directoryToZip = "/tmp/input"
|
|
75
|
+
# outputFile = "/tmp/out.zip"
|
|
76
|
+
# zf = ZipFileGenerator.new(directoryToZip, outputFile)
|
|
77
|
+
# zf.write()
|
|
78
|
+
|
|
79
|
+
class ZipFileGenerator
|
|
80
|
+
# Initialize with the directory to zip and the location of the output archive.
|
|
81
|
+
def initialize(inputDir, outputFile)
|
|
82
|
+
@inputDir = inputDir
|
|
83
|
+
@outputFile = outputFile
|
|
84
|
+
end
|
|
85
|
+
# Zip the input directory.
|
|
86
|
+
def write()
|
|
87
|
+
entries = Dir.entries(@inputDir); entries.delete("."); entries.delete("..")
|
|
88
|
+
io = Zip::File.open(@outputFile, Zip::File::CREATE);
|
|
89
|
+
writeEntries(entries, "", io)
|
|
90
|
+
io.close();
|
|
91
|
+
end
|
|
92
|
+
# A helper method to make the recursion work.
|
|
93
|
+
private
|
|
94
|
+
def writeEntries(entries, path, io)
|
|
95
|
+
entries.each { |e|
|
|
96
|
+
zipFilePath = path == "" ? e : File.join(path, e)
|
|
97
|
+
diskFilePath = File.join(@inputDir, zipFilePath)
|
|
98
|
+
puts "Deflating " + diskFilePath
|
|
99
|
+
if File.directory?(diskFilePath)
|
|
100
|
+
io.mkdir(zipFilePath)
|
|
101
|
+
subdir =Dir.entries(diskFilePath); subdir.delete("."); subdir.delete("..")
|
|
102
|
+
writeEntries(subdir, zipFilePath, io)
|
|
103
|
+
else
|
|
104
|
+
io.get_output_stream(zipFilePath) { |f| f.print(File.open(diskFilePath, "rb").read())}
|
|
105
|
+
end
|
|
106
|
+
}
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Save zip archive entries in sorted by name state
|
|
112
|
+
|
|
113
|
+
To saving zip archives in sorted order like below you need to set `::Zip.sort_entries` to `true`
|
|
114
|
+
|
|
115
|
+
```
|
|
116
|
+
Vegetable/
|
|
117
|
+
Vegetable/bean
|
|
118
|
+
Vegetable/carrot
|
|
119
|
+
Vegetable/celery
|
|
120
|
+
fruit/
|
|
121
|
+
fruit/apple
|
|
122
|
+
fruit/kiwi
|
|
123
|
+
fruit/mango
|
|
124
|
+
fruit/orange
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
After this entries in zip archive will be saved in ordered state.
|
|
128
|
+
|
|
129
|
+
### Reading a Zip file
|
|
130
|
+
|
|
131
|
+
```ruby
|
|
132
|
+
Zip::File.open('foo.zip') do |zip_file|
|
|
133
|
+
# Handle entries one by one
|
|
134
|
+
zip_file.each do |entry|
|
|
135
|
+
# Extract to file/directory/symlink
|
|
136
|
+
puts "Extracting #{entry.name}"
|
|
137
|
+
entry.extract(dest_file)
|
|
138
|
+
|
|
139
|
+
# Read into memory
|
|
140
|
+
content = entry.get_input_stream.read
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
# Find specific entry
|
|
144
|
+
entry = zip_file.glob('*.csv').first
|
|
145
|
+
puts entry.get_input_stream.read
|
|
146
|
+
end
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Password Protection (Experimental)
|
|
150
|
+
|
|
151
|
+
RubyZip supports reading/writing zip files with traditional zip encryption (a.k.a. "ZipCrypto"). AES encryption is not yet supported. It can be used with buffer streams, e.g.:
|
|
152
|
+
|
|
153
|
+
```ruby
|
|
154
|
+
Zip::OutputStream.write_buffer(::StringIO.new(''), Zip::TraditionalEncrypter.new('password')) do |out|
|
|
155
|
+
out.put_next_entry("my_file.txt")
|
|
156
|
+
out.write my_data
|
|
157
|
+
end.string
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
This is an experimental feature and the interface for encryption may change in future versions.
|
|
161
|
+
|
|
162
|
+
## Known issues
|
|
163
|
+
|
|
164
|
+
### Modify docx file with rubyzip
|
|
165
|
+
|
|
166
|
+
Use `write_buffer` instead `open`. Thanks to @jondruse
|
|
167
|
+
|
|
168
|
+
```ruby
|
|
169
|
+
buffer = Zip::OutputStream.write_buffer do |out|
|
|
170
|
+
@zip_file.entries.each do |e|
|
|
171
|
+
unless [DOCUMENT_FILE_PATH, RELS_FILE_PATH].include?(e.name)
|
|
172
|
+
out.put_next_entry(e.name)
|
|
173
|
+
out.write e.get_input_stream.read
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
out.put_next_entry(DOCUMENT_FILE_PATH)
|
|
178
|
+
out.write xml_doc.to_xml(:indent => 0).gsub("\n","")
|
|
179
|
+
|
|
180
|
+
out.put_next_entry(RELS_FILE_PATH)
|
|
181
|
+
out.write rels.to_xml(:indent => 0).gsub("\n","")
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
File.open(new_path, "w") {|f| f.write(buffer.string) }
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
## Configuration
|
|
188
|
+
|
|
189
|
+
By default, rubyzip will not overwrite files if they already exist inside of the extracted path. To change this behavior, you may specify a configuration option like so:
|
|
190
|
+
|
|
191
|
+
```ruby
|
|
192
|
+
Zip.on_exists_proc = true
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
If you're using rubyzip with rails, consider placing this snippet of code in an initializer file such as `config/initializers/rubyzip.rb`
|
|
196
|
+
|
|
197
|
+
Additionally, if you want to configure rubyzip to overwrite existing files while creating a .zip file, you can do so with the following:
|
|
198
|
+
|
|
199
|
+
```ruby
|
|
200
|
+
Zip.continue_on_exists_proc = true
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
If you want to store non english names and want to open properly file on Windows(pre 7) you need to set next option:
|
|
204
|
+
|
|
205
|
+
```ruby
|
|
206
|
+
Zip.unicode_names = true
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
In some zip date of files stored in incorrect format. You can hide warning about it by using:
|
|
210
|
+
|
|
211
|
+
```ruby
|
|
212
|
+
Zip.warn_invalid_date = false
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
You can set the default compression level like so:
|
|
216
|
+
|
|
217
|
+
```ruby
|
|
218
|
+
Zip.default_compression = Zlib::DEFAULT_COMPRESSION
|
|
219
|
+
```
|
|
220
|
+
It defaults to `Zlib::DEFAULT_COMPRESSION`. Possible values are `Zlib::BEST_COMPRESSION`, `Zlib::DEFAULT_COMPRESSION` and `Zlib::NO_COMPRESSION`
|
|
221
|
+
|
|
222
|
+
All settings in same time
|
|
223
|
+
|
|
224
|
+
```ruby
|
|
225
|
+
Zip.setup do |c|
|
|
226
|
+
c.on_exists_proc = true
|
|
227
|
+
c.continue_on_exists_proc = true
|
|
228
|
+
c.unicode_names = true
|
|
229
|
+
c.default_compression = Zlib::BEST_COMPRESSION
|
|
230
|
+
end
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
By default Zip64 support is disabled for writing. To enable it do next:
|
|
234
|
+
|
|
235
|
+
```ruby
|
|
236
|
+
Zip.write_zip64_support = true
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
_NOTE_: If you will enable Zip64 writing then you will need zip extractor with Zip64 support to extract archive.
|
|
240
|
+
|
|
241
|
+
## Developing
|
|
242
|
+
|
|
243
|
+
To run tests you need run next commands:
|
|
244
|
+
|
|
245
|
+
```
|
|
246
|
+
bundle install
|
|
247
|
+
rake
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
## Website and Project Home
|
|
251
|
+
|
|
252
|
+
http://github.com/rubyzip/rubyzip
|
|
253
|
+
|
|
254
|
+
http://rdoc.info/github/rubyzip/rubyzip/master/frames
|
|
255
|
+
|
|
256
|
+
## Authors
|
|
257
|
+
|
|
258
|
+
Alexander Simonov ( alex at simonov.me)
|
|
259
|
+
|
|
260
|
+
Alan Harper ( alan at aussiegeek.net)
|
|
261
|
+
|
|
262
|
+
Thomas Sondergaard (thomas at sondergaard.cc)
|
|
263
|
+
|
|
264
|
+
Technorama Ltd. (oss-ruby-zip at technorama.net)
|
|
265
|
+
|
|
266
|
+
extra-field support contributed by Tatsuki Sugiura (sugi at nemui.org)
|
|
267
|
+
|
|
268
|
+
## License
|
|
269
|
+
|
|
270
|
+
rubyzip is distributed under the same license as ruby. See
|
|
271
|
+
http://www.ruby-lang.org/en/LICENSE.txt
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require 'bundler/gem_tasks'
|
|
2
|
+
require 'rake/testtask'
|
|
3
|
+
|
|
4
|
+
task :default => :test
|
|
5
|
+
|
|
6
|
+
Rake::TestTask.new(:test) do |test|
|
|
7
|
+
test.libs << 'lib'
|
|
8
|
+
test.libs << 'test'
|
|
9
|
+
test.pattern = 'test/**/*_test.rb'
|
|
10
|
+
test.verbose = true
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
#Rake::TestTask.new(:zip64_full_test) do |test|
|
|
14
|
+
# test.libs << File.join(File.dirname(__FILE__), 'lib')
|
|
15
|
+
# test.libs << File.join(File.dirname(__FILE__), 'test')
|
|
16
|
+
# test.pattern = File.join(File.dirname(__FILE__), 'test/zip64_full_test.rb')
|
|
17
|
+
# test.verbose = true
|
|
18
|
+
#end
|
|
19
|
+
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
|
|
2
|
+
* ZipInputStream: Support zip-files with trailing data descriptors
|
|
3
|
+
* Adjust rdoc stylesheet to advertise inherited methods if possible
|
|
4
|
+
* Suggestion: Add ZipFile/ZipInputStream example that demonstrates extracting all entries.
|
|
5
|
+
* Suggestion: ZipFile#extract destination should default to "."
|
|
6
|
+
* Suggestion: ZipEntry should have extract(), get_input_stream() methods etc
|
|
7
|
+
* (is buffering used anywhere with write?)
|
|
8
|
+
* Inflater.sysread should pass the buffer to produce_input.
|
|
9
|
+
* Implement ZipFsDir.glob
|
|
10
|
+
* ZipFile.checkIntegrity method
|
|
11
|
+
* non-MSDOS permission attributes
|
|
12
|
+
** See mail from Ned Konz to ruby-talk subj. "Re: SV: [ANN] Archive 0.2"
|
|
13
|
+
* Packager version, required unpacker version in zip headers
|
|
14
|
+
** See mail from Ned Konz to ruby-talk subj. "Re: SV: [ANN] Archive 0.2"
|
|
15
|
+
* implement storing attributes and ownership information
|