ziperu 0.2.3 → 0.3.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 +4 -4
- data/CHANGELOG.md +190 -0
- data/Cargo.lock +2 -1
- data/README.md +35 -7
- data/ext/ziperu/Cargo.toml +9 -1
- data/ext/ziperu/src/archive.rs +246 -144
- data/ext/ziperu/src/entry_options.rs +1 -1
- data/ext/ziperu/src/errors.rs +39 -11
- data/ext/ziperu/src/extract.rs +332 -104
- data/ext/ziperu/src/gvl.rs +45 -26
- data/ext/ziperu/src/lib.rs +17 -0
- data/ext/ziperu/src/place.rs +379 -0
- data/ext/ziperu/src/rb.rs +14 -1
- data/ext/ziperu/src/reader.rs +100 -29
- data/ext/ziperu/src/sink.rs +2 -7
- data/ext/ziperu/src/source.rs +4 -7
- data/ext/ziperu/src/stream.rs +89 -11
- data/ext/ziperu/src/test_rng.rs +37 -0
- data/ext/ziperu/src/writer.rs +71 -25
- data/ext/ziperu/src/zipcrypto.rs +40 -12
- data/lib/zip.rb +3 -3
- data/lib/ziperu/central_directory.rb +4 -8
- data/lib/ziperu/constants.rb +8 -0
- data/lib/ziperu/crypto.rb +10 -2
- data/lib/ziperu/dos_time.rb +1 -1
- data/lib/ziperu/entry/source.rb +41 -6
- data/lib/ziperu/entry.rb +252 -112
- data/lib/ziperu/entry_set.rb +0 -5
- data/lib/ziperu/errors.rb +4 -2
- data/lib/ziperu/extra_field/zip64.rb +1 -3
- data/lib/ziperu/extra_field.rb +10 -10
- data/lib/ziperu/file/commit.rb +255 -0
- data/lib/ziperu/file/extraction.rb +285 -0
- data/lib/ziperu/file.rb +77 -405
- data/lib/ziperu/file_split.rb +1 -3
- data/lib/ziperu/filesystem/dir.rb +3 -9
- data/lib/ziperu/filesystem/file.rb +2 -6
- data/lib/ziperu/filesystem/zip_file_name_mapper.rb +2 -2
- data/lib/ziperu/input_stream.rb +30 -32
- data/lib/ziperu/ioextras/abstract_input_stream.rb +83 -31
- data/lib/ziperu/ioextras/abstract_output_stream.rb +1 -3
- data/lib/ziperu/ioextras/fake_io.rb +1 -3
- data/lib/ziperu/ioextras.rb +6 -0
- data/lib/ziperu/limits.rb +48 -0
- data/lib/ziperu/null_input_stream.rb +1 -1
- data/lib/ziperu/output_stream.rb +118 -31
- data/lib/ziperu/pass_thru_decompressor.rb +1 -3
- data/lib/ziperu/rails_streaming.rb +5 -5
- data/lib/ziperu/remote_io.rb +181 -32
- data/lib/ziperu/size_estimator.rb +27 -19
- data/lib/ziperu/verify_report.rb +62 -0
- data/lib/ziperu/version.rb +2 -2
- data/lib/ziperu.rb +19 -17
- metadata +8 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Ziperu
|
|
4
|
-
class OutputStream
|
|
4
|
+
class OutputStream # rubocop:disable Style/Documentation -- documented in output_stream.rb
|
|
5
5
|
# Works out, to the byte, how large an archive will be when streamed
|
|
6
6
|
# (`OutputStream.body`, `write_buffer` to a pipe or socket), from the
|
|
7
7
|
# names and sizes of its entries, so a download can carry a
|
|
@@ -25,12 +25,21 @@ module Ziperu
|
|
|
25
25
|
# for a stream: a data descriptor after every file's data, zip64
|
|
26
26
|
# records only for a 4 GiB entry or 65,535 entries.
|
|
27
27
|
class SizeEstimator
|
|
28
|
-
LOCAL_HEADER =
|
|
29
|
-
CENTRAL_HEADER =
|
|
28
|
+
LOCAL_HEADER = LOCAL_ENTRY_STATIC_HEADER_LENGTH
|
|
29
|
+
CENTRAL_HEADER = CDIR_ENTRY_STATIC_HEADER_LENGTH
|
|
30
30
|
END_OF_CENTRAL_DIRECTORY = 22
|
|
31
31
|
ZIP64_END_OF_CENTRAL_DIRECTORY = 56 + 20 # the record and its locator
|
|
32
|
-
ZIP64_THRESHOLD =
|
|
32
|
+
ZIP64_THRESHOLD = ZIP64_SIZE_LIMIT
|
|
33
33
|
ZIP64_ENTRY_THRESHOLD = 0xFFFF
|
|
34
|
+
# After a file's data: signature, CRC and two sizes, 32-bit or 64-bit.
|
|
35
|
+
DATA_DESCRIPTOR = 16
|
|
36
|
+
ZIP64_DATA_DESCRIPTOR = 24
|
|
37
|
+
# Every extra field starts with an ID and a length.
|
|
38
|
+
EXTRA_FIELD_HEADER = 4
|
|
39
|
+
# A local header's zip64 field: its header and two 8-byte sizes.
|
|
40
|
+
ZIP64_LOCAL_EXTRA = EXTRA_FIELD_HEADER + 16
|
|
41
|
+
# The extended timestamp field: its header, flags and the mtime.
|
|
42
|
+
EXTENDED_TIMESTAMP = EXTRA_FIELD_HEADER + 1 + 4
|
|
34
43
|
|
|
35
44
|
def initialize(settings = ::Ziperu)
|
|
36
45
|
@settings = settings
|
|
@@ -52,7 +61,7 @@ module Ziperu
|
|
|
52
61
|
|
|
53
62
|
# A directory entry (`name` ends with `/`).
|
|
54
63
|
def add_directory(name)
|
|
55
|
-
fields = default_fields
|
|
64
|
+
fields = default_fields
|
|
56
65
|
name = name.to_s.b
|
|
57
66
|
@entries += 1
|
|
58
67
|
@data += LOCAL_HEADER + name.bytesize + fields
|
|
@@ -68,8 +77,8 @@ module Ziperu
|
|
|
68
77
|
|
|
69
78
|
# The archive's size in bytes.
|
|
70
79
|
def size
|
|
71
|
-
|
|
72
|
-
zip64 = @entries > ZIP64_ENTRY_THRESHOLD ||
|
|
80
|
+
# `@data` is also where the central directory starts.
|
|
81
|
+
zip64 = @entries > ZIP64_ENTRY_THRESHOLD || @data > ZIP64_THRESHOLD ||
|
|
73
82
|
@central > ZIP64_THRESHOLD
|
|
74
83
|
total = @data + @central + END_OF_CENTRAL_DIRECTORY + @comment
|
|
75
84
|
total += ZIP64_END_OF_CENTRAL_DIRECTORY if zip64
|
|
@@ -79,29 +88,28 @@ module Ziperu
|
|
|
79
88
|
private
|
|
80
89
|
|
|
81
90
|
def add_file(name, size, compressed_size)
|
|
82
|
-
fields = default_fields
|
|
91
|
+
fields = default_fields
|
|
83
92
|
name = name.to_s.b
|
|
84
93
|
large = size >= ZIP64_THRESHOLD || compressed_size >= ZIP64_THRESHOLD
|
|
85
94
|
offset_large = @data >= ZIP64_THRESHOLD
|
|
86
95
|
@entries += 1
|
|
87
|
-
# The local header, with a zip64 extra
|
|
88
|
-
#
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
# The central record: a zip64 extra holds the sizes for a
|
|
92
|
-
# entry and the offset for one past 4 GiB.
|
|
96
|
+
# The local header, with a zip64 extra for a large entry; the data;
|
|
97
|
+
# the descriptor.
|
|
98
|
+
@data += LOCAL_HEADER + name.bytesize + fields + (large ? ZIP64_LOCAL_EXTRA : 0) +
|
|
99
|
+
compressed_size + (large ? ZIP64_DATA_DESCRIPTOR : DATA_DESCRIPTOR)
|
|
100
|
+
# The central record: a zip64 extra holds the two 8-byte sizes for a
|
|
101
|
+
# large entry and the 8-byte offset for one past 4 GiB.
|
|
93
102
|
zip64_extra = 0
|
|
94
103
|
zip64_extra += 16 if large
|
|
95
104
|
zip64_extra += 8 if offset_large
|
|
96
|
-
zip64_extra +=
|
|
105
|
+
zip64_extra += EXTRA_FIELD_HEADER unless zip64_extra.zero?
|
|
97
106
|
@central += CENTRAL_HEADER + name.bytesize + fields + zip64_extra
|
|
98
107
|
self
|
|
99
108
|
end
|
|
100
109
|
|
|
101
|
-
# The extra field the writer adds by default
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
@settings.write_extended_timestamps ? 9 : 0
|
|
110
|
+
# The size of the extra field the writer adds by default.
|
|
111
|
+
def default_fields
|
|
112
|
+
@settings.write_extended_timestamps ? EXTENDED_TIMESTAMP : 0
|
|
105
113
|
end
|
|
106
114
|
end
|
|
107
115
|
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Ziperu
|
|
4
|
+
# What `File#verify(report: true)` found, entry by entry:
|
|
5
|
+
#
|
|
6
|
+
# - `verified`: the entries whose data inflated with the right CRC and
|
|
7
|
+
# size, in archive order;
|
|
8
|
+
# - `failed`: a Hash of the entries that did not to the exception raised;
|
|
9
|
+
# - `skipped`: a Hash of the entries not checked to why: `:encrypted` (no
|
|
10
|
+
# password was given) or `:not_written` (added or replaced since the
|
|
11
|
+
# archive was opened, so not in it yet).
|
|
12
|
+
#
|
|
13
|
+
# Directories have no data and appear in none of them.
|
|
14
|
+
# Not in rubyzip.
|
|
15
|
+
class VerifyReport
|
|
16
|
+
attr_reader :verified, :failed, :skipped
|
|
17
|
+
|
|
18
|
+
def initialize # :nodoc:
|
|
19
|
+
@verified = []
|
|
20
|
+
@failed = {}
|
|
21
|
+
@skipped = {}
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# True when every entry with data was checked and passed.
|
|
25
|
+
def ok?
|
|
26
|
+
@failed.empty? && @skipped.empty?
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# True when nothing that was checked failed; skipped entries aside.
|
|
30
|
+
def no_failures?
|
|
31
|
+
@failed.empty?
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def add_verified(entry) # :nodoc:
|
|
35
|
+
@verified << entry
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def add_failed(entry, error) # :nodoc:
|
|
39
|
+
@failed[entry] = error
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def add_skipped(entry, reason) # :nodoc:
|
|
43
|
+
@skipped[entry] = reason
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def freeze
|
|
47
|
+
@verified.freeze
|
|
48
|
+
@failed.freeze
|
|
49
|
+
@skipped.freeze
|
|
50
|
+
super
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# One line: how many were verified, failed and skipped.
|
|
54
|
+
def to_s
|
|
55
|
+
"#{@verified.size} verified, #{@failed.size} failed, #{@skipped.size} skipped"
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def inspect
|
|
59
|
+
"#<#{self.class.name} #{self}>"
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
data/lib/ziperu/version.rb
CHANGED
data/lib/ziperu.rb
CHANGED
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
# Same standard-library surface rubyzip loads, since code downstream tends
|
|
4
4
|
# to rely on it being there.
|
|
5
|
-
require
|
|
6
|
-
require
|
|
7
|
-
require
|
|
8
|
-
require
|
|
9
|
-
require
|
|
10
|
-
require
|
|
11
|
-
require
|
|
12
|
-
require
|
|
13
|
-
require
|
|
14
|
-
require
|
|
15
|
-
require
|
|
5
|
+
require "English"
|
|
6
|
+
require "delegate"
|
|
7
|
+
require "digest"
|
|
8
|
+
require "fileutils"
|
|
9
|
+
require "forwardable"
|
|
10
|
+
require "pathname"
|
|
11
|
+
require "rbconfig"
|
|
12
|
+
require "singleton"
|
|
13
|
+
require "stringio"
|
|
14
|
+
require "tempfile"
|
|
15
|
+
require "zlib"
|
|
16
16
|
|
|
17
17
|
require_relative "ziperu/version"
|
|
18
18
|
require_relative "ziperu/compat"
|
|
@@ -34,12 +34,12 @@ rescue LoadError => e
|
|
|
34
34
|
" The native extension needs libgcc_s.so.1: on Alpine run `apk add libgcc`."
|
|
35
35
|
elsif e.message.include?("ld-linux") || e.message.include?("musl")
|
|
36
36
|
" The installed ziperu gem was built for another libc; on Alpine (musl) use " \
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
"`gem install ziperu --platform #{RUBY_PLATFORM}` or " \
|
|
38
|
+
"`bundle lock --add-platform #{RUBY_PLATFORM}`, or install the source gem with " \
|
|
39
|
+
"`gem install ziperu --platform ruby` (needs a Rust toolchain)."
|
|
40
40
|
else
|
|
41
41
|
" The native extension for Ruby #{RUBY_VERSION} is missing from the installed gem; " \
|
|
42
|
-
|
|
42
|
+
"install the source gem with `gem install ziperu --platform ruby` (needs a Rust toolchain)."
|
|
43
43
|
end
|
|
44
44
|
raise LoadError, e.message + hint
|
|
45
45
|
end
|
|
@@ -70,6 +70,8 @@ require_relative "ziperu/deflater"
|
|
|
70
70
|
require_relative "ziperu/streamable_directory"
|
|
71
71
|
require_relative "ziperu/file_split"
|
|
72
72
|
require_relative "ziperu/file"
|
|
73
|
+
require_relative "ziperu/verify_report"
|
|
74
|
+
require_relative "ziperu/limits"
|
|
73
75
|
require_relative "ziperu/size_estimator"
|
|
74
76
|
|
|
75
77
|
# Drop-in replacement for rubyzip, backed by a Rust core.
|
|
@@ -84,7 +86,7 @@ require_relative "ziperu/size_estimator"
|
|
|
84
86
|
module Ziperu
|
|
85
87
|
# Loaded on first use, so net/http is only required by those who read
|
|
86
88
|
# archives over HTTP.
|
|
87
|
-
autoload :RemoteIO, ::File.expand_path(
|
|
89
|
+
autoload :RemoteIO, ::File.expand_path("ziperu/remote_io", __dir__)
|
|
88
90
|
|
|
89
91
|
# Used by the ported Deflater only; kept because rubyzip exposes it.
|
|
90
92
|
ZLIB_FLUSHING_STRATEGY = defined?(JRUBY_VERSION) ? Zlib::SYNC_FLUSH : Zlib::NO_FLUSH
|
|
@@ -179,7 +181,7 @@ module Ziperu
|
|
|
179
181
|
# every run and machine. Read from the SOURCE_DATE_EPOCH environment
|
|
180
182
|
# variable, the convention build tools follow; set it here to apply
|
|
181
183
|
# it without the variable, or to nil to ignore the variable.
|
|
182
|
-
@source_date_epoch = ENV[
|
|
184
|
+
@source_date_epoch = ENV["SOURCE_DATE_EPOCH"]&.then { |v| Integer(v, exception: false) }
|
|
183
185
|
end
|
|
184
186
|
|
|
185
187
|
# The time a new entry gets by default: `source_date_epoch` when set,
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ziperu
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Maor Caplan
|
|
@@ -49,12 +49,14 @@ files:
|
|
|
49
49
|
- ext/ziperu/src/extract.rs
|
|
50
50
|
- ext/ziperu/src/gvl.rs
|
|
51
51
|
- ext/ziperu/src/lib.rs
|
|
52
|
+
- ext/ziperu/src/place.rs
|
|
52
53
|
- ext/ziperu/src/rb.rs
|
|
53
54
|
- ext/ziperu/src/reader.rs
|
|
54
55
|
- ext/ziperu/src/sink.rs
|
|
55
56
|
- ext/ziperu/src/source.rs
|
|
56
57
|
- ext/ziperu/src/stream.rs
|
|
57
58
|
- ext/ziperu/src/stream_stats.rs
|
|
59
|
+
- ext/ziperu/src/test_rng.rs
|
|
58
60
|
- ext/ziperu/src/writer.rs
|
|
59
61
|
- ext/ziperu/src/zipcrypto.rs
|
|
60
62
|
- lib/rubyzip.rb
|
|
@@ -132,6 +134,8 @@ files:
|
|
|
132
134
|
- lib/ziperu/extra_field/unknown.rb
|
|
133
135
|
- lib/ziperu/extra_field/zip64.rb
|
|
134
136
|
- lib/ziperu/file.rb
|
|
137
|
+
- lib/ziperu/file/commit.rb
|
|
138
|
+
- lib/ziperu/file/extraction.rb
|
|
135
139
|
- lib/ziperu/file_split.rb
|
|
136
140
|
- lib/ziperu/filesystem.rb
|
|
137
141
|
- lib/ziperu/filesystem/dir.rb
|
|
@@ -145,6 +149,7 @@ files:
|
|
|
145
149
|
- lib/ziperu/ioextras/abstract_input_stream.rb
|
|
146
150
|
- lib/ziperu/ioextras/abstract_output_stream.rb
|
|
147
151
|
- lib/ziperu/ioextras/fake_io.rb
|
|
152
|
+
- lib/ziperu/limits.rb
|
|
148
153
|
- lib/ziperu/null_compressor.rb
|
|
149
154
|
- lib/ziperu/null_decompressor.rb
|
|
150
155
|
- lib/ziperu/null_input_stream.rb
|
|
@@ -158,6 +163,7 @@ files:
|
|
|
158
163
|
- lib/ziperu/size_estimator.rb
|
|
159
164
|
- lib/ziperu/streamable_directory.rb
|
|
160
165
|
- lib/ziperu/streamable_stream.rb
|
|
166
|
+
- lib/ziperu/verify_report.rb
|
|
161
167
|
- lib/ziperu/version.rb
|
|
162
168
|
homepage: https://github.com/caplanmaor/ziperu
|
|
163
169
|
licenses:
|
|
@@ -165,6 +171,7 @@ licenses:
|
|
|
165
171
|
metadata:
|
|
166
172
|
homepage_uri: https://github.com/caplanmaor/ziperu
|
|
167
173
|
source_code_uri: https://github.com/caplanmaor/ziperu
|
|
174
|
+
bug_tracker_uri: https://github.com/caplanmaor/ziperu/issues
|
|
168
175
|
changelog_uri: https://github.com/caplanmaor/ziperu/blob/main/CHANGELOG.md
|
|
169
176
|
rubygems_mfa_required: 'true'
|
|
170
177
|
rdoc_options: []
|