ziperu 0.2.2-x86_64-linux-gnu → 0.3.0-x86_64-linux-gnu
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 +197 -0
- data/README.md +51 -31
- data/lib/zip.rb +3 -3
- data/lib/ziperu/3.1/ziperu.so +0 -0
- data/lib/ziperu/3.2/ziperu.so +0 -0
- data/lib/ziperu/3.3/ziperu.so +0 -0
- data/lib/ziperu/3.4/ziperu.so +0 -0
- data/lib/ziperu/4.0/ziperu.so +0 -0
- 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 +6 -0
- data/lib/ziperu/entry.rb +275 -107
- 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 +280 -0
- data/lib/ziperu/file.rb +52 -363
- 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 +48 -36
- 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 +127 -30
- 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/streamable_stream.rb +110 -10
- data/lib/ziperu/verify_report.rb +62 -0
- data/lib/ziperu/version.rb +2 -2
- data/lib/ziperu.rb +19 -17
- metadata +7 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: afe7616e7db873482aad81f8cd47bad75c0c44f7c2df68d14346604a687fc08d
|
|
4
|
+
data.tar.gz: e9b5292c1bd255579b2e027191215966af5b98231197d092f985a01f818bbacc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4e1a68a5187b6bac16e120a1e17a24ab1afc6c4934b34a7093bede9f74c3148113820e84307a8604445d77ddf4b527253c3d1bd5671f2f172fa698748715c411
|
|
7
|
+
data.tar.gz: db2c4523d236d93130fd6ef896946916b17b66e3f77b2ac4d5e869eaac80d86e57d6e8b6009c01013823df29bd457a61e2889bb687417a3b39359b282b07648c
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,202 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.3.0 (2026-11-14)
|
|
4
|
+
|
|
5
|
+
Security:
|
|
6
|
+
|
|
7
|
+
- Extraction wrote through a link already on disk below the
|
|
8
|
+
destination: with a junction `dest/linked` pointing elsewhere (no
|
|
9
|
+
privilege needed on Windows) or a symlink, the entry `linked/x` was
|
|
10
|
+
written outside the destination, and with `on_exists: :overwrite` a
|
|
11
|
+
file symlink at an entry's path had its target overwritten. Both
|
|
12
|
+
`extract_all` (native and Ruby paths) and `Entry#extract` now skip,
|
|
13
|
+
with a warning, an entry whose path has a link on the way or is one.
|
|
14
|
+
The destination itself may still be a link. On Linux 5.6 and later the
|
|
15
|
+
native extractor also opens each file's directory with `openat2`
|
|
16
|
+
(`RESOLVE_BENEATH | RESOLVE_NO_SYMLINKS`), so a link swapped in after
|
|
17
|
+
the check is refused by the kernel; other systems, and the Ruby path,
|
|
18
|
+
check just before each write (see SECURITY.md).
|
|
19
|
+
- `symlinks: :create` accepted a chain of links that each looked inside
|
|
20
|
+
the destination (`b -> .`, then `c -> b/..`, which is really the
|
|
21
|
+
destination's parent). A link target with `..` after a name is now
|
|
22
|
+
refused; leading `..`s are still allowed.
|
|
23
|
+
- `RemoteIO` sent its `headers:` (credentials, typically) to wherever a
|
|
24
|
+
redirect led, and followed a redirect from https to http. Headers now
|
|
25
|
+
go only to the origin of the URL given, unless `forward_headers: true`;
|
|
26
|
+
an https-to-http redirect raises, and only http and https URLs are
|
|
27
|
+
accepted.
|
|
28
|
+
- `RemoteIO` kept a whole file in memory, however large, when the server
|
|
29
|
+
ignored Range; past `max_full_download:` (64 MB by default, nil for no
|
|
30
|
+
limit) that now raises. Ranged answers must carry the Content-Range
|
|
31
|
+
asked for, and a file whose ETag (or Last-Modified) changes between
|
|
32
|
+
requests raises instead of being read as a mix of two versions; a
|
|
33
|
+
strong ETag is sent as If-Match.
|
|
34
|
+
|
|
35
|
+
Fixed, failures that destroyed data:
|
|
36
|
+
|
|
37
|
+
- An overwrite during extraction (`on_exists: :overwrite`, or a block
|
|
38
|
+
that says so) truncated the existing file, then deleted it if the
|
|
39
|
+
entry failed to extract (a bad CRC, a size limit, a full disk). The
|
|
40
|
+
new file is now written beside it and renamed over it once complete,
|
|
41
|
+
so the original survives a failure. The replacement is a new file:
|
|
42
|
+
it no longer keeps the old one's permissions or hard links.
|
|
43
|
+
- `File.open(path, write: other)` wrote straight over `other`, so a
|
|
44
|
+
failed commit left a partial archive there. It is now written beside
|
|
45
|
+
it and renamed into place.
|
|
46
|
+
- On Windows, a commit over an archive still open elsewhere moves the
|
|
47
|
+
old one aside first; if the new one then could not be renamed into
|
|
48
|
+
place, neither was left at the path. The old one is now put back.
|
|
49
|
+
|
|
50
|
+
Added:
|
|
51
|
+
|
|
52
|
+
- `File#verify(report: true)` returns a `Ziperu::VerifyReport` listing
|
|
53
|
+
the entries verified, the ones that failed (with the exception) and
|
|
54
|
+
the ones skipped and why (`:encrypted` without a password,
|
|
55
|
+
`:not_written` for an entry added since opening). `ok?` is false when
|
|
56
|
+
anything was skipped, so an archive with nothing checked no longer
|
|
57
|
+
passes for a sound one. Without `report:`, `verify` returns the
|
|
58
|
+
failures as before.
|
|
59
|
+
- `File#extraction_plan(dest, **options)` says what `extract_all` would
|
|
60
|
+
do, entry by entry, without writing anything: the path each entry goes
|
|
61
|
+
to, whether it would be extracted or why not (`:unsafe`,
|
|
62
|
+
`:through_link`, `:symlink_skipped`, `:symlink_refused`), whether
|
|
63
|
+
something is already there, which entries land on the same path once
|
|
64
|
+
sanitized, and the declared size (`declared_size`). It is built from the same plan
|
|
65
|
+
`extract_all` follows.
|
|
66
|
+
- `Ziperu::Limits::UPLOAD`, `STRICT` and `NONE`: ready-made sets of the
|
|
67
|
+
limit settings, as keywords for one archive or through
|
|
68
|
+
`Ziperu::Limits.apply` for all.
|
|
69
|
+
|
|
70
|
+
Faster (Windows, against 0.2.3):
|
|
71
|
+
|
|
72
|
+
- Opening an archive hands each entry's facts from the native core as
|
|
73
|
+
one small Array, yielded directly, rather than a Hash of fifteen keys:
|
|
74
|
+
10,000 entries open in 36 ms instead of 44, with a fifth fewer objects.
|
|
75
|
+
- `gets` and `each_line` read from an offset into the buffer instead of
|
|
76
|
+
cutting each line off its front: a 15 MB CSV of 400,000 lines, 2.0 s to
|
|
77
|
+
0.19 s (rubyzip: 1.6 s); 1000 small text entries, 140 to 64 ms.
|
|
78
|
+
- Small writes (`puts`, `<<` of a field) are gathered and handed to the
|
|
79
|
+
native writer 64 KB at a time: 80,000 writes of 100 bytes, 142 to
|
|
80
|
+
73 ms.
|
|
81
|
+
- A commit that rewrites the archive (a remove, a rename) asks the native
|
|
82
|
+
core in one pass which entries carry fields a raw copy would lose, and
|
|
83
|
+
copies runs of untouched entries in one call. Removing one entry of
|
|
84
|
+
10,000: 329 to 178 ms.
|
|
85
|
+
|
|
86
|
+
Fixed:
|
|
87
|
+
|
|
88
|
+
- An append (`OutputStream.open(path, append: true)`, or a commit that
|
|
89
|
+
only adds) that failed before its first entry was added damaged the
|
|
90
|
+
last entry already in the archive; the archive is now left as it was.
|
|
91
|
+
- `InputStream#read(n)` on a stream (a pipe or socket) took time in
|
|
92
|
+
proportion to `n` for every 64 KB read, so a very large `n` was slow or
|
|
93
|
+
failed to allocate.
|
|
94
|
+
- `RemoteIO`: a read spanning the oldest cached block and one not yet
|
|
95
|
+
fetched raised `NoMethodError` once the cache was full.
|
|
96
|
+
- `Zip::Deflater` and `Zip::PassThruCompressor`, kept for code that names
|
|
97
|
+
them, raised `NoMethodError` on the first write.
|
|
98
|
+
- A `Timeout` (or `Thread#raise`, or Ctrl-C) could be lost for good. When
|
|
99
|
+
it was delivered during the native core's own check for a pending
|
|
100
|
+
exception, that check dropped it. A `Timeout.timeout` around a loop of
|
|
101
|
+
reads then never fired, and the loop ran forever. The exception is now
|
|
102
|
+
raised. Seen as a CI test that hung about one run in five.
|
|
103
|
+
- A `Timeout` on a stream's read of a whole large entry
|
|
104
|
+
(`get_input_stream(name, &:read)`) took effect late. The interrupted
|
|
105
|
+
read first copied everything it had read so far, to keep it for the
|
|
106
|
+
next read: for a 768 MiB entry, longer than reading the entry on macOS.
|
|
107
|
+
It now keeps the String it was filling and copies only if another read
|
|
108
|
+
follows.
|
|
109
|
+
|
|
110
|
+
Changed:
|
|
111
|
+
|
|
112
|
+
- `InputStream#ungetc` returns nil, as `IO#ungetc` does.
|
|
113
|
+
|
|
114
|
+
Internal:
|
|
115
|
+
|
|
116
|
+
- RuboCop (`rake rubocop`, and a CI job) with a configuration that keeps
|
|
117
|
+
rubyzip's style in the ported files; clippy now requires a `SAFETY:`
|
|
118
|
+
comment on every unsafe block.
|
|
119
|
+
- `rake compat` gates test by test against COMPAT.md, not on the total:
|
|
120
|
+
a test that newly fails, a file that no longer loads or a file with
|
|
121
|
+
fewer passes fails the task, and COMPAT.md is only rewritten by a full
|
|
122
|
+
run without a regression (or with `COMPAT_ACCEPT=1`). COMPAT.md is
|
|
123
|
+
regenerated: 419 of 476 rubyzip tests pass.
|
|
124
|
+
- Seeded property tests in the Rust crate (`cargo test`) for the
|
|
125
|
+
extraction path check, the zip64 extra field parser and the ZipCrypto
|
|
126
|
+
round trip, 5,000 cases each.
|
|
127
|
+
- The native core exports the layout of its entry rows
|
|
128
|
+
(`Native::Archive::ROW_FIELDS`), built from one list on the Rust side
|
|
129
|
+
for both the rows and the Hashes; a test checks it against
|
|
130
|
+
`Entry::ROW_FIELDS`.
|
|
131
|
+
- `File` is split by job: committing lives in `file/commit.rb`,
|
|
132
|
+
extraction in `file/extraction.rb`, and which entries `extract_all`
|
|
133
|
+
writes, in what order and under which names, is an `ExtractionPlan`.
|
|
134
|
+
An unknown `sanitize:` now raises even for an empty archive.
|
|
135
|
+
- The regression tests that were filed by release (0.2.1, 0.2.2, the code
|
|
136
|
+
review, the quality pass) are regrouped by behaviour: failure
|
|
137
|
+
recovery, IO semantics, names and metadata, archive options.
|
|
138
|
+
- The nightly CI run of the whole suite under GC stress overran GitHub's
|
|
139
|
+
six hours every night. GC stress is now on only from each test's setup
|
|
140
|
+
to its teardown, not while Bundler, minitest and the gem load. The run
|
|
141
|
+
is split into four parallel jobs, and the seven scale tests, which take
|
|
142
|
+
more than a quarter of an hour each under stress, are left out. Every
|
|
143
|
+
push still runs the native-boundary tests under stress.
|
|
144
|
+
- The test that a `Timeout` interrupts native work no longer assumes a
|
|
145
|
+
768 MiB read takes over 0.1 s, which failed on a fast Windows runner.
|
|
146
|
+
It times the work warm and repeats it under a fraction of that. For a
|
|
147
|
+
stream and for `extract_all` it then checks what was left behind (how
|
|
148
|
+
far the reader got, no finished file), not the clock: tidying up after
|
|
149
|
+
an interrupt takes time that varies with the machine. Under valgrind
|
|
150
|
+
it runs the interrupted paths without judging how promptly they stop:
|
|
151
|
+
valgrind runs one thread at a time, and the one raising the timeout can
|
|
152
|
+
wait a whole read for its turn.
|
|
153
|
+
|
|
154
|
+
## 0.2.3 (2026-11-11)
|
|
155
|
+
|
|
156
|
+
Faster (Windows, against 0.2.2):
|
|
157
|
+
|
|
158
|
+
- Writing many small entries to a file: the header each entry patches
|
|
159
|
+
at its end is now still in the write buffer, so it costs no system
|
|
160
|
+
call. 1000 entries of 8 KB: 46 to 32 ms; 10,000 tiny entries: 315 to
|
|
161
|
+
180 ms. A seekable Ruby IO (`write_buffer`) gets the same, in 64 KB
|
|
162
|
+
chunks.
|
|
163
|
+
- `File#get_output_stream` keeps an entry in memory until the commit
|
|
164
|
+
rather than opening a tempfile for each one; past 8 MB held between
|
|
165
|
+
an archive's pending entries, the rest go to tempfiles as before.
|
|
166
|
+
1000 entries and a commit: 981 to 58 ms.
|
|
167
|
+
- `Entry#time` reads the modification time from the central directory,
|
|
168
|
+
as rubyzip does, rather than the entry's local header; the access and
|
|
169
|
+
creation times still come from there. Listing names and times of
|
|
170
|
+
10,000 entries: 153 to 78 ms.
|
|
171
|
+
- Appending to a large archive no longer reads every entry's local
|
|
172
|
+
header, reads the central directory through a buffer, and keeps the
|
|
173
|
+
entries it had after the commit (same objects) rather than building
|
|
174
|
+
them all again. One entry added to a 10,000-entry archive: 337 to
|
|
175
|
+
98 ms.
|
|
176
|
+
- `InputStream#get_next_entry` opens the entry's data when it is first
|
|
177
|
+
read, so walking only the names reads no local header: 103 to 40 ms
|
|
178
|
+
for 10,000 entries.
|
|
179
|
+
- Reading a whole entry of 64 KB or more (`File#read`, and
|
|
180
|
+
`get_input_stream`'s `read` of the rest of one, which is what roo and
|
|
181
|
+
caxlsx do) decompresses straight into the returned String: no second
|
|
182
|
+
copy, and half the peak memory. 64 MB: 58 to 17 ms; a 64 MB Stored
|
|
183
|
+
entry: 62 to 18 ms. An interrupted read rescued still loses nothing.
|
|
184
|
+
- Files added by path (`add`, `add_stored`, `replace`) are read by the
|
|
185
|
+
native core at commit instead of through Ruby: a 64 MB `add_stored`
|
|
186
|
+
and commit, 141 to 34 ms.
|
|
187
|
+
|
|
188
|
+
Fixed:
|
|
189
|
+
|
|
190
|
+
- Native work could not be interrupted, and kept every other thread
|
|
191
|
+
waiting, whenever Ruby declined to release the GVL for it because an
|
|
192
|
+
interrupt flag was set (often just its thread-scheduling timer): it
|
|
193
|
+
then ran to the end with the GVL held. Now a pending `Thread#raise`,
|
|
194
|
+
`Timeout` or Ctrl-C stops it at once, and otherwise the GVL is
|
|
195
|
+
released on another try.
|
|
196
|
+
- `get_input_stream.read` of an entry whose central record declares it
|
|
197
|
+
empty but gives a CRC of some data returned `""`; it raises, as
|
|
198
|
+
`File#read` does.
|
|
199
|
+
|
|
3
200
|
## 0.2.2 (2026-11-11)
|
|
4
201
|
|
|
5
202
|
Fixed:
|
data/README.md
CHANGED
|
@@ -19,10 +19,26 @@ the [`zip`](https://github.com/zip-rs/zip2) crate through
|
|
|
19
19
|
[Magnus](https://github.com/matsadler/magnus). `require "zip"` aliases
|
|
20
20
|
`Zip = Ziperu`, so existing code runs unchanged.
|
|
21
21
|
|
|
22
|
+
ziperu 0.2.3 on GitHub's Linux runners (Ruby 3.4, median of 5), against
|
|
23
|
+
rubyzip 3.7.0:
|
|
24
|
+
|
|
25
|
+
| scenario | rubyzip | ziperu | speedup |
|
|
26
|
+
|---|---:|---:|---:|
|
|
27
|
+
| read 1000 x 8 KB deflated entries | 110 ms | 18 ms | 6.1x |
|
|
28
|
+
| inflate one 64 MB entry | 112 ms | 38 ms | 3.0x |
|
|
29
|
+
| open and list 10000 entries | 184 ms | 75 ms | 2.5x |
|
|
30
|
+
| deflate one 64 MB entry | 323 ms | 101 ms | 3.2x |
|
|
31
|
+
| `get_output_stream` 1000 entries and commit | 310 ms | 84 ms | 3.7x |
|
|
32
|
+
| append one entry to a 10000-entry archive | 1.16 s | 148 ms | 7.8x |
|
|
33
|
+
| add 1000 files from disk (`threads: 4`) | 348 ms | 89 ms | 3.9x |
|
|
34
|
+
|
|
35
|
+
macOS and Windows, every scenario, and which calls release the GVL (what
|
|
36
|
+
Puma users ask about) are in [docs/benchmarks.md](docs/benchmarks.md).
|
|
37
|
+
|
|
22
38
|
- **Precompiled** for Linux (glibc and musl), macOS and Windows, Ruby 3.1 to 4.0. No toolchain, no runtime dependencies.
|
|
23
39
|
- **Fast**: entries inflate and deflate in Rust with the GVL released, the central directory is parsed once, unchanged entries are copied byte for byte on commit, and a commit that only adds entries appends them in place.
|
|
24
40
|
- **Reads everything**: Stored, Deflate, Deflate64, bzip2, zstd, LZMA, XZ, PPMd and the PKZIP 1.x methods; AES and ZipCrypto. Writes Deflate, Stored, bzip2, zstd, XZ, PPMd, AES and ZipCrypto.
|
|
25
|
-
- **Safe by default**: no entry inflates past its declared size, extraction
|
|
41
|
+
- **Safe by default**: no entry inflates past its declared size, extraction skips names that resolve outside the destination and never writes through a link already on disk, symlinks are opt-in, and limits on entry count, entry size, total size and compression ratio can be set up front. [SECURITY.md](SECURITY.md) has the details.
|
|
26
42
|
- **Friendlier than rubyzip where it costs nothing**: a password on the archive (`File.open(path, password: ...)`), `add` from an IO, Pathname arguments, `File#verify`, progress callbacks, and errors that fail at the call site.
|
|
27
43
|
- **Checked against the field**: rubyzip's own test suite, differential fuzzing against Python's `zipfile` and rubyzip, interoperability runs with Info-ZIP, 7-Zip and Python, and the test suites of gems built on rubyzip (roo, caxlsx, rubyXL, docx, write_xlsx, sablon, gepub) run with ziperu in its place.
|
|
28
44
|
|
|
@@ -40,25 +56,8 @@ Or on its own:
|
|
|
40
56
|
gem install ziperu
|
|
41
57
|
```
|
|
42
58
|
|
|
43
|
-
|
|
44
|
-
(
|
|
45
|
-
`aarch64-linux-musl`, `arm-linux-musl`, `x86_64-darwin`, `arm64-darwin`,
|
|
46
|
-
`x64-mingw-ucrt`, `aarch64-mingw-ucrt`), each holding the extension for
|
|
47
|
-
Ruby 3.1 through 4.0. The glibc gems need RubyGems 3.3.22 or later (Ruby
|
|
48
|
-
3.1.4 ships it); the musl gems need `libgcc` (`apk add libgcc`, already in
|
|
49
|
-
the `ruby:3.2-alpine` and later images). Anywhere else the source gem
|
|
50
|
-
builds with Rust 1.88+.
|
|
51
|
-
|
|
52
|
-
Which Rubies, and how firmly:
|
|
53
|
-
|
|
54
|
-
| Ruby | Status |
|
|
55
|
-
| --- | --- |
|
|
56
|
-
| 3.3, 3.4, 4.0 | Supported. The suite runs on Linux, macOS and Windows on every change; binaries ship. |
|
|
57
|
-
| 3.1, 3.2 | Best effort. Past end of life upstream; binaries still ship and the suite runs on 3.1, but a fix that needs a newer Ruby may drop them, in a minor release and with a changelog entry. |
|
|
58
|
-
| ruby-head | Watched. A non-blocking CI job runs the suite nightly, so a new Ruby gets binaries the day it is released. |
|
|
59
|
-
|
|
60
|
-
JRuby and TruffleRuby are not supported: the core is a native extension
|
|
61
|
-
against the CRuby API. rubyzip remains the library for those.
|
|
59
|
+
Precompiled gems ship for Linux, macOS and Windows; see
|
|
60
|
+
[Platforms](#platforms) for the details.
|
|
62
61
|
|
|
63
62
|
## Quick start
|
|
64
63
|
|
|
@@ -240,6 +239,31 @@ Ziperu::File.open(upload, max_entries: 1_000, max_total_size: 1 << 30) { |zip| .
|
|
|
240
239
|
Ziperu::OutputStream.open("out.zip", write_extended_timestamps: true) { |zos| ... }
|
|
241
240
|
```
|
|
242
241
|
|
|
242
|
+
`Ziperu::Limits` has ready-made sets of these: `UPLOAD` for archives
|
|
243
|
+
users upload, `STRICT` for small documents, `NONE` to clear them.
|
|
244
|
+
|
|
245
|
+
```ruby
|
|
246
|
+
Ziperu::File.open(upload, **Ziperu::Limits::UPLOAD) { |zip| ... }
|
|
247
|
+
Ziperu::Limits.apply(Ziperu::Limits::STRICT) # the globals
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
Look before you extract. `extraction_plan` says what `extract_all` would
|
|
251
|
+
do with each entry, without writing anything. `verify(report: true)` says
|
|
252
|
+
which entries were checked, which failed and which were skipped:
|
|
253
|
+
|
|
254
|
+
```ruby
|
|
255
|
+
Ziperu::File.open(upload) do |zip|
|
|
256
|
+
plan = zip.extraction_plan("out", sanitize: :windows)
|
|
257
|
+
plan.reject(&:extract?).each { |item| warn "#{item.entry.name}: #{item.status}" }
|
|
258
|
+
plan.select(&:collides_with) # entries that land on the same path
|
|
259
|
+
plan.sum(&:declared_size) # declared bytes to be written
|
|
260
|
+
|
|
261
|
+
report = zip.verify(report: true)
|
|
262
|
+
report.ok? # false if anything failed or was skipped
|
|
263
|
+
report.skipped # { entry => :encrypted }, say
|
|
264
|
+
end
|
|
265
|
+
```
|
|
266
|
+
|
|
243
267
|
## Migrating from rubyzip
|
|
244
268
|
|
|
245
269
|
Change the Gemfile line and keep `require "zip"`: the `Zip` constant and
|
|
@@ -284,18 +308,14 @@ dump, reads entries in large chunks, copies unchanged entries byte for
|
|
|
284
308
|
byte on `commit`, and releases the GVL while inflating from a file or
|
|
285
309
|
String buffer and while deflating to a file, so other Ruby threads keep running.
|
|
286
310
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
| scenario | rubyzip | ziperu | speedup |
|
|
290
|
-
|---|---:|---:|---:|
|
|
291
|
-
| read 1000 x 8 KB deflated entries | 80 ms | 14 ms | 5.8x |
|
|
292
|
-
| open and list 10000 entries | 135 ms | 58 ms | 2.3x |
|
|
293
|
-
| deflate one 64 MB entry | 188 ms | 77 ms | 2.4x |
|
|
294
|
-
| extract_all 1000 entries | 169 ms | 80 ms | 2.1x |
|
|
295
|
-
| add 1000 files from disk (`threads: 4`) | 214 ms | 60 ms | 3.6x |
|
|
311
|
+
## Platforms
|
|
296
312
|
|
|
297
|
-
|
|
298
|
-
|
|
313
|
+
- **Ruby 3.3 to 4.0** are supported and tested on Linux, macOS and Windows.
|
|
314
|
+
3.1 and 3.2 still get binaries, best effort.
|
|
315
|
+
- **Precompiled** for x86_64 and aarch64 Linux (glibc and musl; musl needs
|
|
316
|
+
`libgcc`), Intel and Apple Silicon macOS, and x64 and arm64 Windows.
|
|
317
|
+
Elsewhere the source gem builds with Rust 1.88+.
|
|
318
|
+
- **CRuby only**: on JRuby or TruffleRuby, use rubyzip.
|
|
299
319
|
|
|
300
320
|
## Development
|
|
301
321
|
|
data/lib/zip.rb
CHANGED
|
@@ -5,14 +5,14 @@
|
|
|
5
5
|
# runs unchanged. If another library already defines `Zip` (rubyzip itself,
|
|
6
6
|
# most likely), the two cannot share the name: load ziperu with
|
|
7
7
|
# `require "ziperu"` and use `Ziperu::` directly instead.
|
|
8
|
-
if defined?(
|
|
8
|
+
if defined?(Zip) && !(defined?(Ziperu) && Zip.equal?(Ziperu))
|
|
9
9
|
raise LoadError, "ziperu cannot alias Zip = Ziperu: a Zip constant is already defined " \
|
|
10
|
-
"(by #{Object.const_source_location(:Zip)&.first ||
|
|
10
|
+
"(by #{Object.const_source_location(:Zip)&.first || "another library"}). " \
|
|
11
11
|
"Remove rubyzip, or require \"ziperu\" and use Ziperu:: instead."
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
require "ziperu"
|
|
15
|
-
Zip = Ziperu unless defined?(
|
|
15
|
+
Zip = Ziperu unless defined?(Zip)
|
|
16
16
|
|
|
17
17
|
# The `zip/...` paths rubyzip's files live at (`require "zip/filesystem"`
|
|
18
18
|
# is the common one) are kept under lib/zip/ as one-line shims onto the
|
data/lib/ziperu/3.1/ziperu.so
CHANGED
|
Binary file
|
data/lib/ziperu/3.2/ziperu.so
CHANGED
|
Binary file
|
data/lib/ziperu/3.3/ziperu.so
CHANGED
|
Binary file
|
data/lib/ziperu/3.4/ziperu.so
CHANGED
|
Binary file
|
data/lib/ziperu/4.0/ziperu.so
CHANGED
|
Binary file
|
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
# (Copyright (C) 2002-2026 the rubyzip authors).
|
|
5
5
|
|
|
6
6
|
module Ziperu
|
|
7
|
-
# Reads
|
|
7
|
+
# Reads the end-of-central-directory records of an archive, in Ruby, and
|
|
8
|
+
# lists an archive held in an IO (`read_from_stream`).
|
|
8
9
|
#
|
|
9
10
|
# The native core refuses archives whose EOCD declares more entries than
|
|
10
11
|
# the central directory holds, so `Ziperu::File.open` raises on them
|
|
@@ -37,7 +38,6 @@ module Ziperu
|
|
|
37
38
|
@entry_set = EntrySet.new
|
|
38
39
|
@native.entries.each { |meta| @entry_set.push_record(Entry.from_meta(@native, meta)) }
|
|
39
40
|
@size = @entry_set.size
|
|
40
|
-
@cdir_offset = @native.central_directory_start if @native.respond_to?(:central_directory_start)
|
|
41
41
|
self
|
|
42
42
|
end
|
|
43
43
|
|
|
@@ -59,9 +59,7 @@ module Ziperu
|
|
|
59
59
|
end
|
|
60
60
|
|
|
61
61
|
def count_entries(io)
|
|
62
|
-
if IOExtras.path_like?(io)
|
|
63
|
-
return ::File.open(IOExtras.path_of(io), 'rb') { |f| count_entries(f) }
|
|
64
|
-
end
|
|
62
|
+
return ::File.open(IOExtras.path_of(io), 'rb') { |f| count_entries(f) } if IOExtras.path_like?(io)
|
|
65
63
|
|
|
66
64
|
read_eocds(io)
|
|
67
65
|
@size
|
|
@@ -119,9 +117,7 @@ module Ziperu
|
|
|
119
117
|
return if unpack_e_o_c_d(data.slice(eocd_location..-1))
|
|
120
118
|
|
|
121
119
|
zip64_eocd_locator = data.rindex([ZIP64_EOCD_LOCATOR_SIG].pack('V'), eocd_location)
|
|
122
|
-
unless zip64_eocd_locator
|
|
123
|
-
raise Error, 'Zip64 end of central directory locator signature expected but not found'
|
|
124
|
-
end
|
|
120
|
+
raise Error, 'Zip64 end of central directory locator signature expected but not found' unless zip64_eocd_locator
|
|
125
121
|
|
|
126
122
|
zip64_eocd_location = data.rindex([ZIP64_END_OF_CD_SIG].pack('V'), zip64_eocd_locator)
|
|
127
123
|
|
data/lib/ziperu/constants.rb
CHANGED
|
@@ -20,6 +20,14 @@ module Ziperu
|
|
|
20
20
|
|
|
21
21
|
SPLIT_FILE_SIGNATURE = 0x08074b50
|
|
22
22
|
|
|
23
|
+
# The longest a name, comment or extra field can be: each length is a
|
|
24
|
+
# 16-bit field.
|
|
25
|
+
MAX_FIELD_LENGTH = 0xFFFF
|
|
26
|
+
|
|
27
|
+
# A size or offset from here up does not fit its 32-bit field and needs
|
|
28
|
+
# the zip64 form.
|
|
29
|
+
ZIP64_SIZE_LIMIT = 0xFFFFFFFF
|
|
30
|
+
|
|
23
31
|
FILE_TYPE_FILE = 0o10
|
|
24
32
|
FILE_TYPE_DIR = 0o04
|
|
25
33
|
FILE_TYPE_SYMLINK = 0o12
|
data/lib/ziperu/crypto.rb
CHANGED
|
@@ -12,9 +12,9 @@ module Ziperu
|
|
|
12
12
|
end
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
-
class TraditionalDecrypter < Decrypter; end
|
|
15
|
+
class TraditionalDecrypter < Decrypter; end # :nodoc:
|
|
16
16
|
|
|
17
|
-
class AESDecrypter < Decrypter
|
|
17
|
+
class AESDecrypter < Decrypter # :nodoc:
|
|
18
18
|
def initialize(password, _strength = nil)
|
|
19
19
|
super(password)
|
|
20
20
|
end
|
|
@@ -39,10 +39,17 @@ module Ziperu
|
|
|
39
39
|
end
|
|
40
40
|
end
|
|
41
41
|
|
|
42
|
+
# No encryption.
|
|
42
43
|
class NullEncrypter < Encrypter
|
|
43
44
|
def initialize
|
|
44
45
|
super(nil)
|
|
45
46
|
end
|
|
47
|
+
|
|
48
|
+
# rubyzip's compressors (Deflater, PassThruCompressor) pass their
|
|
49
|
+
# output through the encrypter.
|
|
50
|
+
def encrypt(data) # :nodoc:
|
|
51
|
+
data
|
|
52
|
+
end
|
|
46
53
|
end
|
|
47
54
|
|
|
48
55
|
# ZipCrypto, the weak legacy cipher that Windows Explorer and other
|
|
@@ -55,6 +62,7 @@ module Ziperu
|
|
|
55
62
|
end
|
|
56
63
|
end
|
|
57
64
|
|
|
65
|
+
# WinZip AES; 256-bit unless another strength is given.
|
|
58
66
|
class AESEncrypter < Encrypter
|
|
59
67
|
include AESEncryption
|
|
60
68
|
|
data/lib/ziperu/dos_time.rb
CHANGED
|
@@ -77,7 +77,7 @@ module Ziperu
|
|
|
77
77
|
hour = (0b1111100000000000 & bin_dos_time) >> 11
|
|
78
78
|
day = (0b11111 & bin_dos_date)
|
|
79
79
|
month = (0b111100000 & bin_dos_date) >> 5
|
|
80
|
-
year = ((0b1111111000000000 & bin_dos_date) >> 9) +
|
|
80
|
+
year = ((0b1111111000000000 & bin_dos_date) >> 9) + DOS_EPOCH_YEAR
|
|
81
81
|
|
|
82
82
|
time = local(year, month, day, hour, minute, second)
|
|
83
83
|
time.absolute_time = false
|
data/lib/ziperu/entry/source.rb
CHANGED
|
@@ -109,6 +109,12 @@ module Ziperu
|
|
|
109
109
|
@index ? archive.local_extra(@index) : archive.local_extra_at(offset)
|
|
110
110
|
end
|
|
111
111
|
|
|
112
|
+
# Moves the record to `native`, which holds it at the same index:
|
|
113
|
+
# the archive reopened after entries were appended to it.
|
|
114
|
+
def rebind(native)
|
|
115
|
+
@native = native
|
|
116
|
+
end
|
|
117
|
+
|
|
112
118
|
def detached
|
|
113
119
|
NONE
|
|
114
120
|
end
|