Commit Graph

588 Commits

Author SHA1 Message Date
Robert Haines 1f3f84c889 Update version number and Changelog for RC2. 2025-02-08 17:18:43 +00:00
Robert Haines deca4d5aeb Fix de facto regression for input streams.
A close reading of the ZIP spec insists that if bit 3 of the GP flags is set
then the archive cannot be read via `Zip::InputStream`. But in most cases
the correct information is present to be able to do so, both safely and
reliably, and v2.4 does allow this.

This commit ensures that behaviour is present in v3.0.
2025-02-08 16:51:30 +00:00
Robert Haines 43d845c2cb Update version number, README and Changelog for RC1.
Also update the year to 2025 in the licence.
2025-01-26 22:23:25 +00:00
Robert Haines 7412338c2e Fix variable name typo in `DecryptedIo`.
Fixes: #580
2025-01-04 16:18:27 +00:00
Bastien 5b0d25e416 Fix misspell 2024-10-26 20:05:18 +01:00
Jean Boussier 5c6a7c9ad9 Fix `File#write_buffer` to always return the given `io`
Ref: ef89a62b70

This fixes a regression in 2.4.rc1.

Cherry-picked into 3.0 for consistency.
2024-04-09 10:10:47 +01:00
Robert Haines 0c0003cfda Add `DOSTime#absolute_time?`.
This method returns `true` if the time instance was created with accurate
timezone information. Ultimately, only those times parsed from binary
DOS format are missing accurate timezone information, but we need this
flag because ruby `Time` objects (from which `DOSTime` is decended) always
have a timezone set (usually whatever is local at the time).
2024-04-08 18:37:08 +01:00
Robert Haines d53f046bc7 Add `Entry#absolute_time?`.
This method returns `true` if an entry has timezone information in its
timestamps, `false` otherwise.
2024-03-07 21:31:24 +00:00
Robert Haines 8afc2514f7 Use explicit named parameters for `File` methods.
Stop using implicit options (`**options`).
2024-03-07 16:57:50 +00:00
Robert Haines bfc9324a75 Remove deprecated InputStream::open_buffer method. 2024-03-02 14:55:46 +00:00
Robert Haines e83bec471b Update API documentation.
Mostly move things out of the public API by removing them from the docs,
but also add and correct docs where appropriate.
2024-03-02 14:52:24 +00:00
Robert Haines 1c06454985 Update minimum ruby version to 3.0.
All rubies before 3.0 are EOL and this is a major version bump, so it's
the right time to do this.
2024-03-01 22:14:48 +00:00
OZAWA Sakuro a2fc20db8f Zip::InputStream#read returns '' with 0 2023-04-14 11:25:22 +01:00
Robert Haines 2ffbfebb88 Document or hide classes from the docs. 2023-04-14 11:25:22 +01:00
Robert Haines 0aa10bf7d5 Document or hide modules from the docs. 2023-04-14 11:25:22 +01:00
Robert Haines ccc3d4ff1a Set version to be 3.0.0.alpha. 2023-04-14 11:25:22 +01:00
Robert Haines 84087e5774 Ensure that entries can be extracted safely without path traversal.
This commit adds a parameter to the `File#extract` and `Entry#extract` methods
so that a base destination directory can be specified for extracting archives
in bulk to somewhere in the filesystem that isn't the current working
directory. This directory is `.` by default. It is combined with the entry
path - which shouldn't but could have relative directories (e.g. `..`) in it -
and tested for safety before extracting.

Resolves #540.
2023-04-14 11:15:24 +01:00
Robert Haines 58f053afb0 Only use the Zip64 CDIR end locator if needed.
Previously the central directory Zip64 data was written even if it wasn't
strictly needed. The standard allows for entries to include Zip64 data
(say, if they are streamed and their size is unknown when writing the file
data) without needing any Zip64 data in the central directory. So now we
only write central directory Zip64 data if there are over 65535 files or
the file data is huge.
2023-01-03 20:19:40 +00:00
Robert Haines f460da3afb Prevent unnecessary Zip64 data being stored.
With Zip64 write support enabled by default, it's important that we
only store the extra data when we need to. This commit ensures that
the Zip64 extra data is included for an entry if its size is over
4GB, or if we don't know how big it will be at the point of writing
the local header data.

This commit also removes the need for the Zip64Placeholder extra
data field. Now we just use the Zip64 field itself and ensure it's
filled in correctly.
2023-01-03 20:19:40 +00:00
Stan Hu d6eb73566c Enable Zip64 by default
Previously if RubyZip attempted to create an archive with more than
64K entries, the central directory would truncate the count. `unzip`
and `zipinfo` would fail with an error message such as:

```
error:  expected central file header signature not found (file #93272).
  (please check that you have transferred or created the zipfile in the
  appropriate BINARY mode and that you have compiled UnZip properly)
```

This generated a lot of confusion and a production issue since many
tools fail to decode a RubyZip-created archive if Zip64 is not enabled
for a large number of files. Since Zip64 support is now the norm,
enable this by default.
2023-01-03 20:19:40 +00:00
Robert Haines 750d372380 Rename DestinationFileExistsError -> DestinationExistsError.
And define the error message within the class.
2022-08-16 11:13:30 +01:00
Robert Haines e3f0aecf93 Define the EntryNameError message within the error class. 2022-08-16 10:52:18 +01:00
Robert Haines 07eca2bae8 Define the EntrySizeError message within the error class. 2022-08-15 22:02:33 +01:00
Robert Haines 7097492dc8 Define the EntryExistsError message within the error class. 2022-08-14 22:23:51 +01:00
Robert Haines 04cc10a80f Remove the InternalError class (never used). 2022-08-14 22:23:51 +01:00
Robert Haines 51231673a4 Define the DecompressionError message within the error class. 2022-08-14 22:23:51 +01:00
Robert Haines 19fe79e31e Define the SplitArchiveError message within the error class. 2022-08-14 22:23:51 +01:00
Robert Haines 03a9ee6b8a Rename `GPFBit3Error` to `StreamingError`.
`GPFBit3Error` doesn't really mean anything to the general user, and
it's not descriptive of the issue at hand. This error is raised when a
zip file cannot be streamed via `InputStream`, so `StreamingError` makes
more sense.

Also standardize the error message while we're about it.
2022-08-14 22:23:51 +01:00
Robert Haines 2e4dd9e0aa Improve the message for CompressionMethodError.
Convert the compression method number into a meaningful text
representation, e.g., "BZIP2" instead of "12".
2022-08-14 22:23:51 +01:00
Robert Haines 08391da4d5 Ensure that `Entry.ftype` is correct via `InputStream`.
When reading an archive with `InputStream`, `Entry.ftype` was returning
`:file` for all entries, even if they were a directory. This is due to
various side-effects in many methods in `Entry`. This commit fixes the
behaviour, but not the side-effects.

Fixes #533.
2022-08-13 22:09:55 +01:00
Brian Williams 6f1ad8b37d Fix unraised error on encrypted archives 2022-08-09 22:11:42 +01:00
Robert Haines 14ff11ba05 Re-initialize CDir after a `commit`.
Using the factored-out code preserves options set in `File`.

Fixes #529.
2022-06-25 08:51:32 +01:00
Robert Haines c243b4429a Factor out the code in `File` to init the CDir.
This allows us to reuse it without overwriting any options passed to `File`.
2022-06-25 08:48:23 +01:00
Robert Haines 6486047d5f Use the new `Entry` time methods in `Filesystem::File`. 2022-06-20 17:18:20 +01:00
Robert Haines 466383ff1a Add other `Entry` time methods and test them all. 2022-06-20 17:18:20 +01:00
Robert Haines fff1f8ea8a Add `Entry#mtime=` as an alias of `Entry#time=`. 2022-06-20 17:18:20 +01:00
Robert Haines 62ed397b1a Generalize `Entry#time=`.
So we can use it for `atime=`, `ctime=` and `utime=` as well.
2022-06-20 17:18:20 +01:00
Robert Haines d6482bd567 Generalize `Entry#time`.
So we can use it for `atime`, `ctime` and `utime` as well.
2022-06-20 17:18:20 +01:00
Robert Haines ae0262df2e Add `Entry#zip64?` as a better way detect Zip64 entries. 2022-06-20 17:18:20 +01:00
Robert Haines 307fc6c6e9 Mark other mutating methods in `Entry` as dirty.
Also, remove `Entry#extra=` as it makes no sense (and wasn't even being
tested).

And remove slightly odd test that was assuming an archive would not be
changed if its utime was changed - even if it was being changed back
immediately. This test was merely confirming that we weren't catching
timestamp changes correctly.
2022-06-20 17:18:20 +01:00
Robert Haines 33dce510a6 Remove `Entry#dirty=` as 'dirtyness' is now monitored internally.
Had to round out some of the accessors that mark an `Entry` as dirty.
2022-06-20 17:18:20 +01:00
Robert Haines 5cd1ef2910 Use new dirty statuses to detect zip file changes.
This also means that we no longer need to keep a copy of the original
set of `Entry`s or the central directory comment to test for changes.

For situations where a zip file has a lot of entries (e.g. #506) this
means we save a lot of memory, and a lot of time constructing the zip
file in memory.
2022-06-20 17:18:20 +01:00
Robert Haines 08641db9f8 Make `CentralDirectory` dirtyable. 2022-06-20 17:18:20 +01:00
Robert Haines 7b340d62a6 Abstract marking as dirty into `Dirtyable` for reuse. 2022-06-20 17:18:20 +01:00
Robert Haines 3002251048 Mark certain methods in `Entry` as making it dirty.
This allows us to track which entries have changed without keeping a
copy of all entries. I hope.
2022-06-20 17:18:19 +01:00
Robert Haines 78a3cc596f Make `Entry::zipfile` private.
No need for it to be public, and especially not writeable.
2022-06-20 17:18:19 +01:00
Robert Haines e0e754ae65 Switch how the `Entry::dirty` flag is used.
Set it to true by default - because a new `Entry` is dirty by
definition, having not been written yet. Then make sure that an `Entry`
that is created by reading from a zip file is set as not dirty.
2022-06-20 17:18:19 +01:00
Robert Haines 48d6acf9ca Ensure all streams passed to `File.new` are in `binmode`.
Previously, only those streams that were passed to `new` by `open_buffer`
were in the correct mode.
2022-06-18 16:19:52 +01:00
Finn Bacall 8b87b0e200 Implement `Zip::FileSystem::ZipFsFile#symlink?` 2022-06-16 20:31:35 +01:00
Robert Haines e07f019507 Improve the description of `InputStream#get_next_entry`.
Documentation now refects the fact that the stream is positioned at the start
of the entry data.
2022-04-23 13:52:50 +01:00