vagrant-unbundled 2.2.6.1 → 2.2.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +11 -9
- data/vagrant.gemspec +1 -1
- data/vendor/bundle/ruby/2.6.0/bundler/gems/vagrant-spec-abfc34474d12/vagrant-spec.gemspec +1 -1
- data/vendor/bundle/ruby/2.6.0/gems/erubi-1.9.0/CHANGELOG +79 -0
- data/vendor/bundle/ruby/2.6.0/gems/erubi-1.9.0/MIT-LICENSE +21 -0
- data/vendor/bundle/ruby/2.6.0/gems/erubi-1.9.0/README.rdoc +109 -0
- data/vendor/bundle/ruby/2.6.0/gems/erubi-1.9.0/Rakefile +78 -0
- data/vendor/bundle/ruby/2.6.0/gems/erubi-1.9.0/lib/erubi/capture_end.rb +52 -0
- data/vendor/bundle/ruby/2.6.0/gems/erubi-1.9.0/lib/erubi.rb +211 -0
- data/vendor/bundle/ruby/2.6.0/gems/erubi-1.9.0/test/test.rb +780 -0
- data/vendor/bundle/ruby/2.6.0/gems/rubyzip-2.0.0/README.md +354 -0
- data/vendor/bundle/ruby/2.6.0/gems/rubyzip-2.0.0/Rakefile +18 -0
- data/vendor/bundle/ruby/2.6.0/gems/rubyzip-2.0.0/TODO +15 -0
- data/vendor/bundle/ruby/2.6.0/gems/rubyzip-2.0.0/lib/zip/central_directory.rb +208 -0
- data/vendor/bundle/ruby/2.6.0/gems/rubyzip-2.0.0/lib/zip/compressor.rb +9 -0
- data/vendor/bundle/ruby/2.6.0/gems/rubyzip-2.0.0/lib/zip/constants.rb +63 -0
- data/vendor/bundle/ruby/2.6.0/gems/rubyzip-2.0.0/lib/zip/crypto/encryption.rb +11 -0
- data/vendor/bundle/ruby/2.6.0/gems/rubyzip-2.0.0/lib/zip/crypto/null_encryption.rb +43 -0
- data/vendor/bundle/ruby/2.6.0/gems/rubyzip-2.0.0/lib/zip/crypto/traditional_encryption.rb +99 -0
- data/vendor/bundle/ruby/2.6.0/gems/rubyzip-2.0.0/lib/zip/decompressor.rb +13 -0
- data/vendor/bundle/ruby/2.6.0/gems/rubyzip-2.0.0/lib/zip/deflater.rb +34 -0
- data/vendor/bundle/ruby/2.6.0/gems/rubyzip-2.0.0/lib/zip/dos_time.rb +48 -0
- data/vendor/bundle/ruby/2.6.0/gems/rubyzip-2.0.0/lib/zip/entry.rb +700 -0
- data/vendor/bundle/ruby/2.6.0/gems/rubyzip-2.0.0/lib/zip/entry_set.rb +86 -0
- data/vendor/bundle/ruby/2.6.0/gems/rubyzip-2.0.0/lib/zip/errors.rb +18 -0
- data/vendor/bundle/ruby/2.6.0/gems/rubyzip-2.0.0/lib/zip/extra_field/generic.rb +43 -0
- data/vendor/bundle/ruby/2.6.0/gems/rubyzip-2.0.0/lib/zip/extra_field/ntfs.rb +90 -0
- data/vendor/bundle/ruby/2.6.0/gems/rubyzip-2.0.0/lib/zip/extra_field/old_unix.rb +44 -0
- data/vendor/bundle/ruby/2.6.0/gems/rubyzip-2.0.0/lib/zip/extra_field/universal_time.rb +47 -0
- data/vendor/bundle/ruby/2.6.0/gems/rubyzip-2.0.0/lib/zip/extra_field/unix.rb +37 -0
- data/vendor/bundle/ruby/2.6.0/gems/rubyzip-2.0.0/lib/zip/extra_field/zip64.rb +68 -0
- data/vendor/bundle/ruby/2.6.0/gems/rubyzip-2.0.0/lib/zip/extra_field/zip64_placeholder.rb +15 -0
- data/vendor/bundle/ruby/2.6.0/gems/rubyzip-2.0.0/lib/zip/extra_field.rb +101 -0
- data/vendor/bundle/ruby/2.6.0/gems/rubyzip-2.0.0/lib/zip/file.rb +443 -0
- data/vendor/bundle/ruby/2.6.0/gems/rubyzip-2.0.0/lib/zip/filesystem.rb +627 -0
- data/vendor/bundle/ruby/2.6.0/gems/rubyzip-2.0.0/lib/zip/inflater.rb +66 -0
- data/vendor/bundle/ruby/2.6.0/gems/rubyzip-2.0.0/lib/zip/input_stream.rb +173 -0
- data/vendor/bundle/ruby/2.6.0/gems/rubyzip-2.0.0/lib/zip/ioextras/abstract_input_stream.rb +111 -0
- data/vendor/bundle/ruby/2.6.0/gems/rubyzip-2.0.0/lib/zip/ioextras/abstract_output_stream.rb +43 -0
- data/vendor/bundle/ruby/2.6.0/gems/rubyzip-2.0.0/lib/zip/ioextras.rb +36 -0
- data/vendor/bundle/ruby/2.6.0/gems/rubyzip-2.0.0/lib/zip/null_compressor.rb +15 -0
- data/vendor/bundle/ruby/2.6.0/gems/rubyzip-2.0.0/lib/zip/null_decompressor.rb +27 -0
- data/vendor/bundle/ruby/2.6.0/gems/rubyzip-2.0.0/lib/zip/null_input_stream.rb +10 -0
- data/vendor/bundle/ruby/2.6.0/gems/rubyzip-2.0.0/lib/zip/output_stream.rb +189 -0
- data/vendor/bundle/ruby/2.6.0/gems/rubyzip-2.0.0/lib/zip/pass_thru_compressor.rb +23 -0
- data/vendor/bundle/ruby/2.6.0/gems/rubyzip-2.0.0/lib/zip/pass_thru_decompressor.rb +40 -0
- data/vendor/bundle/ruby/2.6.0/gems/rubyzip-2.0.0/lib/zip/streamable_directory.rb +15 -0
- data/vendor/bundle/ruby/2.6.0/gems/rubyzip-2.0.0/lib/zip/streamable_stream.rb +56 -0
- data/vendor/bundle/ruby/2.6.0/gems/rubyzip-2.0.0/lib/zip/version.rb +3 -0
- data/vendor/bundle/ruby/2.6.0/gems/rubyzip-2.0.0/lib/zip.rb +71 -0
- data/vendor/bundle/ruby/2.6.0/gems/rubyzip-2.0.0/samples/example.rb +81 -0
- data/vendor/bundle/ruby/2.6.0/gems/rubyzip-2.0.0/samples/example_filesystem.rb +31 -0
- data/vendor/bundle/ruby/2.6.0/gems/rubyzip-2.0.0/samples/example_recursive.rb +54 -0
- data/vendor/bundle/ruby/2.6.0/gems/rubyzip-2.0.0/samples/gtk_ruby_zip.rb +84 -0
- data/vendor/bundle/ruby/2.6.0/gems/rubyzip-2.0.0/samples/qtzip.rb +92 -0
- data/vendor/bundle/ruby/2.6.0/gems/rubyzip-2.0.0/samples/write_simple.rb +12 -0
- data/vendor/bundle/ruby/2.6.0/gems/rubyzip-2.0.0/samples/zipfind.rb +66 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-2.3.3/LICENSE +202 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-2.3.3/README.md +276 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-2.3.3/bin/rwinrm +90 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-2.3.3/lib/winrm/connection.rb +84 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-2.3.3/lib/winrm/connection_opts.rb +90 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-2.3.3/lib/winrm/exceptions.rb +88 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-2.3.3/lib/winrm/http/response_handler.rb +127 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-2.3.3/lib/winrm/http/transport.rb +462 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-2.3.3/lib/winrm/http/transport_factory.rb +64 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-2.3.3/lib/winrm/output.rb +58 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-2.3.3/lib/winrm/psrp/create_pipeline.xml.erb +167 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-2.3.3/lib/winrm/psrp/fragment.rb +68 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-2.3.3/lib/winrm/psrp/init_runspace_pool.xml.erb +224 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-2.3.3/lib/winrm/psrp/message.rb +128 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-2.3.3/lib/winrm/psrp/message_data/base.rb +47 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-2.3.3/lib/winrm/psrp/message_data/error_record.rb +66 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-2.3.3/lib/winrm/psrp/message_data/pipeline_host_call.rb +30 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-2.3.3/lib/winrm/psrp/message_data/pipeline_output.rb +48 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-2.3.3/lib/winrm/psrp/message_data/pipeline_state.rb +38 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-2.3.3/lib/winrm/psrp/message_data/runspacepool_host_call.rb +30 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-2.3.3/lib/winrm/psrp/message_data/runspacepool_state.rb +37 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-2.3.3/lib/winrm/psrp/message_data/session_capability.rb +34 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-2.3.3/lib/winrm/psrp/message_data.rb +40 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-2.3.3/lib/winrm/psrp/message_defragmenter.rb +62 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-2.3.3/lib/winrm/psrp/message_factory.rb +86 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-2.3.3/lib/winrm/psrp/message_fragmenter.rb +58 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-2.3.3/lib/winrm/psrp/powershell_output_decoder.rb +142 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-2.3.3/lib/winrm/psrp/receive_response_reader.rb +95 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-2.3.3/lib/winrm/psrp/session_capability.xml.erb +7 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-2.3.3/lib/winrm/psrp/uuid.rb +39 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-2.3.3/lib/winrm/shells/base.rb +187 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-2.3.3/lib/winrm/shells/cmd.rb +63 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-2.3.3/lib/winrm/shells/power_shell.rb +206 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-2.3.3/lib/winrm/shells/retryable.rb +44 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-2.3.3/lib/winrm/shells/shell_factory.rb +56 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-2.3.3/lib/winrm/version.rb +5 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-2.3.3/lib/winrm/wsmv/base.rb +57 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-2.3.3/lib/winrm/wsmv/cleanup_command.rb +60 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-2.3.3/lib/winrm/wsmv/close_shell.rb +49 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-2.3.3/lib/winrm/wsmv/command.rb +100 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-2.3.3/lib/winrm/wsmv/command_output.rb +75 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-2.3.3/lib/winrm/wsmv/command_output_decoder.rb +54 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-2.3.3/lib/winrm/wsmv/configuration.rb +44 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-2.3.3/lib/winrm/wsmv/create_pipeline.rb +64 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-2.3.3/lib/winrm/wsmv/create_shell.rb +115 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-2.3.3/lib/winrm/wsmv/header.rb +213 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-2.3.3/lib/winrm/wsmv/init_runspace_pool.rb +96 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-2.3.3/lib/winrm/wsmv/iso8601_duration.rb +58 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-2.3.3/lib/winrm/wsmv/keep_alive.rb +66 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-2.3.3/lib/winrm/wsmv/receive_response_reader.rb +128 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-2.3.3/lib/winrm/wsmv/send_data.rb +66 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-2.3.3/lib/winrm/wsmv/soap.rb +49 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-2.3.3/lib/winrm/wsmv/wql_pull.rb +54 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-2.3.3/lib/winrm/wsmv/wql_query.rb +98 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-2.3.3/lib/winrm/wsmv/write_stdin.rb +86 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-2.3.3/lib/winrm.rb +37 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-elevated-1.1.2/LICENSE +202 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-elevated-1.1.2/README.md +99 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-elevated-1.1.2/lib/winrm/shells/elevated.rb +108 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-elevated-1.1.2/lib/winrm-elevated/scripts/elevated_shell.ps1 +116 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-elevated-1.1.2/lib/winrm-elevated.rb +17 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-fs-1.3.4/LICENSE +202 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-fs-1.3.4/README.md +82 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-fs-1.3.4/bin/rwinrmcp +87 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-fs-1.3.4/lib/winrm-fs/core/file_transporter.rb +569 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-fs-1.3.4/lib/winrm-fs/core/tmp_zip.rb +178 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-fs-1.3.4/lib/winrm-fs/exceptions.rb +29 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-fs-1.3.4/lib/winrm-fs/file_manager.rb +158 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-fs-1.3.4/lib/winrm-fs/scripts/check_files.ps1.erb +49 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-fs-1.3.4/lib/winrm-fs/scripts/checksum.ps1.erb +13 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-fs-1.3.4/lib/winrm-fs/scripts/create_dir.ps1.erb +6 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-fs-1.3.4/lib/winrm-fs/scripts/delete.ps1.erb +6 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-fs-1.3.4/lib/winrm-fs/scripts/download.ps1.erb +17 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-fs-1.3.4/lib/winrm-fs/scripts/exists.ps1.erb +10 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-fs-1.3.4/lib/winrm-fs/scripts/extract_files.ps1.erb +52 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-fs-1.3.4/lib/winrm-fs/scripts/scripts.rb +47 -0
- data/vendor/bundle/ruby/2.6.0/gems/winrm-fs-1.3.4/lib/winrm-fs.rb +29 -0
- data/vendor/bundle/ruby/2.6.0/specifications/erubi-1.9.0.gemspec +38 -0
- data/vendor/bundle/ruby/2.6.0/specifications/rubyzip-2.0.0.gemspec +45 -0
- data/vendor/bundle/ruby/2.6.0/specifications/winrm-2.3.3.gemspec +73 -0
- data/vendor/bundle/ruby/2.6.0/specifications/winrm-elevated-1.1.2.gemspec +50 -0
- data/vendor/bundle/ruby/2.6.0/specifications/winrm-fs-1.3.4.gemspec +58 -0
- data/version.txt +1 -1
- metadata +142 -6
@@ -0,0 +1,443 @@
|
|
1
|
+
module Zip
|
2
|
+
# ZipFile is modeled after java.util.zip.ZipFile from the Java SDK.
|
3
|
+
# The most important methods are those inherited from
|
4
|
+
# ZipCentralDirectory for accessing information about the entries in
|
5
|
+
# the archive and methods such as get_input_stream and
|
6
|
+
# get_output_stream for reading from and writing entries to the
|
7
|
+
# archive. The class includes a few convenience methods such as
|
8
|
+
# #extract for extracting entries to the filesystem, and #remove,
|
9
|
+
# #replace, #rename and #mkdir for making simple modifications to
|
10
|
+
# the archive.
|
11
|
+
#
|
12
|
+
# Modifications to a zip archive are not committed until #commit or
|
13
|
+
# #close is called. The method #open accepts a block following
|
14
|
+
# the pattern from File.open offering a simple way to
|
15
|
+
# automatically close the archive when the block returns.
|
16
|
+
#
|
17
|
+
# The following example opens zip archive <code>my.zip</code>
|
18
|
+
# (creating it if it doesn't exist) and adds an entry
|
19
|
+
# <code>first.txt</code> and a directory entry <code>a_dir</code>
|
20
|
+
# to it.
|
21
|
+
#
|
22
|
+
# require 'zip'
|
23
|
+
#
|
24
|
+
# Zip::File.open("my.zip", Zip::File::CREATE) {
|
25
|
+
# |zipfile|
|
26
|
+
# zipfile.get_output_stream("first.txt") { |f| f.puts "Hello from ZipFile" }
|
27
|
+
# zipfile.mkdir("a_dir")
|
28
|
+
# }
|
29
|
+
#
|
30
|
+
# The next example reopens <code>my.zip</code> writes the contents of
|
31
|
+
# <code>first.txt</code> to standard out and deletes the entry from
|
32
|
+
# the archive.
|
33
|
+
#
|
34
|
+
# require 'zip'
|
35
|
+
#
|
36
|
+
# Zip::File.open("my.zip", Zip::File::CREATE) {
|
37
|
+
# |zipfile|
|
38
|
+
# puts zipfile.read("first.txt")
|
39
|
+
# zipfile.remove("first.txt")
|
40
|
+
# }
|
41
|
+
#
|
42
|
+
# ZipFileSystem offers an alternative API that emulates ruby's
|
43
|
+
# interface for accessing the filesystem, ie. the File and Dir classes.
|
44
|
+
|
45
|
+
class File < CentralDirectory
|
46
|
+
CREATE = true
|
47
|
+
SPLIT_SIGNATURE = 0x08074b50
|
48
|
+
ZIP64_EOCD_SIGNATURE = 0x06064b50
|
49
|
+
MAX_SEGMENT_SIZE = 3_221_225_472
|
50
|
+
MIN_SEGMENT_SIZE = 65_536
|
51
|
+
DATA_BUFFER_SIZE = 8192
|
52
|
+
IO_METHODS = [:tell, :seek, :read, :close]
|
53
|
+
|
54
|
+
attr_reader :name
|
55
|
+
|
56
|
+
# default -> false
|
57
|
+
attr_accessor :restore_ownership
|
58
|
+
# default -> false
|
59
|
+
attr_accessor :restore_permissions
|
60
|
+
# default -> true
|
61
|
+
attr_accessor :restore_times
|
62
|
+
# Returns the zip files comment, if it has one
|
63
|
+
attr_accessor :comment
|
64
|
+
|
65
|
+
# Opens a zip archive. Pass true as the second parameter to create
|
66
|
+
# a new archive if it doesn't exist already.
|
67
|
+
def initialize(path_or_io, create = false, buffer = false, options = {})
|
68
|
+
super()
|
69
|
+
@name = path_or_io.respond_to?(:path) ? path_or_io.path : path_or_io
|
70
|
+
@comment = ''
|
71
|
+
@create = create ? true : false # allow any truthy value to mean true
|
72
|
+
|
73
|
+
if ::File.size?(@name.to_s)
|
74
|
+
# There is a file, which exists, that is associated with this zip.
|
75
|
+
@create = false
|
76
|
+
@file_permissions = ::File.stat(@name).mode
|
77
|
+
|
78
|
+
if buffer
|
79
|
+
read_from_stream(path_or_io)
|
80
|
+
else
|
81
|
+
::File.open(@name, 'rb') do |f|
|
82
|
+
read_from_stream(f)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
elsif buffer && path_or_io.size > 0
|
86
|
+
# This zip is probably a non-empty StringIO.
|
87
|
+
read_from_stream(path_or_io)
|
88
|
+
elsif @create
|
89
|
+
# This zip is completely new/empty and is to be created.
|
90
|
+
@entry_set = EntrySet.new
|
91
|
+
elsif ::File.zero?(@name)
|
92
|
+
# A file exists, but it is empty.
|
93
|
+
raise Error, "File #{@name} has zero size. Did you mean to pass the create flag?"
|
94
|
+
else
|
95
|
+
# Everything is wrong.
|
96
|
+
raise Error, "File #{@name} not found"
|
97
|
+
end
|
98
|
+
|
99
|
+
@stored_entries = @entry_set.dup
|
100
|
+
@stored_comment = @comment
|
101
|
+
@restore_ownership = options[:restore_ownership] || false
|
102
|
+
@restore_permissions = options[:restore_permissions] || true
|
103
|
+
@restore_times = options[:restore_times] || true
|
104
|
+
end
|
105
|
+
|
106
|
+
class << self
|
107
|
+
# Same as #new. If a block is passed the ZipFile object is passed
|
108
|
+
# to the block and is automatically closed afterwards just as with
|
109
|
+
# ruby's builtin File.open method.
|
110
|
+
def open(file_name, create = false)
|
111
|
+
zf = ::Zip::File.new(file_name, create)
|
112
|
+
return zf unless block_given?
|
113
|
+
begin
|
114
|
+
yield zf
|
115
|
+
ensure
|
116
|
+
zf.close
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
# Same as #open. But outputs data to a buffer instead of a file
|
121
|
+
def add_buffer
|
122
|
+
io = ::StringIO.new('')
|
123
|
+
zf = ::Zip::File.new(io, true, true)
|
124
|
+
yield zf
|
125
|
+
zf.write_buffer(io)
|
126
|
+
end
|
127
|
+
|
128
|
+
# Like #open, but reads zip archive contents from a String or open IO
|
129
|
+
# stream, and outputs data to a buffer.
|
130
|
+
# (This can be used to extract data from a
|
131
|
+
# downloaded zip archive without first saving it to disk.)
|
132
|
+
def open_buffer(io, options = {})
|
133
|
+
unless IO_METHODS.map { |method| io.respond_to?(method) }.all? || io.is_a?(String)
|
134
|
+
raise "Zip::File.open_buffer expects a String or IO-like argument (responds to #{IO_METHODS.join(', ')}). Found: #{io.class}"
|
135
|
+
end
|
136
|
+
|
137
|
+
io = ::StringIO.new(io) if io.is_a?(::String)
|
138
|
+
|
139
|
+
# https://github.com/rubyzip/rubyzip/issues/119
|
140
|
+
io.binmode if io.respond_to?(:binmode)
|
141
|
+
|
142
|
+
zf = ::Zip::File.new(io, true, true, options)
|
143
|
+
return zf unless block_given?
|
144
|
+
yield zf
|
145
|
+
|
146
|
+
begin
|
147
|
+
zf.write_buffer(io)
|
148
|
+
rescue IOError => e
|
149
|
+
raise unless e.message == 'not opened for writing'
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
# Iterates over the contents of the ZipFile. This is more efficient
|
154
|
+
# than using a ZipInputStream since this methods simply iterates
|
155
|
+
# through the entries in the central directory structure in the archive
|
156
|
+
# whereas ZipInputStream jumps through the entire archive accessing the
|
157
|
+
# local entry headers (which contain the same information as the
|
158
|
+
# central directory).
|
159
|
+
def foreach(aZipFileName, &block)
|
160
|
+
open(aZipFileName) do |zipFile|
|
161
|
+
zipFile.each(&block)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
def get_segment_size_for_split(segment_size)
|
166
|
+
if MIN_SEGMENT_SIZE > segment_size
|
167
|
+
MIN_SEGMENT_SIZE
|
168
|
+
elsif MAX_SEGMENT_SIZE < segment_size
|
169
|
+
MAX_SEGMENT_SIZE
|
170
|
+
else
|
171
|
+
segment_size
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
def get_partial_zip_file_name(zip_file_name, partial_zip_file_name)
|
176
|
+
unless partial_zip_file_name.nil?
|
177
|
+
partial_zip_file_name = zip_file_name.sub(/#{::File.basename(zip_file_name)}\z/,
|
178
|
+
partial_zip_file_name + ::File.extname(zip_file_name))
|
179
|
+
end
|
180
|
+
partial_zip_file_name ||= zip_file_name
|
181
|
+
partial_zip_file_name
|
182
|
+
end
|
183
|
+
|
184
|
+
def get_segment_count_for_split(zip_file_size, segment_size)
|
185
|
+
(zip_file_size / segment_size).to_i + (zip_file_size % segment_size == 0 ? 0 : 1)
|
186
|
+
end
|
187
|
+
|
188
|
+
def put_split_signature(szip_file, segment_size)
|
189
|
+
signature_packed = [SPLIT_SIGNATURE].pack('V')
|
190
|
+
szip_file << signature_packed
|
191
|
+
segment_size - signature_packed.size
|
192
|
+
end
|
193
|
+
|
194
|
+
#
|
195
|
+
# TODO: Make the code more understandable
|
196
|
+
#
|
197
|
+
def save_splited_part(zip_file, partial_zip_file_name, zip_file_size, szip_file_index, segment_size, segment_count)
|
198
|
+
ssegment_size = zip_file_size - zip_file.pos
|
199
|
+
ssegment_size = segment_size if ssegment_size > segment_size
|
200
|
+
szip_file_name = "#{partial_zip_file_name}.#{format('%03d', szip_file_index)}"
|
201
|
+
::File.open(szip_file_name, 'wb') do |szip_file|
|
202
|
+
if szip_file_index == 1
|
203
|
+
ssegment_size = put_split_signature(szip_file, segment_size)
|
204
|
+
end
|
205
|
+
chunk_bytes = 0
|
206
|
+
until ssegment_size == chunk_bytes || zip_file.eof?
|
207
|
+
segment_bytes_left = ssegment_size - chunk_bytes
|
208
|
+
buffer_size = segment_bytes_left < DATA_BUFFER_SIZE ? segment_bytes_left : DATA_BUFFER_SIZE
|
209
|
+
chunk = zip_file.read(buffer_size)
|
210
|
+
chunk_bytes += buffer_size
|
211
|
+
szip_file << chunk
|
212
|
+
# Info for track splitting
|
213
|
+
yield segment_count, szip_file_index, chunk_bytes, ssegment_size if block_given?
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
# Splits an archive into parts with segment size
|
219
|
+
def split(zip_file_name, segment_size = MAX_SEGMENT_SIZE, delete_zip_file = true, partial_zip_file_name = nil)
|
220
|
+
raise Error, "File #{zip_file_name} not found" unless ::File.exist?(zip_file_name)
|
221
|
+
raise Errno::ENOENT, zip_file_name unless ::File.readable?(zip_file_name)
|
222
|
+
zip_file_size = ::File.size(zip_file_name)
|
223
|
+
segment_size = get_segment_size_for_split(segment_size)
|
224
|
+
return if zip_file_size <= segment_size
|
225
|
+
segment_count = get_segment_count_for_split(zip_file_size, segment_size)
|
226
|
+
# Checking for correct zip structure
|
227
|
+
open(zip_file_name) {}
|
228
|
+
partial_zip_file_name = get_partial_zip_file_name(zip_file_name, partial_zip_file_name)
|
229
|
+
szip_file_index = 0
|
230
|
+
::File.open(zip_file_name, 'rb') do |zip_file|
|
231
|
+
until zip_file.eof?
|
232
|
+
szip_file_index += 1
|
233
|
+
save_splited_part(zip_file, partial_zip_file_name, zip_file_size, szip_file_index, segment_size, segment_count)
|
234
|
+
end
|
235
|
+
end
|
236
|
+
::File.delete(zip_file_name) if delete_zip_file
|
237
|
+
szip_file_index
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
# Returns an input stream to the specified entry. If a block is passed
|
242
|
+
# the stream object is passed to the block and the stream is automatically
|
243
|
+
# closed afterwards just as with ruby's builtin File.open method.
|
244
|
+
def get_input_stream(entry, &aProc)
|
245
|
+
get_entry(entry).get_input_stream(&aProc)
|
246
|
+
end
|
247
|
+
|
248
|
+
# Returns an output stream to the specified entry. If entry is not an instance
|
249
|
+
# of Zip::Entry, a new Zip::Entry will be initialized using the arguments
|
250
|
+
# specified. If a block is passed the stream object is passed to the block and
|
251
|
+
# the stream is automatically closed afterwards just as with ruby's builtin
|
252
|
+
# File.open method.
|
253
|
+
def get_output_stream(entry, permission_int = nil, comment = nil, extra = nil, compressed_size = nil, crc = nil, compression_method = nil, size = nil, time = nil, &aProc)
|
254
|
+
new_entry =
|
255
|
+
if entry.kind_of?(Entry)
|
256
|
+
entry
|
257
|
+
else
|
258
|
+
Entry.new(@name, entry.to_s, comment, extra, compressed_size, crc, compression_method, size, time)
|
259
|
+
end
|
260
|
+
if new_entry.directory?
|
261
|
+
raise ArgumentError,
|
262
|
+
"cannot open stream to directory entry - '#{new_entry}'"
|
263
|
+
end
|
264
|
+
new_entry.unix_perms = permission_int
|
265
|
+
zip_streamable_entry = StreamableStream.new(new_entry)
|
266
|
+
@entry_set << zip_streamable_entry
|
267
|
+
zip_streamable_entry.get_output_stream(&aProc)
|
268
|
+
end
|
269
|
+
|
270
|
+
# Returns the name of the zip archive
|
271
|
+
def to_s
|
272
|
+
@name
|
273
|
+
end
|
274
|
+
|
275
|
+
# Returns a string containing the contents of the specified entry
|
276
|
+
def read(entry)
|
277
|
+
get_input_stream(entry) { |is| is.read }
|
278
|
+
end
|
279
|
+
|
280
|
+
# Convenience method for adding the contents of a file to the archive
|
281
|
+
def add(entry, src_path, &continue_on_exists_proc)
|
282
|
+
continue_on_exists_proc ||= proc { ::Zip.continue_on_exists_proc }
|
283
|
+
check_entry_exists(entry, continue_on_exists_proc, 'add')
|
284
|
+
new_entry = entry.kind_of?(::Zip::Entry) ? entry : ::Zip::Entry.new(@name, entry.to_s)
|
285
|
+
new_entry.gather_fileinfo_from_srcpath(src_path)
|
286
|
+
new_entry.dirty = true
|
287
|
+
@entry_set << new_entry
|
288
|
+
end
|
289
|
+
|
290
|
+
# Convenience method for adding the contents of a file to the archive
|
291
|
+
# in Stored format (uncompressed)
|
292
|
+
def add_stored(entry, src_path, &continue_on_exists_proc)
|
293
|
+
entry = ::Zip::Entry.new(@name, entry.to_s, nil, nil, nil, nil, ::Zip::Entry::STORED)
|
294
|
+
add(entry, src_path, &continue_on_exists_proc)
|
295
|
+
end
|
296
|
+
|
297
|
+
# Removes the specified entry.
|
298
|
+
def remove(entry)
|
299
|
+
@entry_set.delete(get_entry(entry))
|
300
|
+
end
|
301
|
+
|
302
|
+
# Renames the specified entry.
|
303
|
+
def rename(entry, new_name, &continue_on_exists_proc)
|
304
|
+
foundEntry = get_entry(entry)
|
305
|
+
check_entry_exists(new_name, continue_on_exists_proc, 'rename')
|
306
|
+
@entry_set.delete(foundEntry)
|
307
|
+
foundEntry.name = new_name
|
308
|
+
@entry_set << foundEntry
|
309
|
+
end
|
310
|
+
|
311
|
+
# Replaces the specified entry with the contents of srcPath (from
|
312
|
+
# the file system).
|
313
|
+
def replace(entry, srcPath)
|
314
|
+
check_file(srcPath)
|
315
|
+
remove(entry)
|
316
|
+
add(entry, srcPath)
|
317
|
+
end
|
318
|
+
|
319
|
+
# Extracts entry to file dest_path.
|
320
|
+
def extract(entry, dest_path, &block)
|
321
|
+
block ||= proc { ::Zip.on_exists_proc }
|
322
|
+
found_entry = get_entry(entry)
|
323
|
+
found_entry.extract(dest_path, &block)
|
324
|
+
end
|
325
|
+
|
326
|
+
# Commits changes that has been made since the previous commit to
|
327
|
+
# the zip archive.
|
328
|
+
def commit
|
329
|
+
return if name.is_a?(StringIO) || !commit_required?
|
330
|
+
on_success_replace do |tmp_file|
|
331
|
+
::Zip::OutputStream.open(tmp_file) do |zos|
|
332
|
+
@entry_set.each do |e|
|
333
|
+
e.write_to_zip_output_stream(zos)
|
334
|
+
e.dirty = false
|
335
|
+
e.clean_up
|
336
|
+
end
|
337
|
+
zos.comment = comment
|
338
|
+
end
|
339
|
+
true
|
340
|
+
end
|
341
|
+
initialize(name)
|
342
|
+
end
|
343
|
+
|
344
|
+
# Write buffer write changes to buffer and return
|
345
|
+
def write_buffer(io = ::StringIO.new(''))
|
346
|
+
::Zip::OutputStream.write_buffer(io) do |zos|
|
347
|
+
@entry_set.each { |e| e.write_to_zip_output_stream(zos) }
|
348
|
+
zos.comment = comment
|
349
|
+
end
|
350
|
+
end
|
351
|
+
|
352
|
+
# Closes the zip file committing any changes that has been made.
|
353
|
+
def close
|
354
|
+
commit
|
355
|
+
end
|
356
|
+
|
357
|
+
# Returns true if any changes has been made to this archive since
|
358
|
+
# the previous commit
|
359
|
+
def commit_required?
|
360
|
+
@entry_set.each do |e|
|
361
|
+
return true if e.dirty
|
362
|
+
end
|
363
|
+
@comment != @stored_comment || @entry_set != @stored_entries || @create
|
364
|
+
end
|
365
|
+
|
366
|
+
# Searches for entry with the specified name. Returns nil if
|
367
|
+
# no entry is found. See also get_entry
|
368
|
+
def find_entry(entry_name)
|
369
|
+
@entry_set.find_entry(entry_name)
|
370
|
+
end
|
371
|
+
|
372
|
+
# Searches for entries given a glob
|
373
|
+
def glob(*args, &block)
|
374
|
+
@entry_set.glob(*args, &block)
|
375
|
+
end
|
376
|
+
|
377
|
+
# Searches for an entry just as find_entry, but throws Errno::ENOENT
|
378
|
+
# if no entry is found.
|
379
|
+
def get_entry(entry)
|
380
|
+
selected_entry = find_entry(entry)
|
381
|
+
raise Errno::ENOENT, entry unless selected_entry
|
382
|
+
selected_entry.restore_ownership = @restore_ownership
|
383
|
+
selected_entry.restore_permissions = @restore_permissions
|
384
|
+
selected_entry.restore_times = @restore_times
|
385
|
+
selected_entry
|
386
|
+
end
|
387
|
+
|
388
|
+
# Creates a directory
|
389
|
+
def mkdir(entryName, permissionInt = 0o755)
|
390
|
+
raise Errno::EEXIST, "File exists - #{entryName}" if find_entry(entryName)
|
391
|
+
entryName = entryName.dup.to_s
|
392
|
+
entryName << '/' unless entryName.end_with?('/')
|
393
|
+
@entry_set << ::Zip::StreamableDirectory.new(@name, entryName, nil, permissionInt)
|
394
|
+
end
|
395
|
+
|
396
|
+
private
|
397
|
+
|
398
|
+
def directory?(newEntry, srcPath)
|
399
|
+
srcPathIsDirectory = ::File.directory?(srcPath)
|
400
|
+
if newEntry.directory? && !srcPathIsDirectory
|
401
|
+
raise ArgumentError,
|
402
|
+
"entry name '#{newEntry}' indicates directory entry, but " \
|
403
|
+
"'#{srcPath}' is not a directory"
|
404
|
+
elsif !newEntry.directory? && srcPathIsDirectory
|
405
|
+
newEntry.name += '/'
|
406
|
+
end
|
407
|
+
newEntry.directory? && srcPathIsDirectory
|
408
|
+
end
|
409
|
+
|
410
|
+
def check_entry_exists(entryName, continue_on_exists_proc, procedureName)
|
411
|
+
continue_on_exists_proc ||= proc { Zip.continue_on_exists_proc }
|
412
|
+
return unless @entry_set.include?(entryName)
|
413
|
+
if continue_on_exists_proc.call
|
414
|
+
remove get_entry(entryName)
|
415
|
+
else
|
416
|
+
raise ::Zip::EntryExistsError,
|
417
|
+
procedureName + " failed. Entry #{entryName} already exists"
|
418
|
+
end
|
419
|
+
end
|
420
|
+
|
421
|
+
def check_file(path)
|
422
|
+
raise Errno::ENOENT, path unless ::File.readable?(path)
|
423
|
+
end
|
424
|
+
|
425
|
+
def on_success_replace
|
426
|
+
dirname, basename = ::File.split(name)
|
427
|
+
::Dir::Tmpname.create(basename, dirname) do |tmp_filename|
|
428
|
+
begin
|
429
|
+
if yield tmp_filename
|
430
|
+
::File.rename(tmp_filename, name)
|
431
|
+
::File.chmod(@file_permissions, name) unless @create
|
432
|
+
end
|
433
|
+
ensure
|
434
|
+
::File.unlink(tmp_filename) if ::File.exist?(tmp_filename)
|
435
|
+
end
|
436
|
+
end
|
437
|
+
end
|
438
|
+
end
|
439
|
+
end
|
440
|
+
|
441
|
+
# Copyright (C) 2002, 2003 Thomas Sondergaard
|
442
|
+
# rubyzip is free software; you can redistribute it and/or
|
443
|
+
# modify it under the terms of the ruby license.
|