122 Commits

Author SHA1 Message Date
Quytelda Kahja e621f9a576 Don't add Zip64 extra fields when copying entries without them
When copying an entry from another archive, there is no reason to add
Zip64 extra fields if the source entry doesn't have them. This change
checks whether a copied entry had Zip64 extra fields before
appending/updating the field in the local header.
2025-06-02 16:49:33 +02:00
Quytelda Kahja 7496676394 Add a 'StrictEntry' action for creating entries from strict data
When entry data is provided as a strict ByteString, we don't need to
stream the data to determine its uncompressed size. Thus, we can rule
out the need for Zip64 extra fields early.

This addresses issue #126.
2025-05-25 20:09:29 +02:00
Quytelda Kahja b2ecfcae19 Remove redundant duplicate cases in 'sinkEntry'
The case statement in question evaluates to an identical expression in
all cases, so we can elide it.
2025-05-25 20:09:29 +02:00
Quytelda Kahja 3f7821a8c2 Simplify Map traversals and folds
Use foldlWithKey, foldMapWithKey, and traverseWithKey to process Maps
in a single pass and avoid using (!), which is a partial function.
2025-05-25 20:09:29 +02:00
Mark Karpov 0d1b117a14 Test with GHC 9.10.1 2025-01-21 13:33:08 +01:00
Mark Karpov 8d7f6c2c75 Stop manually deriving Typeable 2025-01-21 12:24:42 +01:00
Niklas Hambüchen c69cc3d6c2 Derive Show EntryDescription 2024-06-19 20:19:24 +02:00
Patrick Chilton 708a49146c Expose internal modules 2024-06-19 20:19:24 +02:00
Mark Karpov 63779b106a Improve the test suite to catch cases like issue 111 2024-04-20 21:00:47 +02:00
Mark Karpov da5df36c81 Fix corruption of large files when zip64 is used
Previously the code did not account for the fact that the initial stub local
header (with uncompressed and compressed sizes set to 0) could not serve for
correct estimation of the final local header size due to the fact that the
local header size was determined by the uncompressed and compressed sizes of
the corresponding data, which are only known after streaming of the data.
These sizes dictated whether or not a zip64 extra field entry should be
included in the header or not. Thus, before this fix there would be cases of
corruption where the final (longer) local header written by seeking back to
the beginning of the initial stub local header after the data had been
streamed would overwrite the beginning of the data.

This is fixed by

* always writing a zip64 entry in local headers, which does not violate the
  spec and will be safely ignored in the case of smaller entries, and
* respecting the spec more precisely where it says that whenever there is a
  zip64 extra field entry in a local header both uncompressed and compressed
  sizes must always be written.

This is deemed safe because the only source of size variation for local
headers is the uncompressed and compressed sizes of the corresponding data.
2024-04-20 09:33:59 +02:00
Mark Karpov 1848e8b3f9 Switch to GHC2021 2023-06-24 11:58:51 +02:00
Masahiro Sakai 04c1f22efe Introduce UnsupportedCompressionMethod
This data constructor of ZipException is defined unconditionally and
replaces BZip2Unsupported and ZstdUnsupported which previously were defined
conditionally via CPP.
2023-04-27 16:43:23 +02:00
dependabot[bot] 267a19f3c0 Bump mrkkrp/ormolu-action from 9 to 10
Bumps [mrkkrp/ormolu-action](https://github.com/mrkkrp/ormolu-action) from 9 to 10.
- [Release notes](https://github.com/mrkkrp/ormolu-action/releases)
- [Changelog](https://github.com/mrkkrp/ormolu-action/blob/master/CHANGELOG.md)
- [Commits](https://github.com/mrkkrp/ormolu-action/compare/v9...v10)

---
updated-dependencies:
- dependency-name: mrkkrp/ormolu-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-02-14 17:45:38 +01:00
Mark Karpov f9a9099f35 Write the Zip64 extra field only when it is necessary 2021-10-29 20:20:10 +02:00
Julian Ospald 630998e997 Fix build with disable-zstd/disable-bzip2 2021-06-06 16:30:18 +02:00
Mark Karpov fc967375c9 Improve the writing 2021-04-18 20:47:29 +02:00
Alexander Vershilov fc1027caa6 Set file permissions on Unix platforms
Set user permissions on linux platform as follows:

  * if an existing file is added, use its permissions
  * if an entry is generated from a bytestring or a stream, use 0600

This behavior mimics the zip utility.
2021-01-18 23:55:03 +01:00
Csaba Hruska 7dee54beb6 Add support for Zstandard (zstd) compression method 2020-09-16 16:22:56 +02:00
Mark Karpov aff36c3010 Re-format with Ormolu 0.1.2.0 2020-07-10 22:29:56 +02:00
Mark Karpov 8b358565e4 Format the source code with Ormolu 2020-04-23 22:22:12 +02:00
Mark Karpov 6816fb7ac5 Add ‘packDirRecur'’ 2020-04-12 11:48:13 +02:00
Mark Karpov 88b1484373 Fix the build for Mac 2020-03-16 20:26:39 +01:00
Alexander Vershilov 26b5746cbe Introduce helpers for setting permissions
It was very hard to set permissions using this library, as the permissions
were not properly documented. Here we try to solve the problem in 2 ways:

1. We add a low level documentation that explains how to work with
   permissions.
2. We introduce unix specific helpers that allow to describe permissions in
   a human readable way.

Unfortunately making those helpers OS agnostic is a pretty hard task we
enable them only on the Unix platforms.
2020-03-11 20:35:34 +01:00
Alexander Vershilov 72970d9e47 Add OS version to the required/made by versions
As per zip spec we may want to encode host version. This version is used by
e.g. the unzip utility in order to understand how to interpret external
info (type of files and permissions).

Current algorithm is pretty naive, we do not test for all OS versions
supported by zip. Instead we check if we run on windows and put 0 in that
case (MS-DOS and OS/2 (FAT / VFAT / FAT32 file systems). Otherwise we put 3
(UNIX).

This way code works properly on the unix OS, and we keep old behavior for
the other OS.

Note that we didn't change ‘toVersion’ function, as it already masked the
higher byte where OS information was stored.

This code was tested manually by storing archive and then unarchiving it via
unzip. There is no automated test because such test would require external
tools (unzip).
2020-03-11 20:35:34 +01:00
Moritz Kiefer 687bc036aa Ignore DoesNotExistError in removeFile
We have seen a bunch of errors on CI of the form

```
C:\users\foobar\ghcBDA1.zip: DeleteFile "\\\\?\\C:\\users\\foobar\\ghcBDA1.zip": does not exist (The system cannot find the file specified.)
```

I haven’t managed to reproduce this but looking at the code it seems
like we can be interrupted with an async exception (we kill threads
pretty aggressively) in the `bracketOnError` call after the file has
been renamed but before the whole block returns. In this case, the
file will not exist but you’ll run the cleanup in `bracketOnError`
anyway which will then fail.

We could try to fix this by masking things differently but ignoring
the error seems like a simpler and more robust solution.
2020-03-02 11:35:44 +01:00
mrkkrp d9cfb8d4a1 Add ‘since’ note for ‘BZip2Unsupported’ 2019-12-01 23:39:02 +01:00
Rodney Lorrimar 5a39029ceb Add Cabal flag to avoid the bzip2 C library dependency
The bzlib-conduit library is causing us trouble when trying to
cross-compile it for Windows.

The best thing to do in our case is to remove the dependency.

This change adds -fdisable-bzip2. Under this flag, if a caller
attempts to compress or decompress a BZip2 entry, then an exception
will be thrown.

Resolves #57
2019-11-30 16:46:42 +01:00
mrkkrp 8b4ae21a6b Replace the current year by the word “present” in copyright notes
[skip ci]
2019-07-03 21:17:43 +02:00
mrkkrp 8c9ebd1f8f Update copyright years
[skip ci]
2019-01-01 12:54:19 +07:00
mrkkrp d7eae13e34 Misc corrections 2018-09-22 21:17:55 +07:00
Ramakrishnan Muthukrishnan fe2e6cbc2d Allow to manipulate external file attributes (#52) 2018-09-22 19:39:46 +07:00
mrkkrp 1f9283d345 A couple of cosmetic changes 2018-06-23 20:13:38 +07:00
Mark Karpov bcbcd0b9de Test Zip64 features on CI (#49) 2018-06-23 18:54:58 +07:00
Mark Karpov a09152b92c Make ‘saveEntry’ and ‘unpackInto’ restore modification time (#47) 2018-05-24 11:00:44 +07:00
mrkkrp 756ba096f1 Enable more warnings 2018-03-21 19:04:07 +07:00
Mark Karpov e131160592 Stop depending on ‘path’, ‘path-io’, and ‘plan-b’ plus more (#43) 2018-02-09 20:33:35 +07:00
mrkkrp 1d2559e953 Compatibility with newer conduit 2018-02-05 23:05:18 +07:00
mrkkrp 88ed27108c Include 2018 into the copyright years range
[skip ci]
2018-01-01 13:59:31 +07:00
Mark Karpov a5f189f0fe Add some ‘monad-control’ instances for ‘ZipArchive’ (#38) 2017-08-08 22:27:20 +07:00
mrkkrp c00236f7d1 Use ‘ZipSink’ from the public Conduit API 2017-08-01 17:59:41 +07:00
Mark Karpov 3f187d099d Switch to the newer Conduit API (#37) 2017-07-31 21:19:13 +07:00
mrkkrp 2c9ed28477 Even more documentation improvements
[skip ci]
2017-05-24 20:29:57 +07:00
mrkkrp 2008d72f33 Refactor an ugly fragment of code 2017-05-24 18:26:40 +07:00
mrkkrp 0417b9afe0 Improve the documentation
[skip ci]
2017-05-24 18:26:34 +07:00
mrkkrp 783004da4a Update my email address
[skip ci]
2017-05-24 17:16:52 +07:00
mrkkrp 260efe3e11 Derive ‘Eq’ and ‘Ord’ for ‘EntrySelectorException’, ‘ZipException’ 2017-04-01 18:43:51 +03:00
mrkkrp 2f04ec8d75 Numerous cosmetic corrections to the docs 2017-04-01 18:40:39 +03:00
Alexey Karakulov 70123f3996 Allow any MonadResource for getEntrySource (#34) 2017-04-01 15:29:09 +03:00
mrkkrp d8d28e14d2 Fix the issue with mod time serialization on 32 bit systems
Close #32.
2017-03-04 23:36:24 +03:00
Rahul Muttineni e1b2a4eb23 Write correct number of entries to central directory with Zip64 (#31) 2017-02-25 17:40:08 +04:00