Skip to content
Merged
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ jobs:
fail-fast: false
matrix:
swift-version:
- 5.10
- 6.0
- 6.1
- 6.2
include:
- { swift-version: 5.10, swift-branch: swift-5.10.1-release, swift-tag: 5.10.1-RELEASE }
- { swift-version: 6.0, swift-branch: swift-6.0.3-release, swift-tag: 6.0.3-RELEASE }
- { swift-version: 6.1, swift-branch: swift-6.1-release, swift-tag: 6.1-RELEASE }
- { swift-version: 6.1, swift-branch: swift-6.1.3-release, swift-tag: 6.1.3-RELEASE }
- { swift-version: 6.2, swift-branch: swift-6.2-release, swift-tag: 6.2-RELEASE }
runs-on: windows-latest
timeout-minutes: 60
steps:
Expand Down Expand Up @@ -57,7 +57,7 @@ jobs:
cmake --build . --config Release
cmake --install . --prefix ../install
- name: Check out code
uses: actions/checkout@v4
uses: actions/checkout@v5
- name: Run unit tests
run: |
swift test -Xcc -I'C:/Program Files (x86)/zlib/include' -Xcc -D_INTSAFE_H_INCLUDED_ -Xlinker -L'C:/Program Files (x86)/zlib/lib' -Xbuild-tools-swiftc -windows-sdk-root -Xbuild-tools-swiftc "${env:WindowsSdkDir}" -Xbuild-tools-swiftc -windows-sdk-version -Xbuild-tools-swiftc ${env:UCRTVersion} -Xswiftc -windows-sdk-root -Xswiftc "${env:WindowsSdkDir}" -Xswiftc -windows-sdk-version -Xswiftc ${env:UCRTVersion}
2 changes: 1 addition & 1 deletion .swift-format
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"indentation": {
"spaces": 4
},
"indentConditionalCompilationBlocks": true,
"indentConditionalCompilationBlocks": false,
"indentSwitchCaseLabels": false,
"lineBreakAroundMultilineExpressionChainComponents": false,
"lineBreakBeforeControlFlowKeywords": false,
Expand Down
32 changes: 10 additions & 22 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
// swift-tools-version:5.10
// swift-tools-version:6.0
import PackageDescription

#if canImport(Darwin) || compiler(<6.0)
import Foundation
#else
import FoundationEssentials
#endif

let package = Package(
name: "Zip",
products: [
Expand Down Expand Up @@ -45,25 +39,19 @@ let package = Package(

var swiftSettings: [SwiftSetting] {
[
.enableUpcomingFeature("ExistentialAny"),
.enableUpcomingFeature("ConciseMagicFile"),
.enableUpcomingFeature("ForwardTrailingClosures"),
.enableUpcomingFeature("DisableOutwardActorInference"),
.enableUpcomingFeature("StrictConcurrency"),
.enableExperimentalFeature("StrictConcurrency=complete"),
.enableExperimentalFeature("AccessLevelOnImport"),
.enableUpcomingFeature("ExistentialAny")
]
}

if let target = package.targets.filter({ $0.name == "CMinizip" }).first {
if let target = package.targets.first(where: { $0.name == "CMinizip" }) {
#if os(Windows)
if ProcessInfo.processInfo.environment["ZIP_USE_DYNAMIC_ZLIB"] == nil {
target.cSettings?.append(contentsOf: [.define("ZLIB_STATIC")])
target.linkerSettings = [.linkedLibrary("zlibstatic")]
} else {
target.linkerSettings = [.linkedLibrary("zlib")]
}
if Context.environment["ZIP_USE_DYNAMIC_ZLIB"] == nil {
target.cSettings?.append(contentsOf: [.define("ZLIB_STATIC")])
target.linkerSettings = [.linkedLibrary("zlibstatic")]
} else {
target.linkerSettings = [.linkedLibrary("zlib")]
}
#else
target.linkerSettings = [.linkedLibrary("z")]
target.linkerSettings = [.linkedLibrary("z")]
#endif
}
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
<img src="https://img.shields.io/github/actions/workflow/status/vapor-community/Zip/test.yml?event=push&style=plastic&logo=github&label=tests&logoColor=%23ccc" alt="Continuous Integration">
</a>
<a href="https://codecov.io/github/vapor-community/Zip">
<img src="https://img.shields.io/codecov/c/github/vapor-community/Zip?style=plastic&logo=codecov&label=codecov">
<img src="https://img.shields.io/codecov/c/github/vapor-community/Zip?style=plastic&logo=codecov&label=codecov" alt="Code Coverage">
</a>
<a href="https://swift.org">
<img src="https://design.vapor.codes/images/swift59up.svg" alt="Swift 5.10+">
<img src="https://design.vapor.codes/images/swift60up.svg" alt="Swift 6.0+">
</a>
</div>
<br>
Expand Down Expand Up @@ -40,7 +40,7 @@ and add it to your target's dependencies:

### Supported Platforms

Zip supports all platforms supported by Swift 5.10 and later.
Zip supports all platforms supported by Swift 6.0 and later.

To use Zip on Windows, you need to pass an available build of `zlib` to the build via extended flags. For example:

Expand Down
6 changes: 3 additions & 3 deletions Sources/Zip/Date+dosDate.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#if canImport(Darwin) || compiler(<6.0)
import Foundation
#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import FoundationEssentials
import Foundation
#endif

extension Date {
Expand Down
10 changes: 5 additions & 5 deletions Sources/Zip/QuickZip.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
// Copyright © 2016 Roy Marmelstein. All rights reserved.
//

#if canImport(Darwin) || compiler(<6.0)
import Foundation
#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import FoundationEssentials
import Foundation
#endif

extension Zip {
Expand All @@ -23,7 +23,7 @@ extension Zip {
///
/// - Returns: `URL` of the destination folder.
public class func quickUnzipFile(_ path: URL) throws -> URL {
return try quickUnzipFile(path, progress: nil)
try quickUnzipFile(path, progress: nil)
}

/// Unzips a file with less configuration.
Expand Down Expand Up @@ -57,7 +57,7 @@ extension Zip {
///
/// - Returns: `URL` of the destination folder.
public class func quickZipFiles(_ paths: [URL], fileName: String) throws -> URL {
return try quickZipFiles(paths, fileName: fileName, progress: nil)
try quickZipFiles(paths, fileName: fileName, progress: nil)
}

/// Zips files with less configuration.
Expand Down
8 changes: 4 additions & 4 deletions Sources/Zip/URL+nativePath.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#if canImport(Darwin) || compiler(<6.0)
import Foundation
#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import FoundationEssentials
import Foundation
#endif

extension URL {
var nativePath: String {
return withUnsafeFileSystemRepresentation { String(cString: $0!) }
withUnsafeFileSystemRepresentation { String(cString: $0!) }
}
}
2 changes: 1 addition & 1 deletion Sources/Zip/Zip.docc/Documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ and add it to your target's dependencies:

### Supported Platforms

Zip supports all platforms supported by Swift 5.10 and later.
Zip supports all platforms supported by Swift 6.0 and later.

To use Zip on Windows, you need to pass an available build of `zlib` to the build via extended flags. For example:

Expand Down
47 changes: 21 additions & 26 deletions Sources/Zip/Zip.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public class Zip {
}

#if os(Windows)
var fileNames = Set<String>()
var fileNames = Set<String>()
#endif

var buffer = [CUnsignedChar](repeating: 0, count: 4096)
Expand Down Expand Up @@ -101,23 +101,23 @@ public class Zip {
var pathString = String(cString: fileName)

#if os(Windows)
// Windows Reserved Characters
let reservedCharacters: CharacterSet = ["<", ">", ":", "\"", "|", "?", "*"]

if pathString.rangeOfCharacter(from: reservedCharacters) != nil {
pathString = pathString.components(separatedBy: reservedCharacters).joined(separator: "_")

let pathExtension = (pathString as NSString).pathExtension
let pathWithoutExtension = (pathString as NSString).deletingPathExtension
var counter = 1
while fileNames.contains(pathString) {
let newFileName = "\(pathWithoutExtension) (\(counter))"
pathString = pathExtension.isEmpty ? newFileName : newFileName.appendingPathExtension(pathExtension) ?? newFileName
counter += 1
}
// Windows Reserved Characters
let reservedCharacters: CharacterSet = ["<", ">", ":", "\"", "|", "?", "*"]

if pathString.rangeOfCharacter(from: reservedCharacters) != nil {
pathString = pathString.components(separatedBy: reservedCharacters).joined(separator: "_")

let pathExtension = (pathString as NSString).pathExtension
let pathWithoutExtension = (pathString as NSString).deletingPathExtension
var counter = 1
while fileNames.contains(pathString) {
let newFileName = "\(pathWithoutExtension) (\(counter))"
pathString = pathExtension.isEmpty ? newFileName : newFileName.appendingPathExtension(pathExtension) ?? newFileName
counter += 1
}
}

fileNames.insert(pathString)
fileNames.insert(pathString)
#endif

guard !pathString.isEmpty else {
Expand All @@ -136,16 +136,11 @@ public class Zip {
throw ZipError.unzipFail
}

let directoryAttributes: [FileAttributeKey: Any]?
#if (os(Linux) || os(Windows)) && compiler(<6.0)
directoryAttributes = nil
#else
let creationDate = Date()
directoryAttributes = [
.creationDate: creationDate,
.modificationDate: creationDate,
]
#endif
let creationDate = Date()
let directoryAttributes: [FileAttributeKey: Any]? = [
.creationDate: creationDate,
.modificationDate: creationDate,
]

let isDirectory =
fileName[Int(fileInfo.size_filename - 1)] == "/".cString(using: String.Encoding.utf8)?.first
Expand Down
12 changes: 4 additions & 8 deletions Sources/Zip/ZipCompression.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,10 @@ public enum ZipCompression: Int {

internal var minizipCompression: Int32 {
switch self {
case .NoCompression:
return Z_NO_COMPRESSION
case .BestSpeed:
return Z_BEST_SPEED
case .DefaultCompression:
return Z_DEFAULT_COMPRESSION
case .BestCompression:
return Z_BEST_COMPRESSION
case .NoCompression: Z_NO_COMPRESSION
case .BestSpeed: Z_BEST_SPEED
case .DefaultCompression: Z_DEFAULT_COMPRESSION
case .BestCompression: Z_BEST_COMPRESSION
}
}
}
6 changes: 3 additions & 3 deletions Sources/Zip/ZipError.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#if canImport(Darwin) || compiler(<6.0)
import Foundation
#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import FoundationEssentials
import Foundation
#endif

/// Errors that can be thrown by Zip.
Expand Down
Loading
Loading