Wanted: ZIP package for macOS + Linux + Windows

I have found the fork by @gregcotten of ZIPFoundation which actually works well on macOS, Linux, and Windows (thanks!), but on non-Apple platforms the integrated sources of CZLib are compiled with an unsafe flag. With this unsafe flag you have to reference a commit number if directly used in your package, and if the usage is indirect, you need to reference a local package.

Question 1: Can I use this package (in another referenced package) without having to use a locally referenced package? (I think not.)

Question 2: I think a good cross platform ZIP (compression) package would be nice, maybe as part of the standard libraries? Maybe in the new Foundation as soon as it is stable?

2 Likes

Hi! Yes, I made an attempt at making ZIPFoundation compatible with Windows, and it seems to work!

I didn't realize this! The unsafe flag just silences a warning "-Wno-shorten-64-to-32", perhaps we can just fix the warnings instead of silencing them. I've removed the unsafe flag and committed to my fork.

Agreed. Also, as I recall trying to get Foundation.Progress working was a non-starter (couldn't observe any properties of it on non-Apple) so I ended up using some random open-source progress framework instead since I didn't want to reinvent the wheel.

4 Likes

Thank you for your answer.

I tried without the unsafe flag, and now on Windows I indeed get a lot of linker warnings "locally defined symbol imported" (for parts produced from Swift sources!), compare this other topic. The resulting program seems to work fine, but yes, it would be nice if this could be fixed (someone help?).

One more little "barrier" for the use of your fork is that your changes reside inside a "development" branch (branches are also judged as "unstable" by the SPM), I needed to fork your repo, merge this branch into main and also needed to set a version tag. (I will not link here to my fork since I think your fork should be the deciding one, but this might be reason that so many forks exist of your repo. Or what about a pull request for weichsel/ZIPFoundation at some point?)

OK fixed. You should be able to use:

.package(url: "https://github.com/gregcotten/ZIPFoundationModern", .upToNextMajor(from: "0.0.1")),

That's actually the total number of forks that the original repo had, not mine!

I had to make some aggressive changes and I'm not sure they'd be up for the PR.

Just for a little context: I was in somewhat of a rush to deploy a Windows Swift+Electron app (now running on thousands of customers Windows PCs!) and just needed something to work and hacked this together.

3 Likes

I've been using Zip on macOS and Linux. It has no other dependencies and might work on Windows.

FWIW, there are quite a number of zip packages in the package index.

Is compression framework available under Linux?

Sadly is does not work on Windows:

C:\Projekte\sspringer\Zip>swift build -c release
Building for production...
C:\Projekte\sspringer\Zip\Zip\minizip\zip.c:21:10: fatal error: 'zlib.h' file not found
#include <zlib.h>
         ^~~~~~~~
1 error generated.
[0/3] Compiling Minizip zip.c

Especially when you have to support macOS + Linux + Windows, and you have a problem at hand where non-pure Swift packages are common like in the case of file compression, the Swift Package Index can only be the start of a search, because there is no indication for Windows support in the Swift Package Index, see the other forums topic just started by me.

In the mentioned fork of ZIPFoundationModern, there is a test #if canImport(Compression), compiling the C sources of CZLib if it fails, and I see the compilation of e.g. CZLib/compress.c when compiling it on Linux. From that observation I would say the compression framework is not available on Linux.

The fact that the header is not found does not mean it does not work on Windows. It means that it is not dependency free and it does not properly indicate that. It has a dependency on zlib and that is not accounted for.

The package can work on Windows fairly straightforwardly:

Build complete! (2.17s)
Test Suite 'All tests' started at 2023-08-19 11:20:53.998
Test Suite 'debug.xctest' started at 2023-08-19 11:20:53.998
Test Suite 'ZipTests' started at 2023-08-19 11:20:53.998
Test Case 'ZipTests.testAddedCustomFileExtensionIsValid' started at 2023-08-19 11:20:53.998
Test Case 'ZipTests.testAddedCustomFileExtensionIsValid' passed (0.0 seconds)
Test Case 'ZipTests.testDefaultFileExtensionsIsNotRemoved' started at 2023-08-19 11:20:53.998
Test Case 'ZipTests.testDefaultFileExtensionsIsNotRemoved' passed (0.0 seconds)
Test Case 'ZipTests.testDefaultFileExtensionsIsValid' started at 2023-08-19 11:20:53.998
Test Case 'ZipTests.testDefaultFileExtensionsIsValid' passed (0.0 seconds)
Test Case 'ZipTests.testFileExtensionIsInvalidForInvalidUrl' started at 2023-08-19 11:20:53.998
Test Case 'ZipTests.testFileExtensionIsInvalidForInvalidUrl' passed (0.0 seconds)
Test Case 'ZipTests.testFileExtensionIsNotInvalidForValidUrl' started at 2023-08-19 11:20:53.998
Test Case 'ZipTests.testFileExtensionIsNotInvalidForValidUrl' passed (0.0 seconds)
Test Case 'ZipTests.testImplicitProgressUnzip' started at 2023-08-19 11:20:53.998
Test Case 'ZipTests.testImplicitProgressUnzip' passed (0.062 seconds)
Test Case 'ZipTests.testImplicitProgressZip' started at 2023-08-19 11:20:54.060
Test Case 'ZipTests.testImplicitProgressZip' passed (0.0 seconds)
Test Case 'ZipTests.testQuickUnzip' started at 2023-08-19 11:20:54.060
Test Case 'ZipTests.testQuickUnzip' passed (0.047 seconds)
Test Case 'ZipTests.testQuickUnzipNonExistingPath' started at 2023-08-19 11:20:54.107
Test Case 'ZipTests.testQuickUnzipNonExistingPath' passed (0.015 seconds)
Test Case 'ZipTests.testQuickUnzipNonZipPath' started at 2023-08-19 11:20:54.122
Test Case 'ZipTests.testQuickUnzipNonZipPath' passed (0.0 seconds)
Test Case 'ZipTests.testQuickUnzipOnlineURL' started at 2023-08-19 11:20:54.122
Test Case 'ZipTests.testQuickUnzipOnlineURL' passed (0.0 seconds)
Test Case 'ZipTests.testQuickUnzipProgress' started at 2023-08-19 11:20:54.122
Test Case 'ZipTests.testQuickUnzipProgress' passed (0.047 seconds)
Test Case 'ZipTests.testQuickUnzipSubDir' started at 2023-08-19 11:20:54.169
Test Case 'ZipTests.testQuickUnzipSubDir' passed (0.052 seconds)
Test Case 'ZipTests.testQuickZip' started at 2023-08-19 11:20:54.221
Test Case 'ZipTests.testQuickZip' passed (0.002 seconds)
Test Case 'ZipTests.testQuickZipFolder' started at 2023-08-19 11:20:54.223
Test Case 'ZipTests.testQuickZipFolder' passed (0.04 seconds)
Test Case 'ZipTests.testRemovedCustomFileExtensionIsInvalid' started at 2023-08-19 11:20:54.263
Test Case 'ZipTests.testRemovedCustomFileExtensionIsInvalid' passed (0.0 seconds)
Test Case 'ZipTests.testUnzip' started at 2023-08-19 11:20:54.263
Test Case 'ZipTests.testUnzip' passed (0.063 seconds)
Test Case 'ZipTests.testUnzipPermissions' started at 2023-08-19 11:20:54.326
Test Case 'ZipTests.testUnzipPermissions' passed (0.015 seconds)
Test Case 'ZipTests.testUnzipWithUnsupportedPermissions' started at 2023-08-19 11:20:54.341
Test Case 'ZipTests.testUnzipWithUnsupportedPermissions' passed (0.0 seconds)
Test Case 'ZipTests.testZip' started at 2023-08-19 11:20:54.341
Test Case 'ZipTests.testZip' passed (0.016 seconds)
Test Case 'ZipTests.testZipUnzipPassword' started at 2023-08-19 11:20:54.357
Test Case 'ZipTests.testZipUnzipPassword' passed (0.031 seconds)
Test Suite 'ZipTests' passed at 2023-08-19 11:20:54.388
Executed 21 tests, with 0 failures (0 unexpected) in 0.39 (0.39) seconds
Test Suite 'debug.xctest' passed at 2023-08-19 11:20:54.388
         Executed 21 tests, with 0 failures (0 unexpected) in 0.39 (0.39) seconds
Test Suite 'All tests' passed at 2023-08-19 11:20:54.388
         Executed 21 tests, with 0 failures (0 unexpected) in 0.39 (0.39) seconds

While true that the package does have portability issues, it took maybe 10m to sort out the package.

Edit: for the interested party: Windows Support by compnerd · Pull Request #246 · marmelroy/Zip · GitHub is the superset of the requisite changes.

1 Like