Skip to content

Commit

Permalink
Merge branch 'development' into enhancement/throwingArchiveInit
Browse files Browse the repository at this point in the history
  • Loading branch information
weichsel authored Aug 16, 2023
2 parents e272da8 + 1f10742 commit 6f4dc69
Show file tree
Hide file tree
Showing 16 changed files with 79 additions and 34 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ jobs:
Xcode:
strategy:
matrix:
xcode_version: ['13.2.1', '13.1', '13.0', '12.5.1', '12.4', '11.7']
runs-on: macos-11
xcode_version: ['13.3.1', '13.4', '14.0.1', '14.1', '14.2']
runs-on: macos-12
env:
DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode_version }}.app
steps:
Expand Down
2 changes: 1 addition & 1 deletion [email protected]
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// swift-tools-version:4.0
import PackageDescription

#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
#if os(macOS) || os(iOS) || os(tvOS) || os(visionOS) || os(watchOS)
let dependencies: [Package.Dependency] = []
#else
let dependencies: [Package.Dependency] = [.package(url: "https://github.com/IBM-Swift/CZlib.git", .exact("0.1.2"))]
Expand Down
27 changes: 27 additions & 0 deletions [email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// swift-tools-version:5.9
import PackageDescription

#if canImport(Compression)
let targets: [Target] = [
.target(name: "ZIPFoundation"),
.testTarget(name: "ZIPFoundationTests", dependencies: ["ZIPFoundation"])
]
#else
let targets: [Target] = [
.systemLibrary(name: "CZLib", pkgConfig: "zlib", providers: [.brew(["zlib"]), .apt(["zlib"])]),
.target(name: "ZIPFoundation", dependencies: ["CZLib"], cSettings: [.define("_GNU_SOURCE", to: "1")]),
.testTarget(name: "ZIPFoundationTests", dependencies: ["ZIPFoundation"])
]
#endif

let package = Package(
name: "ZIPFoundation",
platforms: [
.macOS(.v10_11), .iOS(.v9), .tvOS(.v9), .watchOS(.v2), .visionOS(.v1)
],
products: [
.library(name: "ZIPFoundation", targets: ["ZIPFoundation"])
],
targets: targets,
swiftLanguageVersions: [.v4, .v4_2, .v5]
)
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![Swift Package Manager compatible](https://img.shields.io/badge/SPM-compatible-brightgreen.svg)](https://github.com/apple/swift-package-manager)
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
[![CocoaPods Compatible](https://img.shields.io/cocoapods/v/ZIPFoundation.svg)](https://cocoapods.org/pods/ZIPFoundation)
[![Platform](https://img.shields.io/badge/Platforms-macOS%20|%20iOS%20|%20tvOS%20|%20watchOS%20|%20Linux-lightgrey.svg)](https://github.com/weichsel/ZIPFoundation)
[![Platform](https://img.shields.io/badge/Platforms-macOS%20|%20iOS%20|%20tvOS%20|%20watchOS%20|%20visionOS%20|%20Linux-lightgrey.svg)](https://github.com/weichsel/ZIPFoundation)
[![Twitter](https://img.shields.io/badge/[email protected]?style=flat)](http://twitter.com/weichsel)

ZIP Foundation is a library to create, read and modify ZIP archive files.
Expand Down Expand Up @@ -40,7 +40,7 @@ To learn more about the performance characteristics of the framework, you can re

## Requirements

- iOS 12.0+ / macOS 10.11+ / tvOS 12.0+ / watchOS 2.0+
- iOS 12.0+ / macOS 10.11+ / tvOS 12.0+ / watchOS 2.0+ / visionOS 1.0+
- Or Linux with zlib development package
- Xcode 11.0
- Swift 4.0
Expand Down
4 changes: 2 additions & 2 deletions Sources/ZIPFoundation/Archive+MemoryFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class MemoryFile {
let cookie = Unmanaged.passRetained(self)
let writable = mode.count > 0 && (mode.first! != "r" || mode.last! == "+")
let append = mode.count > 0 && mode.first! == "a"
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(Android)
#if os(macOS) || os(iOS) || os(tvOS) || os(visionOS) || os(watchOS) || os(Android)
let result = writable
? funopen(cookie.toOpaque(), readStub, writeStub, seekStub, closeStub)
: funopen(cookie.toOpaque(), readStub, nil, seekStub, closeStub)
Expand Down Expand Up @@ -99,7 +99,7 @@ private func closeStub(_ cookie: UnsafeMutableRawPointer?) -> Int32 {
return 0
}

#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(Android)
#if os(macOS) || os(iOS) || os(tvOS) || os(visionOS) || os(watchOS) || os(Android)
private func readStub(_ cookie: UnsafeMutableRawPointer?,
_ bytePtr: UnsafeMutablePointer<Int8>?,
_ count: Int32) -> Int32 {
Expand Down
2 changes: 1 addition & 1 deletion Sources/ZIPFoundation/Archive+Writing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ extension Archive {
#endif
} else {
let fileManager = FileManager()
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
#if os(macOS) || os(iOS) || os(tvOS) || os(visionOS) || os(watchOS)
do {
_ = try fileManager.replaceItemAt(self.url, withItemAt: archive.url)
} catch {
Expand Down
8 changes: 4 additions & 4 deletions Sources/ZIPFoundation/Data+Compression.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ extension Data {
/// - consumer: A closure that processes the result of the compress operation.
/// - Returns: The checksum of the processed content.
public static func compress(size: Int64, bufferSize: Int, provider: Provider, consumer: Consumer) throws -> CRC32 {
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
#if os(macOS) || os(iOS) || os(tvOS) || os(visionOS) || os(watchOS)
return try self.process(operation: COMPRESSION_STREAM_ENCODE, size: size, bufferSize: bufferSize,
provider: provider, consumer: consumer)
#else
Expand All @@ -84,7 +84,7 @@ extension Data {
/// - Returns: The checksum of the processed content.
public static func decompress(size: Int64, bufferSize: Int, skipCRC32: Bool,
provider: Provider, consumer: Consumer) throws -> CRC32 {
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
#if os(macOS) || os(iOS) || os(tvOS) || os(visionOS) || os(watchOS)
return try self.process(operation: COMPRESSION_STREAM_DECODE, size: size, bufferSize: bufferSize,
skipCRC32: skipCRC32, provider: provider, consumer: consumer)
#else
Expand All @@ -95,7 +95,7 @@ extension Data {

// MARK: - Apple Platforms

#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
#if os(macOS) || os(iOS) || os(tvOS) || os(visionOS) || os(watchOS)
import Compression

extension Data {
Expand Down Expand Up @@ -351,7 +351,7 @@ extension Data {
}
}

#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
#if os(macOS) || os(iOS) || os(tvOS) || os(visionOS) || os(watchOS)
#else
mutating func withUnsafeMutableBytes<T>(_ body: (UnsafeMutableRawBufferPointer) throws -> T) rethrows -> T {
let count = self.count
Expand Down
4 changes: 2 additions & 2 deletions Sources/ZIPFoundation/Date+ZIP.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ extension Date {
private extension Date {

enum Constants {
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
#if os(macOS) || os(iOS) || os(tvOS) || os(visionOS) || os(watchOS)
static let absoluteTimeIntervalSince1970 = kCFAbsoluteTimeIntervalSince1970
#else
static let absoluteTimeIntervalSince1970: Double = 978307200.0
Expand All @@ -77,7 +77,7 @@ private extension Date {
extension stat {

var lastAccessDate: Date {
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
#if os(macOS) || os(iOS) || os(tvOS) || os(visionOS) || os(watchOS)
return Date(timespec: st_atimespec)
#else
return Date(timespec: st_atim)
Expand Down
8 changes: 4 additions & 4 deletions Sources/ZIPFoundation/FileManager+ZIP.swift
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ extension FileManager {
return
}

#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
#if os(macOS) || os(iOS) || os(tvOS) || os(visionOS) || os(watchOS)
guard let posixPermissions = attributes[.posixPermissions] as? NSNumber else {
throw Entry.EntryError.missingPermissionsAttributeError
}
Expand Down Expand Up @@ -220,7 +220,7 @@ extension FileManager {
let defaultPermissions = entryType == .directory ? defaultDirectoryPermissions : defaultFilePermissions
var attributes = [.posixPermissions: defaultPermissions] as [FileAttributeKey: Any]
// Certain keys are not yet supported in swift-corelibs
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
#if os(macOS) || os(iOS) || os(tvOS) || os(visionOS) || os(watchOS)
attributes[.modificationDate] = Date(dateTime: (fileDate, fileTime))
#endif
let versionMadeBy = centralDirectoryStructure.versionMadeBy
Expand Down Expand Up @@ -276,7 +276,7 @@ extension FileManager {
let entryFileSystemRepresentation = fileManager.fileSystemRepresentation(withPath: url.path)
var fileStat = stat()
lstat(entryFileSystemRepresentation, &fileStat)
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
#if os(macOS) || os(iOS) || os(tvOS) || os(visionOS) || os(watchOS)
let modTimeSpec = fileStat.st_mtimespec
#else
let modTimeSpec = fileStat.st_mtim
Expand Down Expand Up @@ -327,7 +327,7 @@ extension CocoaError {
#if swift(>=4.2)
#else

#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
#if os(macOS) || os(iOS) || os(tvOS) || os(visionOS) || os(watchOS)
#else

// The swift-corelibs-foundation version of NSError.swift was missing a convenience method to create
Expand Down
2 changes: 1 addition & 1 deletion Sources/ZIPFoundation/URL+ZIP.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Foundation
extension URL {

static func temporaryReplacementDirectoryURL(for archive: Archive) -> URL {
#if swift(>=5.0) || os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
#if swift(>=5.0) || os(macOS) || os(iOS) || os(tvOS) || os(visionOS) || os(watchOS)
if archive.url.isFileURL,
let tempDir = try? FileManager().url(for: .itemReplacementDirectory, in: .userDomainMask,
appropriateFor: archive.url, create: true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ extension ZIPFoundationTests {
} catch {
XCTFail("Unexpected error while trying to transfer symlink attributes")
}
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
#if os(macOS) || os(iOS) || os(tvOS) || os(visionOS) || os(watchOS)
do {
var resourceValues = URLResourceValues()
resourceValues.isUserImmutable = true
Expand Down
25 changes: 21 additions & 4 deletions Tests/ZIPFoundationTests/ZIPFoundationFileManagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,11 @@ extension ZIPFoundationTests {
}

let shellZIPURL = shellZIP(directoryAtURL: testBundleURL)
let shellZIPInfos = Set(ZIPInfo.makeZIPInfos(forArchiveAtURL: shellZIPURL, mode: .shellParsing))
let builtInZIPInfos = Set(ZIPInfo.makeZIPInfos(forArchiveAtURL: builtInZIPURL, mode: .directoryIteration))
let diff = builtInZIPInfos.symmetricDifference(shellZIPInfos)
XCTAssert(diff.count == 0)
let shellZIPInfos = ZIPInfo.makeZIPInfos(forArchiveAtURL: shellZIPURL, mode: .shellParsing)
.sorted { $0.path < $1.path }
let builtInZIPInfos = ZIPInfo.makeZIPInfos(forArchiveAtURL: builtInZIPURL, mode: .directoryIteration)
.sorted { $0.path < $1.path }
XCTAssert(shellZIPInfos == builtInZIPInfos)
#endif
}
}
Expand Down Expand Up @@ -285,6 +286,22 @@ private struct ZIPInfo: Hashable {
}
}

extension ZIPInfo: Equatable {

static func == (lhs: Self, rhs: Self) -> Bool {
let hasSamePath = lhs.path == rhs.path
let hasSameSize = lhs.size == rhs.size
// ZIP date/timesstamps have very low resolution. We have to compare with some leeway.
let startDate = lhs.modificationDate.addingTimeInterval(-2)
let endDate = lhs.modificationDate.addingTimeInterval(+2)
let dateRange = startDate...endDate
let hasSameDate = dateRange.contains(rhs.modificationDate)
return hasSamePath &&
hasSameSize &&
hasSameDate
}
}

private extension URL {

static func makeRelativePath(fromPath path: String, relativeToPath basePath: String, isDirectory: Bool) -> String {
Expand Down
5 changes: 3 additions & 2 deletions Tests/ZIPFoundationTests/ZIPFoundationMemoryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ extension ZIPFoundationTests {
XCTAssert(archive.checkIntegrity())
// Trigger the code path that is taken if funopen() fails
// We can only do this on Apple platforms
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
#if os(macOS) || os(iOS) || os(tvOS) || os(visionOS) || os(watchOS)
let entryRemoval = {
self.XCTAssertSwiftError(try archive.remove(entryToRemove),
throws: Archive.ArchiveError.unreadableArchive)
Expand Down Expand Up @@ -140,11 +140,12 @@ extension ZIPFoundationTests {
throws: Archive.ArchiveError.missingEndOfCentralDirectoryRecord)
// Trigger the code path that is taken if funopen() fails
// We can only do this on Apple platforms
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
#if os(macOS) || os(iOS) || os(tvOS) || os(visionOS) || os(watchOS)
let archiveCreation = {
self.XCTAssertSwiftError(try Archive(data: data, accessMode: .read),
throws: Archive.ArchiveError.unreadableArchive)
}

self.runWithoutMemory {
try? archiveCreation()
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/ZIPFoundationTests/ZIPFoundationProgressTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import XCTest
@testable import ZIPFoundation

#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
#if os(macOS) || os(iOS) || os(tvOS) || os(visionOS) || os(watchOS)
extension ZIPFoundationTests {

func testArchiveAddUncompressedEntryProgress() {
Expand Down
10 changes: 5 additions & 5 deletions Tests/ZIPFoundationTests/ZIPFoundationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class ZIPFoundationTests: XCTestCase {
}

func runWithFileDescriptorLimit(_ limit: UInt64, handler: () throws -> Void) rethrows {
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(Android)
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(visionOS) || os(Android)
let fileNoFlag = RLIMIT_NOFILE
#else
let fileNoFlag = Int32(RLIMIT_NOFILE.rawValue)
Expand All @@ -155,7 +155,7 @@ class ZIPFoundationTests: XCTestCase {
}

func runWithoutMemory(handler: () -> Void) {
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
#if os(macOS) || os(iOS) || os(tvOS) || os(visionOS) || os(watchOS)
let systemAllocator = CFAllocatorGetDefault().takeUnretainedValue()
CFAllocatorSetDefault(kCFAllocatorNull)
defer { CFAllocatorSetDefault(systemAllocator) }
Expand All @@ -182,7 +182,7 @@ class ZIPFoundationTests: XCTestCase {
extension ZIPFoundationTests {
// From https://oleb.net/blog/2017/03/keeping-xctest-in-sync/
func testLinuxTestSuiteIncludesAllTests() {
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
#if os(macOS) || os(iOS) || os(tvOS) || os(visionOS) || os(watchOS)
let thisClass = type(of: self)
let linuxCount = thisClass.allTests.count
let darwinCount = Int(thisClass.defaultTestSuite.testCaseCount)
Expand Down Expand Up @@ -299,7 +299,7 @@ extension ZIPFoundationTests {
}

static var darwinOnlyTests: [(String, (ZIPFoundationTests) -> () throws -> Void)] {
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
#if os(macOS) || os(iOS) || os(tvOS) || os(visionOS) || os(watchOS)
return [
("testFileModificationDate", testFileModificationDate),
("testFileModificationDateHelperMethods", testFileModificationDateHelperMethods),
Expand Down Expand Up @@ -366,7 +366,7 @@ extension Archive {

extension Data {
static func makeRandomData(size: Int) -> Data {
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(visionOS)
let bytes = [UInt32](repeating: 0, count: size).map { _ in UInt32.random(in: 0...UInt32.max) }
#else
let bytes = [UInt32](repeating: 0, count: size).map { _ in random() }
Expand Down
4 changes: 2 additions & 2 deletions ZIPFoundation.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@
OTHER_SWIFT_FLAGS = "-DXcode";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = "";
SUPPORTED_PLATFORMS = "macosx iphoneos iphonesimulator appletvos appletvsimulator watchos watchsimulator";
SUPPORTED_PLATFORMS = "macosx iphoneos iphonesimulator appletvos appletvsimulator watchos watchsimulator xrsimulator xros";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.0;
Expand Down Expand Up @@ -496,7 +496,7 @@
OTHER_SWIFT_FLAGS = "-DXcode";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = "";
SUPPORTED_PLATFORMS = "macosx iphoneos iphonesimulator appletvos appletvsimulator watchos watchsimulator";
SUPPORTED_PLATFORMS = "macosx iphoneos iphonesimulator appletvos appletvsimulator watchos watchsimulator xrsimulator xros";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 4.0;
TVOS_DEPLOYMENT_TARGET = 12.0;
Expand Down

0 comments on commit 6f4dc69

Please sign in to comment.