Skip to content

Commit

Permalink
Fixed Swift 3 and macOS compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
colemancda committed Sep 15, 2018
1 parent 9151c7e commit d83af64
Show file tree
Hide file tree
Showing 14 changed files with 29 additions and 5 deletions.
1 change: 1 addition & 0 deletions Sources/ZIPFoundation/Archive+Reading.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import Foundation

@available(macOS 10.11, *)
extension Archive {
/// Read a ZIP `Entry` from the receiver and write it to `url`.
///
Expand Down
1 change: 1 addition & 0 deletions Sources/ZIPFoundation/Archive+Writing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import Foundation

@available(macOS 10.11, *)
extension Archive {
private enum ModifyOperation: Int {
case remove = -1
Expand Down
4 changes: 4 additions & 0 deletions Sources/ZIPFoundation/Archive.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public enum CompressionMethod: UInt16 {
/// var archiveURL = URL(fileURLWithPath: "/path/file.zip")
/// var archive = Archive(url: archiveURL, accessMode: .update)
/// try archive?.addEntry("test.txt", relativeTo: baseURL, compressionMethod: .deflate)

@available(macOS 10.11, *)
public final class Archive: Sequence {
typealias LocalFileHeader = Entry.LocalFileHeader
typealias DataDescriptor = Entry.DataDescriptor
Expand Down Expand Up @@ -243,6 +245,7 @@ public final class Archive: Sequence {
}
}

@available(macOS 10.11, *)
extension Archive {
/// The number of the work units that have to be performed when
/// removing `entry` from the receiver.
Expand Down Expand Up @@ -301,6 +304,7 @@ extension Archive {
}
}

@available(macOS 10.11, *)
extension Archive.EndOfCentralDirectoryRecord {
var data: Data {
var endOfCentralDirectorySignature = self.endOfCentralDirectorySignature
Expand Down
2 changes: 2 additions & 0 deletions Sources/ZIPFoundation/Data+Compression.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public let crcTable: [UInt32] = [
0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
0x2d02ef8d]

@available(macOS 10.11, *)
extension Data {
enum CompressionError: Error {
case invalidStream
Expand Down Expand Up @@ -137,6 +138,7 @@ extension Data {
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
import Compression

@available(macOS 10.11, *)
extension Data {
@inline(__always)
static func process(operation: compression_stream_operation, size: Int, bufferSize: Int,
Expand Down
1 change: 1 addition & 0 deletions Sources/ZIPFoundation/Data+Serialization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ protocol DataSerializable {
var data: Data { get }
}

@available(macOS 10.11, *)
extension Data {
enum DataError: Error {
case unreadableFile
Expand Down
4 changes: 4 additions & 0 deletions Sources/ZIPFoundation/Entry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import CoreFoundation
///
/// You can retrieve instances of `Entry` from an `Archive` via subscripting or iteration.
/// Entries are identified by their `path`.
@available(macOS 10.11, *)
public struct Entry: Equatable {
/// The type of an `Entry` in a ZIP `Archive`.
public enum EntryType: Int {
Expand Down Expand Up @@ -203,6 +204,7 @@ public struct Entry: Equatable {
}
}

@available(macOS 10.11, *)
extension Entry.LocalFileHeader {
var data: Data {
var localFileHeaderSignature = self.localFileHeaderSignature
Expand Down Expand Up @@ -257,6 +259,7 @@ extension Entry.LocalFileHeader {
}
}

@available(macOS 10.11, *)
extension Entry.CentralDirectoryStructure {
var data: Data {
var centralDirectorySignature = self.centralDirectorySignature
Expand Down Expand Up @@ -378,6 +381,7 @@ extension Entry.CentralDirectoryStructure {
}
}

@available(macOS 10.11, *)
extension Entry.DataDescriptor {
init?(data: Data, additionalDataProvider provider: (Int) throws -> Data) {
guard data.count == Entry.DataDescriptor.size else { return nil }
Expand Down
1 change: 1 addition & 0 deletions Sources/ZIPFoundation/FileManager+ZIP.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import Foundation

@available(macOS 10.11, *)
extension FileManager {
typealias CentralDirectoryStructure = Entry.CentralDirectoryStructure

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import XCTest
@testable import ZIPFoundation

@available(macOS 10.11, *)
extension ZIPFoundationTests {
func testReadStructureErrorConditions() {
let processInfo = ProcessInfo.processInfo
Expand Down
1 change: 1 addition & 0 deletions Tests/ZIPFoundationTests/ZIPFoundationEntryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import XCTest
@testable import ZIPFoundation

@available(macOS 10.11, *)
extension ZIPFoundationTests {
func testEntryWrongDataLengthErrorConditions() {
let emptyCDS = Entry.CentralDirectoryStructure(data: Data(),
Expand Down
6 changes: 4 additions & 2 deletions Tests/ZIPFoundationTests/ZIPFoundationFileManagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import XCTest
@testable import ZIPFoundation

@available(macOS 10.11, *)
extension ZIPFoundationTests {
func testZipItem() {
let fileManager = FileManager()
Expand Down Expand Up @@ -404,9 +405,10 @@ extension ZIPFoundationTests {
// MARK: - Swift 3 compatibility

#if swift(>=4.0)
#else
#elseif swift(>=3.0)
internal extension FileManager {


@objc(swiftCreateFileAtPath:contents:attributes:)
@discardableResult
func createFile(atPath path: String,
contents: Data? = nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import XCTest
@testable import ZIPFoundation

@available(macOS 10.11, *)
extension ZIPFoundationTests {
func testPerformanceWriteUncompressed() {
let archive = self.archive(for: #function, mode: .create)
Expand Down
1 change: 1 addition & 0 deletions Tests/ZIPFoundationTests/ZIPFoundationReadingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import XCTest
@testable import ZIPFoundation

@available(macOS 10.11, *)
extension ZIPFoundationTests {
func testExtractUncompressedFolderEntries() {
let archive = self.archive(for: #function, mode: .read)
Expand Down
9 changes: 6 additions & 3 deletions Tests/ZIPFoundationTests/ZIPFoundationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ enum AdditionalDataError: Error {
case invalidDataError
}

class ZIPFoundationTests: XCTestCase {
@available(macOS 10.11, *)
final class ZIPFoundationTests: XCTestCase {
class var testBundle: Bundle {
return Bundle(for: self)
}
Expand Down Expand Up @@ -235,6 +236,7 @@ class ZIPFoundationTests: XCTestCase {

}

@available(macOS 10.11, *)
extension ZIPFoundationTests {
// From https://oleb.net/blog/2017/03/keeping-xctest-in-sync/
func testLinuxTestSuiteIncludesAllTests() {
Expand Down Expand Up @@ -311,9 +313,9 @@ extension ZIPFoundationTests {
("testLinuxTestSuiteIncludesAllTests", testLinuxTestSuiteIncludesAllTests)
] + darwinOnlyTests
}

static var darwinOnlyTests: [(String, (ZIPFoundationTests) -> () throws -> Void)] {
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
#if swift(>=3.2) && (os(macOS) || os(iOS) || os(tvOS) || os(watchOS))
return [
("testZipItemProgress", testZipItemProgress),
("testUnzipItemProgress", testUnzipItemProgress),
Expand All @@ -327,6 +329,7 @@ extension ZIPFoundationTests {
}
}

@available(macOS 10.11, *)
extension Archive {
func checkIntegrity() -> Bool {
var isCorrect = false
Expand Down
1 change: 1 addition & 0 deletions Tests/ZIPFoundationTests/ZIPFoundationWritingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import XCTest
@testable import ZIPFoundation

@available(macOS 10.11, *)
extension ZIPFoundationTests {
func testCreateArchiveAddUncompressedEntry() {
let archive = self.archive(for: #function, mode: .create)
Expand Down

0 comments on commit d83af64

Please sign in to comment.